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

More mod examples

This commit is contained in:
tobspr 2022-01-16 16:45:05 +01:00
parent 43348a8931
commit 41a8d4334c
4 changed files with 128 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}
`);
}

View File

@ -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";
});
}
};
});

View File

@ -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);
}
});
}
};
});