From 21be08a919cb5df4a62a4b480e17683a2d23187f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 7 Feb 2020 06:05:16 +0100 Subject: [PATCH] obey stacking order when drawing hero layers --- data.sh | 15 ++++++++++++++- engine.js | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/data.sh b/data.sh index be6b3fb..1ba1370 100755 --- a/data.sh +++ b/data.sh @@ -2,7 +2,7 @@ printf 'gamedata = {\n' for base in mods/fantasycore mods/empyrean_campaign; do - find $base/animations -name '*.txt' |while read -r file; do + find $base/animations $base/engine -name '*.txt' |while read -r file; do file="${file#"${base}"}" printf '"%s": {\n' "$file" sed -E ' @@ -45,6 +45,19 @@ for base in mods/fantasycore mods/empyrean_campaign; do # frame list end s;("frames": []\n,0-9 [-]+),;\1\n],;g; + # layer group (in engine/hero_layers.txt) + s;\nlayer=[0-9],([^\n]+)\n;\nlayers: [\1]\n;; + :layer_1 + s;(\nlayers: [^\n]+)\nlayer=[0-9]+,([^\n]+)\n;\1,[\2]\n;; + tlayer_1; + :layer_2 + s;(\nlayers: [^\n"]*)([],[])([^\n]*\n);\1"\2"\3;; + tlayer_2; + :layer_3 + s;(\nlayers: [^\n]+)""([^\n]+\n);\1\2;; + tlayer_3 + s;\nlayers: "([^\n]+)"\n;\nlayers: [\1],\n;; + # animation duration s;\n(duration)=([0-9]+)ms\n;\n"\1": \2,\n;g s;\n(duration)=([0-9]+)s\n;\n"\1": \2000,\n;g diff --git a/engine.js b/engine.js index 30c06f6..c769cca 100644 --- a/engine.js +++ b/engine.js @@ -54,23 +54,35 @@ function Mob(textdef) { } function Player(gender = "female", hair = "short"){ - // this.head = new Mob("/animations/avatar/"+gender+"/head_short.txt") - // this.chest = new Mob("/animations/avatar/"+gender+"/default_chest.txt") - // this.hands = new Mob("/animations/avatar/"+gender+"/default_hands.txt") - // this.legs = new Mob("/animations/avatar/"+gender+"/default_legs.txt") - // this.feet = new Mob("/animations/avatar/"+gender+"/default_feet.txt") - this.limbs = [ - (gender == "female")?new Mob("/animations/avatar/female/head_long.txt"):new Mob("/animations/avatar/male/head_"+hair+".txt"), - new Mob("/animations/avatar/"+gender+"/default_chest.txt"), - new Mob("/animations/avatar/"+gender+"/default_hands.txt"), - new Mob("/animations/avatar/"+gender+"/default_legs.txt"), - new Mob("/animations/avatar/"+gender+"/default_feet.txt") - ] + this.x=0; this.y=0; this.direction=0; + this.limbs = { + head : (gender == "female")?new Mob("/animations/avatar/female/head_long.txt"):new Mob("/animations/avatar/male/head_"+hair+".txt"), + chest: new Mob("/animations/avatar/"+gender+"/default_chest.txt"), + hands: new Mob("/animations/avatar/"+gender+"/default_hands.txt"), + legs : new Mob("/animations/avatar/"+gender+"/default_legs.txt"), + feet : new Mob("/animations/avatar/"+gender+"/default_feet.txt"), + main : new Mob("/animations/avatar/"+gender+"/club.txt"), + off : new Mob("/animations/avatar/"+gender+"/shield.txt") + } - this.place = function(x,y){ this.limbs.forEach(limb => limb.place(x,y)); return this; } - this.direct = function(x,y){ this.limbs.forEach(limb => limb.direct(x,y)); return this; } - this.animate = function(x,y){ this.limbs.forEach(limb => limb.animate(x,y)); return this; } - this.draw = function(x,y){ this.limbs.forEach(limb => limb.draw(x,y)); return this; } + this.place = function(x,y) { + this.x = x; this.y = y; + for (var limb in this.limbs) this.limbs[limb].place(x,y); + return this; + } + this.direct = function(d) { + this.direction = d; + for (var limb in this.limbs) this.limbs[limb].direct(d); + return this; + } + this.animate = function(anim){ + for (var limb in this.limbs) this.limbs[limb].animate(anim); + return this; + } + this.draw = function(){ + gamedata["/engine/hero_layers.txt"].layers[this.direction].forEach(limb => this.limbs[limb].draw()); + return this; + } } canvas = document.getElementById("view").getContext("2d"); -- 2.39.2