mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add smooth_zooming mod example, Fix UI toggle, (hopefully) fix vram issues, add latest discounts
This commit is contained in:
@@ -40,6 +40,7 @@ To get into shapez.io modding, I highly recommend checking out all of the exampl
|
||||
| [modify_existing_building.js](modify_existing_building.js) | Makes the rotator building always unlocked and adds a new statistic to the building panel | Modifying a builtin building, replacing builtin methods |
|
||||
| [modify_ui.js](modify_ui.js) | Shows how to add custom UI elements to builtin game states (the Main Menu in this case) | Extending builtin UI states, Adding CSS |
|
||||
| [pasting.js](pasting.js) | Shows a dialog when pasting text in the game | Listening to paste events |
|
||||
| [smooth_zooming.js](smooth_zooming.js) | Allows to smoothly zoom in and out | Keybindings, overriding methods |
|
||||
| [sandbox.js](sandbox.js) | Makes blueprints free and always unlocked | Overriding builtin methods |
|
||||
|
||||
### Advanced Examples
|
||||
|
||||
58
mod_examples/smooth_zooming.js
Normal file
58
mod_examples/smooth_zooming.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// @ts-nocheck
|
||||
const METADATA = {
|
||||
website: "https://tobspr.io",
|
||||
author: "tobspr",
|
||||
name: "Smooth Zoom",
|
||||
version: "1",
|
||||
id: "smooth_zoom",
|
||||
description: "Allows to zoom in and out smoothly, also disables map overview",
|
||||
minimumGameVersion: ">=1.5.0",
|
||||
};
|
||||
|
||||
class Mod extends shapez.Mod {
|
||||
init() {
|
||||
this.modInterface.registerIngameKeybinding({
|
||||
id: "smooth_zoom_zoom_in",
|
||||
keyCode: shapez.keyToKeyCode("1"),
|
||||
translation: "Zoom In (use with SHIFT)",
|
||||
modifiers: {
|
||||
shift: true,
|
||||
},
|
||||
handler: root => {
|
||||
root.camera.setDesiredZoom(5);
|
||||
return shapez.STOP_PROPAGATION;
|
||||
},
|
||||
});
|
||||
this.modInterface.registerIngameKeybinding({
|
||||
id: "smooth_zoom_zoom_out",
|
||||
keyCode: shapez.keyToKeyCode("0"),
|
||||
translation: "Zoom Out (use with SHIFT)",
|
||||
modifiers: {
|
||||
shift: true,
|
||||
},
|
||||
handler: root => {
|
||||
root.camera.setDesiredZoom(0.1);
|
||||
return shapez.STOP_PROPAGATION;
|
||||
},
|
||||
});
|
||||
|
||||
this.modInterface.extendClass(shapez.Camera, ({ $old }) => ({
|
||||
internalUpdateZooming(now, dt) {
|
||||
if (!this.currentlyPinching && this.desiredZoom !== null) {
|
||||
const diff = this.zoomLevel - this.desiredZoom;
|
||||
if (Math.abs(diff) > 0.0001) {
|
||||
const speed = 0.0005;
|
||||
let step = Math.sign(diff) * Math.min(speed, Math.abs(diff));
|
||||
const pow = 1 / 2;
|
||||
this.zoomLevel = Math.pow(Math.pow(this.zoomLevel, pow) - step, 1 / pow);
|
||||
} else {
|
||||
this.zoomLevel = this.desiredZoom;
|
||||
this.desiredZoom = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
shapez.globalConfig.mapChunkOverviewMinZoom = -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user