Doodad Tool: Add Tag Support for edit-doodad

* The `doodad edit-doodad` command now allows setting custom key/value
  tags in doodad files, for extra data storage useful to their scripts.
* Colored keys and doors now store a `color` tag with the appropriate
  color so that their scripts don't have to parse their Title to find
  that information.
* Trapdoors now store a `direction` tag to hold the direction the door
  is facing.
This commit is contained in:
Noah 2020-01-02 22:12:20 -08:00
parent f7c4847934
commit a4e3dbb8d4
4 changed files with 19 additions and 19 deletions

View File

@ -45,27 +45,35 @@ doors() {
cd doors/ cd doors/
doodad convert -t "Red Door" red1.png red2.png door-red.doodad doodad convert -t "Red Door" red1.png red2.png door-red.doodad
doodad edit-doodad -q --tag color=red door-red.doodad
doodad install-script locked-door.js door-red.doodad doodad install-script locked-door.js door-red.doodad
doodad convert -t "Blue Door" blue1.png blue2.png door-blue.doodad doodad convert -t "Blue Door" blue1.png blue2.png door-blue.doodad
doodad edit-doodad -q --tag color=blue door-blue.doodad
doodad install-script locked-door.js door-blue.doodad doodad install-script locked-door.js door-blue.doodad
doodad convert -t "Green Door" green1.png green2.png door-green.doodad doodad convert -t "Green Door" green1.png green2.png door-green.doodad
doodad edit-doodad -q --tag color=green door-green.doodad
doodad install-script locked-door.js door-green.doodad doodad install-script locked-door.js door-green.doodad
doodad convert -t "Yellow Door" yellow1.png yellow2.png door-yellow.doodad doodad convert -t "Yellow Door" yellow1.png yellow2.png door-yellow.doodad
doodad edit-doodad -q --tag color=yellow door-yellow.doodad
doodad install-script locked-door.js door-yellow.doodad doodad install-script locked-door.js door-yellow.doodad
doodad convert -t "Red Key" red-key.png key-red.doodad doodad convert -t "Red Key" red-key.png key-red.doodad
doodad edit-doodad -q --tag color=red key-red.doodad
doodad install-script keys.js key-red.doodad doodad install-script keys.js key-red.doodad
doodad convert -t "Blue Key" blue-key.png key-blue.doodad doodad convert -t "Blue Key" blue-key.png key-blue.doodad
doodad edit-doodad -q --tag color=blue key-blue.doodad
doodad install-script keys.js key-blue.doodad doodad install-script keys.js key-blue.doodad
doodad convert -t "Green Key" green-key.png key-green.doodad doodad convert -t "Green Key" green-key.png key-green.doodad
doodad edit-doodad -q --tag color=green key-green.doodad
doodad install-script keys.js key-green.doodad doodad install-script keys.js key-green.doodad
doodad convert -t "Yellow Key" yellow-key.png key-yellow.doodad doodad convert -t "Yellow Key" yellow-key.png key-yellow.doodad
doodad edit-doodad -q --tag color=yellow key-yellow.doodad
doodad install-script keys.js key-yellow.doodad doodad install-script keys.js key-yellow.doodad
doodad convert -t "Electric Door" electric{1,2,3,4}.png door-electric.doodad doodad convert -t "Electric Door" electric{1,2,3,4}.png door-electric.doodad
@ -88,6 +96,11 @@ trapdoors() {
doodad install-script trapdoor.js trapdoor-right.doodad doodad install-script trapdoor.js trapdoor-right.doodad
doodad install-script trapdoor.js trapdoor-up.doodad doodad install-script trapdoor.js trapdoor-up.doodad
doodad edit-doodad -q --tag direction=down trapdoor-down.doodad
doodad edit-doodad -q --tag direction=left trapdoor-left.doodad
doodad edit-doodad -q --tag direction=right trapdoor-right.doodad
doodad edit-doodad -q --tag direction=up trapdoor-up.doodad
cp trapdoor-*.doodad ../../../assets/doodads/ cp trapdoor-*.doodad ../../../assets/doodads/
cd .. cd ..

View File

@ -1,7 +1,8 @@
function main() { function main() {
var color = Self.Doodad.Tag("color");
Events.OnCollide(function(e) { Events.OnCollide(function(e) {
console.log("%s picked up by %s", Self.Doodad.Title, e.Actor.Title); e.Actor.SetData("key:" + color, "true");
e.Actor.SetData("key:" + Self.Doodad.Title, "true");
Self.Destroy(); Self.Destroy();
}) })
} }

View File

@ -1,14 +1,7 @@
function main() { function main() {
Self.AddAnimation("open", 0, [1]); Self.AddAnimation("open", 0, [1]);
var unlocked = false; var unlocked = false;
var color = Self.Doodad.Tag("color");
// Map our door names to key names.
var KeyMap = {
"Blue Door": "Blue Key",
"Red Door": "Red Key",
"Green Door": "Green Key",
"Yellow Door": "Yellow Key"
}
Self.SetHitbox(16, 0, 32, 64); Self.SetHitbox(16, 0, 32, 64);
@ -18,7 +11,7 @@ function main() {
} }
if (e.InHitbox) { if (e.InHitbox) {
var data = e.Actor.GetData("key:" + KeyMap[Self.Doodad.Title]); var data = e.Actor.GetData("key:" + color);
if (data === "") { if (data === "") {
// Door is locked. // Door is locked.
return false; return false;

View File

@ -1,13 +1,6 @@
function main() { function main() {
// What direction is the trapdoor facing? // What direction is the trapdoor facing?
// - Titles are like "Trapdoor Left" or "Trapdoor Right" var direction = Self.Doodad.Tag("direction");
// - The default (down) is called just "Trapdoor"
var direction = Self.Doodad.Title.split(" ")[1];
if (!direction) {
direction = "down";
}
direction = direction.toLowerCase();
console.log("Trapdoor(%s) initialized", direction); console.log("Trapdoor(%s) initialized", direction);
var timer = 0; var timer = 0;