]> git.plutz.net Git - flarejs/commitdiff
generate js gamedata file statically
authorPaul Hänsch <paul@plutz.net>
Thu, 6 Feb 2020 17:10:31 +0000 (18:10 +0100)
committerPaul Hänsch <paul@plutz.net>
Thu, 6 Feb 2020 17:10:31 +0000 (18:10 +0100)
Makefile
data.sh [new file with mode: 0755]
index.cgi
mods [new symlink]

index 24781a931b5fffa8423e4624a8c4e48aceee3228..9a51dac96f82c980004d4969739638f6d1249bd5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+default: _subtrees data.js
+
 .PHONY: _subtrees
 
 _subtrees: _cgilite
@@ -7,3 +9,6 @@ cgilite:
 
 _cgilite: cgilite
        git subtree pull --squash -P $< https://git.plutz.net/git/$< master
+
+data.js: data.sh mods/
+       ./$< >$@
diff --git a/data.sh b/data.sh
new file mode 100755 (executable)
index 0000000..be6b3fb
--- /dev/null
+++ b/data.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+printf 'gamedata = {\n'
+for base in mods/fantasycore 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'
index d8423cb1f33132d89dd038b1135440bd1bb67a68..da8c8a82e93837c96168f5ed196f73fb8121fbec 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -12,84 +12,23 @@ if [ "$_PATH" = / ]; then
        <html><head>
          <title>FlareJS</title>
        </head><body>
-         <canvas id="view" width=640 height=480 style="border: 1px solid red;"></canvas>
-         <img src="images/avatar/male/clothes.png" style="display: none;" />
+         <canvas id="view" width=480 height=320 style="border: 1px solid red;"></canvas>
+          $(
+         for base in mods/fantasycore mods/empyrean_campaign; do
+           find $base/images/avatar $base/images/enemies -name '*.png' |while read -r file; do
+             file="${file#"${base}/"}"
+             printf '<img src="%s" style="display: none;" />' "$file"
+            done
+          done) 
          <script type="text/javascript" src="/data.js"></script>
          <script type="text/javascript" src="/engine.js"></script>
        </body></html>
        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
+  for base in . \
+              ./mods/empyrean_campaign \
+              ./mods/fantasycore \
+              ./mods/default; do
     [ -f "${base}/$_PATH" ] && FILE "${base}/$_PATH"
   done
 fi
diff --git a/mods b/mods
new file mode 120000 (symlink)
index 0000000..48c596d
--- /dev/null
+++ b/mods
@@ -0,0 +1 @@
+/usr/share/games/flare/mods/
\ No newline at end of file