diff --git a/mod_examples/buildings_have_cost.js b/mod_examples/buildings_have_cost.js index 41b7ad86..7fda49c6 100644 --- a/mod_examples/buildings_have_cost.js +++ b/mod_examples/buildings_have_cost.js @@ -59,7 +59,6 @@ registerMod(() => { // Make the player start with some currency this.modInterface.runAfterMethod(shapez.GameCore, "initNewGame", function () { - console.log("Giving player start currency"); this.root.hubGoals.storedShapes[CURRENCY] = 100; }); @@ -86,8 +85,6 @@ registerMod(() => { this.modInterface.replaceMethod(shapez.GameLogic, "tryPlaceBuilding", function ($original, args) { const result = $original(...args); if (result && result.components.Belt) { - console.log("BELT PLACED"); - this.root.hubGoals.storedShapes[CURRENCY]--; } return result; diff --git a/mod_examples/custom_css.js b/mod_examples/custom_css.js index 248e0983..a5dfcc08 100644 --- a/mod_examples/custom_css.js +++ b/mod_examples/custom_css.js @@ -19,6 +19,9 @@ registerMod(() => { } init() { + // Notice that, since the UI is scaled dynamically, every pixel value + // should be wrapped in '$scaled()' (see below) + this.modInterface.registerCss(` * { font-family: "Comic Sans", "Comic Sans MS", "ComicSans", Tahoma !important; @@ -33,7 +36,7 @@ registerMod(() => { } #state_MainMenuState .mainContainer, #state_MainMenuState .modsOverview { - border: 5px solid #000 !important; + border: $scaled(5px) solid #000 !important; } `); } diff --git a/mod_examples/custom_sub_shapes.js b/mod_examples/custom_sub_shapes.js new file mode 100644 index 00000000..0ed47aec --- /dev/null +++ b/mod_examples/custom_sub_shapes.js @@ -0,0 +1,53 @@ +/** + * This shows how to add custom sub shapes + */ +registerMod(() => { + return class ModImpl extends shapez.Mod { + constructor(app, modLoader) { + super( + app, + { + website: "https://tobspr.io", + author: "tobspr", + name: "Mod Example: Custom Sub Shapes", + version: "1", + id: "custom-sub-shapes", + description: "Shows how to add custom sub shapes", + }, + modLoader + ); + } + + init() { + // Add a new type of sub shape ("Line", short code "L") + this.modInterface.registerSubShapeType({ + id: "line", + shortCode: "L", + + // Make it spawn on the map + weightComputation: distanceToOriginInChunks => + Math.round(20 + Math.max(Math.min(distanceToOriginInChunks, 30), 0)), + + // This defines how to draw it + draw: ({ context, quadrantSize, layerScale }) => { + const quadrantHalfSize = quadrantSize / 2; + context.beginPath(); + context.moveTo(-quadrantHalfSize, quadrantHalfSize); + context.arc( + -quadrantHalfSize, + quadrantHalfSize, + quadrantSize * layerScale, + -Math.PI * 0.25, + 0 + ); + context.closePath(); + }, + }); + + // Modify the goal of the first level to add our goal + this.signals.modifyLevelDefinitions.add(definitions => { + definitions[0].shape = "LuLuLuLu"; + }); + } + }; +}); diff --git a/mod_examples/translations.js b/mod_examples/translations.js new file mode 100644 index 00000000..7763ee16 --- /dev/null +++ b/mod_examples/translations.js @@ -0,0 +1,71 @@ +/** + * Shows to add new translations + */ +registerMod(() => { + return class ModImpl extends shapez.Mod { + constructor(app, modLoader) { + super( + app, + { + website: "https://tobspr.io", + author: "tobspr", + name: "Mod Example: Translations", + version: "1", + id: "translations", + description: "Shows how to add and modify translations", + }, + modLoader + ); + } + + init() { + // Replace an existing translation in the english language + this.modInterface.registerTranslations("en", { + ingame: { + interactiveTutorial: { + title: "Hello", + hints: { + "1_1_extractor": "World!", + }, + }, + }, + }); + + // Replace an existing translation in german + this.modInterface.registerTranslations("de", { + ingame: { + interactiveTutorial: { + title: "Hallo", + hints: { + "1_1_extractor": "Welt!", + }, + }, + }, + }); + + // Add an entirely new translation which is localized in german and english + this.modInterface.registerTranslations("en", { + mods: { + mymod: { + test: "Test Translation", + }, + }, + }); + this.modInterface.registerTranslations("de", { + mods: { + mymod: { + test: "Test Übersetzung", + }, + }, + }); + + // Show a dialog in the main menu + this.signals.stateEntered.add(state => { + if (state instanceof shapez.MainMenuState) { + // Will show differently based on the selected language + this.dialogs.showInfo("My translation", shapez.T.mods.mymod.test); + } + }); + } + }; +});