1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 18:21:51 +00:00

Add support for paste signals

This commit is contained in:
tobspr 2022-01-17 09:34:34 +01:00
parent 459cc76d96
commit 8943dc045c
5 changed files with 60 additions and 30 deletions

View File

@ -8,6 +8,10 @@ const steam = require("./steam");
const asyncLock = require("async-lock");
const windowStateKeeper = require("electron-window-state");
// Disable hardware key handling, i.e. being able to pause/resume the game music
// with hardware keys
app.commandLine.appendSwitch("disable-features", "HardwareMediaKeyHandling");
const isDev = app.commandLine.hasSwitch("dev");
const isLocal = app.commandLine.hasSwitch("local");
const safeMode = app.commandLine.hasSwitch("safe-mode");

View File

@ -106,17 +106,6 @@ class Mod extends shapez.Mod {
// Add an atlas
this.modInterface.registerAtlas(RESOURCES["demoAtlas.png"], RESOURCES["demoAtlas.json"]);
this.modInterface.registerTranslations("en", {
ingame: {
interactiveTutorial: {
title: "Hello",
hints: {
"1_1_extractor": "World!",
},
},
},
});
// Register a new component
this.modInterface.registerComponent(DemoModComponent);
@ -128,29 +117,29 @@ class Mod extends shapez.Mod {
drawHooks: ["staticAfter"],
});
// Register the new building
this.modInterface.registerNewBuilding({
metaClass: MetaDemoModBuilding,
buildingIconBase64: RESOURCES["demoBuilding.png"],
// // Register the new building
// this.modInterface.registerNewBuilding({
// metaClass: MetaDemoModBuilding,
// buildingIconBase64: RESOURCES["demoBuilding.png"],
variantsAndRotations: [
{
description: "A test building",
name: "A test name",
// variantsAndRotations: [
// {
// description: "A test building",
// name: "A test name",
regularImageBase64: RESOURCES["demoBuilding.png"],
blueprintImageBase64: RESOURCES["demoBuildingBlueprint.png"],
tutorialImageBase64: RESOURCES["demoBuildingBlueprint.png"],
},
],
});
// regularImageBase64: RESOURCES["demoBuilding.png"],
// blueprintImageBase64: RESOURCES["demoBuildingBlueprint.png"],
// tutorialImageBase64: RESOURCES["demoBuildingBlueprint.png"],
// },
// ],
// });
// Add it to the regular toolbar
this.modInterface.addNewBuildingToToolbar({
toolbar: "regular",
location: "primary",
metaClass: MetaDemoModBuilding,
});
// this.modInterface.addNewBuildingToToolbar({
// toolbar: "regular",
// location: "primary",
// metaClass: MetaDemoModBuilding,
// });
// Register keybinding
this.modInterface.registerIngameKeybinding({

25
mod_examples/pasting.js Normal file
View File

@ -0,0 +1,25 @@
/**
* This is the minimal structure of a mod
*/
const METADATA = {
website: "https://tobspr.io",
author: "tobspr",
name: "Mod Example: Pasting",
version: "1",
id: "pasting",
description: "Shows how to properly receive paste events ingame",
};
class Mod extends shapez.Mod {
init() {
this.signals.gameInitialized.add(root => {
root.gameState.inputReciever.paste.add(event => {
event.preventDefault();
const data = event.clipboardData.getData("text");
this.dialogs.showInfo("Pasted", "You pasted: '" + data + "'");
});
});
}
}

View File

@ -149,6 +149,8 @@ export class InputDistributor {
window.addEventListener("mouseup", this.handleKeyMouseUp.bind(this));
window.addEventListener("blur", this.handleBlur.bind(this));
document.addEventListener("paste", this.handlePaste.bind(this));
}
forwardToReceiver(eventId, payload = null) {
@ -186,6 +188,13 @@ export class InputDistributor {
this.keysDown.clear();
}
/**
*
*/
handlePaste(ev) {
this.forwardToReceiver("paste", ev);
}
/**
* @param {KeyboardEvent | MouseEvent} event
*/

View File

@ -12,12 +12,15 @@ export class InputReceiver {
// Dispatched on destroy
this.destroyed = new Signal();
this.paste = new Signal();
}
cleanup() {
this.backButton.removeAll();
this.keydown.removeAll();
this.keyup.removeAll();
this.paste.removeAll();
this.destroyed.dispatch();
}