Skip to content

Commit

Permalink
add localization support
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitmel committed Dec 22, 2020
1 parent 3e9a12c commit da1fbf6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions assets/data/lang/sc/gui.en_US.json.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"labels": {
"menu": {
"map-menu": {
"teleport-anywhere": {
"question": "\\c[3]Teleport\\c[0] to map \"[!]\"?",
"map-id": "\\c[3]Map ID:\\c[0] [!]"
}
}
}
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"name": "teleport-anywhere",
"version": "0.1.0",
"ccmodHumanName": "Teleport Anywhere!",
"description": "Teleport to any map/room simply by clicking it in the map menu",
"description": "Teleport to any map/room in an area simply by clicking it in the map menu",
"license": "CC0-1.0",
"homepage": "https://github.com/dmitmel/crosscode-teleport-anywhere",
"module": true,
"prestart": "prestart.js"
"prestart": "prestart.js",
"assets": [
"data/lang/sc/gui.en_US.json.patch"
]
}
11 changes: 8 additions & 3 deletions prestart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Well, this code turned out to not be as straight-forward as I anticipated

const LANG_NAMESPACE = 'sc.gui.menu.map-menu.teleport-anywhere';

sc.MapAreaContainer.inject({
// See below
mouseWasOverWhenDragged: false,
Expand Down Expand Up @@ -106,12 +108,15 @@ sc.MapAreaContainer.inject({

// All of the checks above effectively are checking if the map has been
// clicked and a map room ("map map"?) was under the cursor.
// Here you can basically see the main branch of onLandmarkPressed.

let hoveredMapName = this.hoverRoom.text;
let hoveredMapID = this.hoverRoom.name;
// Here you can basically see the main branch of onLandmarkPressed. I'll
// admit I got carried away with formatting.
let dialogText = `\\c[3]Teleport\\c[0] to map "${hoveredMapName}"?\n\\c[3]Map ID:\\c[0] ${hoveredMapID}`;
// I'll admit I got carried away with formatting.
let dialogText = [
ig.lang.grammarReplace(ig.lang.get(`${LANG_NAMESPACE}.question`), hoveredMapName),
ig.lang.grammarReplace(ig.lang.get(`${LANG_NAMESPACE}.map-id`), hoveredMapID),
].join('\n');
sc.BUTTON_SOUND.submit.play();
sc.Dialogs.showYesNoDialog(dialogText, sc.DIALOG_INFO_ICON.QUESTION, (dialogBtn) => {
// sc.menu.mapDrag is unset in onLandmarkPressed, dunno why, I'll follow along...
Expand Down

0 comments on commit da1fbf6

Please sign in to comment.