Merge pull request #1070 from SquareScreamYT/main

modlangs.js <library to translate mods>
This commit is contained in:
slweeb 2025-03-31 13:38:09 -04:00 committed by GitHub
commit e6334507aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 0 deletions

View File

@ -418,6 +418,7 @@
<tr><td>libpacman-v1.js</td><td>Library for making mods</td><td>mollthecoder</td></tr>
<tr><td>libpixeltracking.js</td><td>Library for tracking pixels</td><td>mollthecoder</td></tr>
<tr><td>maxColorOffset.js</td><td>Adds a property to specify how much a pixels color can be randomly offset from the element color</td><td>Alice</td></tr>
<tr><td>modlangs.js</td><td>Adds a customisable property in an element to allow for translations in mods. See the file for instructions on how to implement.</td><td>SquareScreamYT</td></tr>
<tr><td>nested_for_reaction_example.js</td><td>An example of using a nested for loop to add reactions. It makes various things kill plants</td><td>Alice</td></tr>
<tr><td>nv7.js</td><td>Adds a giant Nv7 image [Large]</td><td>Nv7</td></tr>
<tr><td>place_all_elements.js</td><td>Experimental function that places every pixel</td><td>Alice</td></tr>

53
mods/modlangs.js Normal file
View File

@ -0,0 +1,53 @@
function add_lang(langcode) {
for (element in elements) {
if (elements[element]["name_"+langcode]) {
lang[element] = elements[element]["name_"+langcode];
}
}
}
/*
INSTRUCTIONS
put this code at the top of your mod:
set langcode to whatever language code (zh_cn is simplified chinese)
langcode = "zh_cn"
var mods_to_include = ["mods/modlangs.js"]
var mods_included = mods_to_include.map(mod => enabledMods.includes(mod));
var all_mods_included = mods_included.reduce(function(a,b) { return a && b });
if(!all_mods_included) {
var mods_needed = mods_to_include.filter(function(modPath) { return !(enabledMods.includes(modPath)) });
mods_needed.forEach(function(modPath) {
enabledMods.splice(enabledMods.indexOf("mods/modlangs"),0,modPath);
});
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
}
runAfterLoad(function() {
add_lang(langcode)
})
then you can add the name_ + langcode to your element like this:
elements.eat = {
color: ["#ffba79","#efff79"],
tool: function(pixel) {
if (elements[pixel.element].isFood || elements[pixel.element].category === "food" || eLists.JUICEMIXABLE.includes(pixel.element) || elements[pixel.element].id === elements.uranium.id || elements[pixel.element].id === elements.mercury.id) {
deletePixel(pixel.x, pixel.y);
}
},
category: "tools",
desc: "Eats pixels.",
name_zh_cn: "吃"
}
*/