Last active
January 22, 2024 16:28
-
-
Save dogboydog/42edb0886989467ec3671acdce4e749f to your computer and use it in GitHub Desktop.
Testing world scripting functionality for Tiled (map editor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Testing world scripting functionality | |
*/ | |
var WorldScripting = {}; | |
WorldScripting.scriptAction = tiled.registerAction("WorldScripting", function (action) { | |
var state = { | |
worlds: tiled.worlds, | |
} | |
tiled.worldsChanged.connect(() => { | |
state.worlds = tiled.worlds; | |
drawDialog(); | |
tiled.log("Worlds changed.") | |
}); | |
var dialog = new Dialog('World Scripting'); | |
dialog.minimumWidth = 700; | |
dialog.newRowMode = Dialog.ManualRows; | |
function drawDialog() { | |
if (dialog == null){ | |
return; | |
} | |
dialog.clear() | |
dialog.addHeading('World Scripting'); | |
dialog.addNewRow(); | |
dialog.addHeading(`Loaded Worlds (${tiled.worlds.length})`); | |
dialog.addNewRow(); | |
dialog.addLabel('Display name'); | |
dialog.addLabel('Maps') | |
dialog.addSeparator(); | |
for (var i = 0; i < state.worlds.length; i++) { | |
var world = state.worlds[i]; | |
dialog.addLabel(world.displayName) | |
var allMaps = world.allMaps(); | |
if (allMaps.length >= 1) { | |
// show the first matching map on the same line | |
dialog.addLabel(allMaps[0].fileName); | |
} | |
var unloadButton = dialog.addButton('Unload'); | |
unloadButton.clicked.connect(() => { | |
tiled.unloadWorld(world.fileName); | |
}) | |
dialog.addNewRow(); | |
for (var mapIndex = 1; mapIndex < allMaps.length; mapIndex++) { | |
dialog.addLabel(''); | |
dialog.addLabel(allMaps[mapIndex].fileName); | |
dialog.addNewRow(); | |
} | |
dialog.addSeparator(); | |
} | |
} | |
drawDialog(); | |
dialog.show(); | |
dialog.finished.connect(function(){ | |
dialog = null; | |
}); | |
}); | |
WorldScripting.scriptAction.text = "World Scripting Test"; | |
tiled.extendMenu("Edit", [ | |
{ action: "WorldScripting" }, | |
{ separator: true } | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment