From: Paul Hänsch Date: Thu, 6 Feb 2020 03:59:58 +0000 (+0100) Subject: initial X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=58ce9fb28cd30838ff0d7ea75860223c683ae8e4;p=flarejs initial --- diff --git a/engine.js b/engine.js new file mode 100644 index 0000000..c83911c --- /dev/null +++ b/engine.js @@ -0,0 +1,60 @@ +function Mob(textdef) { + this.direction = 0; + this.position = [0, 0]; + this.info = gamedata[textdef]; + this.animation = "stance"; + this.previous_animation = ""; + this.frametime = performance.now(); + this.image = document.querySelector("img[src='"+ this.info.image +"']"); + + this.place = function(x, y) { this.position = [x, y]; } + this.direct = function(d) { this.direction = d % 8; } + this.animate = function(a) { + this.previous_animation = this.animation; + this.animation = a; + this.frametime = performance.now(); + } + + this.draw = function(){ + var f, a = this.info[this.animation]; + var frame = ( performance.now() - this.frametime ) * a.frames.length / a.duration | 0; + + switch(a.type){ + case "looped": + frame = frame % a.frames.length; + break; + case "play_once": + if ( frame >= a.frames.length ){ + this.animation = this.previous_animation; + this.previous_animation = ""; + this.frametime = performance.now(); + a = this.info[this.animation]; + frame = 0; + } + break; + case "back_forth": + frame = frame % (a.frames.length * 2 - 2); + if ( frame >= a.frames.length ){ + frame = a.frames.length - frame % a.frames.length - 1; + } + break; + default: break; + } + f = a.frames[frame][this.direction]; + + canvas.clearRect(0,0, 640, 480); + canvas.drawImage(this.image, f[0], f[1], f[2], f[3], + this.position[0] - f[4], this.position[1] - f[5], + f[2], f[3]); + + // var fetch = new XMLHttpRequest(); + // fetch.open("GET", textdef, false); fetch.send(); + // this.description = fetch.responseText.split('\n'); + } +} + +canvas = document.getElementById("view").getContext("2d"); +player = new Mob("/animations/avatar/male/clothes.txt"); +player.place(320, 240); + +setInterval( function() { player.draw(); }, 33); diff --git a/index.cgi b/index.cgi new file mode 100755 index 0000000..d8423cb --- /dev/null +++ b/index.cgi @@ -0,0 +1,95 @@ +#!/bin/sh + +. cgilite/cgilite.sh +. cgilite/file.sh + +_PATH="$(PATH "${PATH_INFO}")" + +if [ "$_PATH" = / ]; then + printf 'Content-Type: text/html\r\n\r\n' + cat <<-EOF + + + FlareJS + + + + + + + EOF +elif [ "$_PATH" = "/data.js" -a data.js -nt "$0" ]; then + FILE data.js +elif [ "$_PATH" = "/data.js" -a ! data.js -nt "$0" ]; then + printf 'Content-Type: text/javascript\r\n\r\n' + { + printf 'gamedata = {\n' + for base in /usr/share/games/flare/mods/fantasycore /usr/share/games/flare/mods/empyrean_campaign; do + find $base/animations -name '*.txt' |while read -r file; do + file="${file#"${base}"}" + printf '"%s": {\n' "$file" + sed -E ' + # read entire file into buffer + :X N; $!bX; s;$;\n;; s;^;\n;; s;\r\n;\n;g; + + # Comment and empty lines + :Y s;\n#[^\n]*\n;\n;g; tY; + + # INCLUDE, APPEND + s;\nAPPEND\n;\n;g; + s;\nINCLUDE ([^\n]+)\n;\n"INCLUDE": "\1"\n;g; + + # section heading, eg. [stance] + s;\n\[([^\n]+)\]\n(([^]\n[]+\n)+);"\1": {\n\2 },\n;g; + + # frame list start + s;\nframes=[0-9]+\n;\n;g; + s;(\nframe=[^\n]+)+;\n"frames": [&;g; + + # frame list, 8 angles isometric + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\nframe=[0-9]+,3,([0-9,-]+)\nframe=[0-9]+,4,([0-9,-]+)\nframe=[0-9]+,5,([0-9,-]+)\nframe=[0-9]+,6,([0-9,-]+)\nframe=[0-9]+,7,([0-9,-]+)\n;[[\1], [\2], [\3], [\4], [\5], [\6], [\7], [\8]],\n;g + # frame list, workaround for bug in avatar/female/dagger.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,3,([0-9,-]+)\nframe=[0-9]+,4,([0-9,-]+)\nframe=[0-9]+,5,([0-9,-]+)\nframe=[0-9]+,6,([0-9,-]+)\nframe=[0-9]+,7,([0-9,-]+)\n;[[\1], [\2], [0,0,0,0,0,0], [\3], [\4], [\5], [\6], [\7]],\n;g + # frame list, workaround for bug in avatar/male/greatsword.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\nframe=[0-9]+,3,([0-9,-]+)\nframe=[0-9]+,4,([0-9,-]+)\nframe=[0-9]+,5,([0-9,-]+)\nframe=[0-9]+,7,([0-9,-]+)\n;[[\1], [\2], [\3], [\4], [\5], [\6], [0,0,0,0,0,0], [\7]],\n;g + # frame list, workaround for bug in avatar/male/slingshot.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\nframe=[0-9]+,4,([0-9,-]+)\nframe=[0-9]+,5,([0-9,-]+)\nframe=[0-9]+,6,([0-9,-]+)\nframe=[0-9]+,7,([0-9,-]+)\n;[[\1], [\2], [\3], [0,0,0,0,0,0], [\4], [\5], [\6], [\7]],\n;g + # frame list, 6 angles e.g. powers/freeze.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\nframe=[0-9]+,3,([0-9,-]+)\nframe=[0-9]+,4,([0-9,-]+)\nframe=[0-9]+,5,([0-9,-]+)\n;[[\1], [\2], [\3], [\4], [\5], [\6]],\n;g + # frame list, 4 angles e.g. powers/spikes.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\nframe=[0-9]+,3,([0-9,-]+)\n;[[\1], [\2], [\3], [\4]],\n;g + # frame list, 3 angles e.g. powers/quake.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\nframe=[0-9]+,2,([0-9,-]+)\n;[[\1], [\2], [\3]],\n;g + # frame list, 2 angles e.g. powers/blast.txt + s;frame=[0-9]+,0,([0-9,-]+)\nframe=[0-9]+,1,([0-9,-]+)\n;[[\1], [\2]],\n;g + # frame list, front angle only + s;frame=[0-9]+,0,([0-9,-]+)\n;[[\1]],\n;g + + # frame list end + s;("frames": []\n,0-9 [-]+),;\1\n],;g; + + # 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 + + :general + # general scalar + s;\n([^=\n]+)=([0-9-]+)\n;\n"\1": \2,\n;g + + # general array + s;\n([^=\n]+)=([0-9,-]+)\n;\n"\1": [\2],\n;g + + # general text + s;\n([^=\n]+)=([^\n]+)\n;\n"\1": "\2",\n;g + tgeneral; + ' "${base}${file}" + printf '},\n' + done + done + printf '}\n' + } |tee data.js +else + for base in . /usr/share/games/flare/mods/empyrean_campaign /usr/share/games/flare/mods/fantasycore /usr/share/games/flare/mods/default; do + [ -f "${base}/$_PATH" ] && FILE "${base}/$_PATH" + done +fi diff --git a/flarejs.html b/index.html similarity index 100% rename from flarejs.html rename to index.html