]> git.lizzy.rs Git - dragonblocks.git/commitdiff
Rename PixelManipulator to Schematic
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 28 Jun 2021 09:53:58 +0000 (11:53 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 28 Jun 2021 09:53:58 +0000 (11:53 +0200)
engine/init.js
engine/mapgen.js
engine/pixel_manipulator.js [deleted file]
engine/schematic.js [new file with mode: 0644]
game/plants/plants.js
game/tnt/init.js

index 0f76fb16f6d39787f3fa70d0f6ebbad389b3505f..349d4670b39693a4c990cca98c2aceb0a4257c99 100644 (file)
                "falling_node",
                "timer",
                "player",
-               "pixel_manipulator",
+               "schematic",
                "chat",
                "chatcommands",
                "mainmenu",
index 8aeba2d212d0f92e10c24ead56f1cb1643fbcbf2..b1c6e13685cb7058320cbdbbfb2dc4903b54a50d 100644 (file)
@@ -59,7 +59,7 @@ dragonblocks.mapgen.list["v3"] = _ => {
        let snode = dragonblocks.setNode;
        let gnode = dragonblocks.getNode;
 
-       let pm = dragonblocks.PixelManipulator;
+       let schem = dragonblocks.Schematic;
 
        let rand = dblib.random;
 
@@ -337,35 +337,35 @@ dragonblocks.mapgen.list["v3"] = _ => {
                };
 
                function structure(x, y, mat) {
-                       new pm([["§" + mat, mat], [mat, mat]])
+                       new schem([["§" + mat, mat], [mat, mat]])
                                .addFunction(belowGround)
                                .apply(x, y);
 
                        let sides = [
-                               new pm([[mat, mat], ["§", ""]]),
-                               new pm([["§", "", mat], ["", "", mat]]),
-                               new pm([["§", ""], ["", ""], [mat, mat]]),
-                               new pm([[mat, "§"], [mat, ""]]),
+                               new schem([[mat, mat], ["§", ""]]),
+                               new schem([["§", "", mat], ["", "", mat]]),
+                               new schem([["§", ""], ["", ""], [mat, mat]]),
+                               new schem([[mat, "§"], [mat, ""]]),
                        ];
 
                        for (let side of sides)
                                side.addFunction(belowGround);
 
                        let moresides = [
-                               new pm([[mat, mat], ["", ""], ["§", ""]]),
-                               new pm([["§", "", "", mat], ["", "", "", mat]]),
-                               new pm([["§", ""], ["", ""], ["", ""], [mat, mat]]),
-                               new pm([[mat, "", "§"], [mat, "", ""]]),
+                               new schem([[mat, mat], ["", ""], ["§", ""]]),
+                               new schem([["§", "", "", mat], ["", "", "", mat]]),
+                               new schem([["§", ""], ["", ""], ["", ""], [mat, mat]]),
+                               new schem([[mat, "", "§"], [mat, "", ""]]),
                        ];
 
                        for (let moreside of moresides)
                                moreside.addFunction(belowGround);
 
                        let corners = [
-                               new pm([[mat, ""], ["", "§"]]),
-                               new pm([["", "", mat], ["§", "", ""]]),
-                               new pm([["§", "", ""], ["", "", ""], ["", "", mat]]),
-                               new pm([["§", "", ""], ["", "", ""], ["", "", mat]]),
+                               new schem([[mat, ""], ["", "§"]]),
+                               new schem([["", "", mat], ["§", "", ""]]),
+                               new schem([["§", "", ""], ["", "", ""], ["", "", mat]]),
+                               new schem([["§", "", ""], ["", "", ""], ["", "", mat]]),
                        ];
 
                        for (let corner of corners)
@@ -399,7 +399,7 @@ dragonblocks.mapgen.list["v3"] = _ => {
                let cave = (x, y, r) => {
                        r *= 2;
 
-                       let cavepm = new pm([
+                       let caveschem = new schem([
                                ["",    "air",  "air", "air",    ""],
                                ["air", "air",  "air", "air", "air"],
                                ["air", "air", "§air", "air", "air"],
@@ -407,7 +407,7 @@ dragonblocks.mapgen.list["v3"] = _ => {
                                ["",    "air",  "air", "air",    ""],
                        ]);
 
-                       cavepm.addFunction((node, x, y) => {
+                       caveschem.addFunction((node, x, y) => {
                                if (y < ground[x])
                                        return false;
 
@@ -415,7 +415,7 @@ dragonblocks.mapgen.list["v3"] = _ => {
                                        cave(x, y, r);
                        });
 
-                       cavepm.apply(x, y);
+                       caveschem.apply(x, y);
                };
 
                let newCave = (x, y) => {
diff --git a/engine/pixel_manipulator.js b/engine/pixel_manipulator.js
deleted file mode 100644 (file)
index 31a0d31..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * pixel_manipulator.js
- *
- * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- *
- */
-
-dragonblocks.PixelManipulator = class
-{
-       constructor(arr)
-       {
-               this.data = [];
-               this.functions = [];
-
-               let pos;
-
-               for (let y = 0; y < arr.length; y++) {
-                       for (let x = 0; x < arr[y].length; x++) {
-                               let node = arr[y][x];
-
-                               if (node[0] == "§") {
-                                       pos = {x: x, y: y};
-                                       node = node.slice(1, node.length);
-                               }
-
-                               if (node == "")
-                                       continue;
-
-                               this.data.push({
-                                       x: x,
-                                       y: y,
-                                       node: node,
-                               });
-                       }
-               }
-
-               if (! pos)
-                       pos = {x: 0, y: 0};
-
-               for (let pixel of this.data) {
-                       pixel.x = pixel.x - pos.x;
-                       pixel.y = pixel.y - pos.y;
-               }
-       }
-
-       apply(x, y)
-       {
-               for (let pixel of this.data) {
-                       let mx, my;
-                       mx = pixel.x + x;
-                       my = pixel.y + y;
-
-                       let node = dragonblocks.getNode(mx, my);
-                       if (! node)
-                               continue;
-
-                       let nodeDef = node.toNode();
-
-                       let doApply = true;
-
-                       for (let func of this.functions) {
-                               if (func(nodeDef, mx, my, pixel.node) == false) {
-                                       doApply = false;
-                                       break;
-                               }
-                       }
-
-                       if (doApply)
-                               dragonblocks.setNode(mx, my, pixel.node);
-               }
-
-               return this;
-       }
-
-       replace(toReplace, replaceWith)
-       {
-               for (let pixel of this.data)
-                       if (pixel.node == toReplace)
-                               pixel.node = replaceWith;
-
-               return this;
-       }
-
-       addFunction(func)
-       {
-               this.functions.push(func);
-               return this;
-       }
-};
diff --git a/engine/schematic.js b/engine/schematic.js
new file mode 100644 (file)
index 0000000..ba893f9
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * schematic.js
+ *
+ * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ *
+ */
+
+dragonblocks.Schematic = class
+{
+       constructor(arr)
+       {
+               this.data = [];
+               this.functions = [];
+
+               let anchor;
+
+               for (let y = 0; y < arr.length; y++) {
+                       for (let x = 0; x < arr[y].length; x++) {
+                               let node = arr[y][x];
+
+                               if (node[0] == "§") {
+                                       anchor = {x: x, y: y};
+                                       node = node.slice(1, node.length);
+                               }
+
+                               if (node == "")
+                                       continue;
+
+                               this.data.push({
+                                       x: x,
+                                       y: y,
+                                       node: node,
+                               });
+                       }
+               }
+
+               if (! anchor)
+                       anchor = {x: 0, y: 0};
+
+               for (let pixel of this.data) {
+                       pixel.x = pixel.x - anchor.x;
+                       pixel.y = pixel.y - anchor.y;
+               }
+       }
+
+       apply(x, y)
+       {
+               for (let pixel of this.data) {
+                       let mx, my;
+                       mx = pixel.x + x;
+                       my = pixel.y + y;
+
+                       let node = dragonblocks.getNode(mx, my);
+                       if (! node)
+                               continue;
+
+                       let nodeDef = node.toNode();
+
+                       let doApply = true;
+
+                       for (let func of this.functions) {
+                               if (func(nodeDef, mx, my, pixel.node) == false) {
+                                       doApply = false;
+                                       break;
+                               }
+                       }
+
+                       if (doApply)
+                               dragonblocks.setNode(mx, my, pixel.node);
+               }
+
+               return this;
+       }
+
+       replace(toReplace, replaceWith)
+       {
+               for (let pixel of this.data)
+                       if (pixel.node == toReplace)
+                               pixel.node = replaceWith;
+
+               return this;
+       }
+
+       addFunction(func)
+       {
+               this.functions.push(func);
+               return this;
+       }
+};
index d62a33f9444918c9a63487516dda09cdd35f8997..767e5649576d99fc1b42bb7ba46731eea4224626 100644 (file)
@@ -24,7 +24,7 @@ doors.registerDoor({
 });
 plants.registerTree({
        name: "apple",
-       tree: new dragonblocks.PixelManipulator([
+       tree: new dragonblocks.Schematic([
                ["leaves", "leaves", "leaves"],
                ["leaves", "leaves", "leaves"],
                ["leaves", "leaves", "leaves"],
@@ -38,7 +38,7 @@ plants.registerTree({
 });
 plants.registerTree({
        name: "pine",
-       tree: new dragonblocks.PixelManipulator([
+       tree: new dragonblocks.Schematic([
                ["", "", "leaves", "", ""],
                ["", "", "leaves", "", ""],
                ["", "leaves", "leaves", "leaves", ""],
@@ -56,7 +56,7 @@ plants.registerTree({
 });
 plants.registerTree({
        name: "acacia",
-       tree: new dragonblocks.PixelManipulator([
+       tree: new dragonblocks.Schematic([
                ["", "", "leaves", "leaves", "leaves", "", ""],
                ["leaves", "leaves", "leaves", "tree", "leaves", "leaves", "leaves"],
                ["leaves", "tree", "leaves", "tree", "leaves", "tree", "leaves"],
@@ -71,7 +71,7 @@ plants.registerTree({
 });
 plants.registerTree({
        name: "jungle",
-       tree: new dragonblocks.PixelManipulator([
+       tree: new dragonblocks.Schematic([
                ["", "leaves", "leaves", "leaves", ""],
                ["leaves", "leaves", "leaves", "leaves", "leaves"],
                ["leaves", "leaves", "leaves", "leaves", "leaves"],
@@ -94,7 +94,7 @@ plants.registerTree({
 });
 plants.registerTree({
        name: "aspen",
-       tree: new dragonblocks.PixelManipulator([
+       tree: new dragonblocks.Schematic([
                ["leaves", "leaves", "leaves"],
                ["leaves", "leaves", "leaves"],
                ["leaves", "leaves", "leaves"],
index 3cf003119c0e047349efb1ffe625a2db269cd261..720af3df169103f06d76f787062a46577fea2169 100644 (file)
@@ -1,5 +1,5 @@
 tnt = {};
-tnt.explosion = new dragonblocks.PixelManipulator([
+tnt.explosion = new dragonblocks.Schematic([
        ["", "air", "air", "air", ""],
        ["air", "air", "air", "air", "air"],
        ["air", "air", "§air", "air", "air"],