]> git.r.bdr.sh - rbdr/serpentity/commitdiff
Prepare it for the browser
authorBen Beltran <redacted>
Mon, 11 Aug 2014 23:28:59 +0000 (18:28 -0500)
committerBen Beltran <redacted>
Mon, 11 Aug 2014 23:28:59 +0000 (18:28 -0500)
.gitignore
bower.json [new file with mode: 0644]
browser_test/index.html [new file with mode: 0644]
lib/serpentity/serpentity.js
package.json

index da23d0d4bab05054b5ff73fe4d5910e17a6b278b..e5a4385ca6ccea135ac5a2dabb5c8abfe73c4ae3 100644 (file)
@@ -23,3 +23,4 @@ build/Release
 # Deployed apps should consider commenting this line out:
 # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
 node_modules
 # Deployed apps should consider commenting this line out:
 # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
 node_modules
+bower_modules
diff --git a/bower.json b/bower.json
new file mode 100644 (file)
index 0000000..985e6c8
--- /dev/null
@@ -0,0 +1,31 @@
+{
+  "name": "serpentity",
+  "version": "0.1.3",
+  "homepage": "https://github.com/benbeltran/serpentity",
+  "authors": [
+    "Ben Beltran <ben@nsovocal.com>"
+  ],
+  "description": "A simple entity framework inspired by ash",
+  "main": [
+    "./lib/serpentity/serpentity.js",
+    "./lib/serpentity/entity.js",
+    "./lib/serpentity/node.js",
+    "./lib/serpentity/node_collection.js",
+    "./lib/serpentity/component.js",
+    "./lib/serpentity/system.js"
+  ],
+  "keywords": [
+    "entity"
+  ],
+  "license": "MIT",
+  "ignore": [
+    "**/.*",
+    "node_modules",
+    "bower_components",
+    "test",
+    "tests"
+  ],
+  "dependencies": {
+    "neon": "*"
+  }
+}
diff --git a/browser_test/index.html b/browser_test/index.html
new file mode 100644 (file)
index 0000000..9133ed5
--- /dev/null
@@ -0,0 +1,161 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Serpentity Browser Test</title>
+    <script src="/node_modules/neon/neon.js"></script>
+    <script src="/lib/serpentity/serpentity.js"></script>
+    <script src="/lib/serpentity/entity.js"></script>
+    <script src="/lib/serpentity/node.js"></script>
+    <script src="/lib/serpentity/node_collection.js"></script>
+    <script src="/lib/serpentity/component.js"></script>
+    <script src="/lib/serpentity/system.js"></script>
+    <script type="application/javascript">
+        /////////////////
+        // Load the stuff
+        /////////////////
+        console.log("\n## Loading")
+        console.log("Serpentity: " + (typeof Serpentity !== "undefined" ? "LOAD OK" : "FAIL"));
+        console.log("Serpentity.Entity: " + (typeof Serpentity !== "undefined" && Serpentity.Entity ? "LOAD OK" : "FAIL"));
+        console.log("Serpentity.Component: " + (typeof Serpentity !== "undefined" && Serpentity.Component ? "LOAD OK" : "FAIL"));
+        console.log("Serpentity.System: " + (typeof Serpentity !== "undefined" && Serpentity.System ? "LOAD OK" : "FAIL"));
+        console.log("Serpentity.Node: " + (typeof Serpentity !== "undefined" && Serpentity.Node ? "LOAD OK" : "FAIL"));
+        console.log("Serpentity.NodeCollection: " + (typeof Serpentity !== "undefined" && Serpentity.NodeCollection ? "LOAD OK" : "FAIL"));
+
+        //////////////////////
+        // Create test classes
+        //////////////////////
+        console.log("\n## Creating Test Classes");
+        Class("TestSystem").inherits(Serpentity.System)({
+            prototype : {
+                added : function added(engine) {
+                    this.testNodes = engine.getNodes(TestNode);
+                    console.log("System added callback: " + "EXEC OK");
+                },
+
+                removed : function removed(engine) {
+                    this.testNodes = null;
+                    console.log("System removed callback: " + "EXEC OK");
+                },
+
+                update : function update(dt) {
+                    this.testNodes.forEach(function (node) {
+                        console.log("Running Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
+                    });
+                    console.log("System update callback: " + "EXEC OK");
+                }
+            }
+        });
+        var testSystem = new TestSystem();
+
+        Class("LowProTestSystem").inherits(Serpentity.System)({
+            prototype : {
+                added : function added(engine) {
+                    this.testNodes = engine.getNodes(TestNode);
+                    console.log("System added callback: " + "EXEC OK");
+                },
+
+                removed : function removed(engine) {
+                    this.testNodes = null;
+                    console.log("System removed callback: " + "EXEC OK");
+                },
+
+                update : function update(dt) {
+                    this.testNodes.forEach(function (node) {
+                        console.log("Running Low Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
+                    });
+                    console.log("System update callback: " + "EXEC OK");
+                }
+            }
+        });
+        var lowProTestSystem = new LowProTestSystem();
+        console.log("LowProTestSystem: " + "CREATE OK")
+
+        Class("MidProTestSystem").inherits(Serpentity.System)({
+            prototype : {
+                added : function added(engine) {
+                    this.testNodes = engine.getNodes(TestNode);
+                    console.log("System added callback: " + "EXEC OK");
+                },
+
+                removed : function removed(engine) {
+                    this.testNodes = null;
+                    console.log("System removed callback: " + "EXEC OK");
+                },
+
+                update : function update(dt) {
+                    this.testNodes.forEach(function (node) {
+                        console.log("Running Mid Priority Node: " + (node.test.testMessage === "test" ? "SYSTEM OK" : "FAIL"));
+                    });
+                    console.log("System update callback: " + "EXEC OK");
+                }
+            }
+        });
+        var midProTestSystem = new MidProTestSystem();
+        console.log("MidProTestSystem: " + "CREATE OK")
+
+
+        Class("TestComponent").inherits(Serpentity.Component)({
+            prototype : {
+                testMessage : "test"
+            }
+        });
+        console.log("TestComponent: " + "CREATE OK")
+
+        Class("TestNode").inherits(Serpentity.Node)({
+            types : {
+                test : TestComponent
+            }
+        });
+        console.log("TestNode: " + "CREATE OK")
+
+
+        console.log("\n## Adding system to the engine")
+
+        var engine = new Serpentity();
+        console.log("engine: " + "CREATE OK")
+
+        engine.addSystem(testSystem, 0);
+
+        console.log("\n## Running update without any entities")
+        engine.update(10);
+
+        console.log("\n## Adding system to the engine and updating")
+        var entity = new Serpentity.Entity();
+        entity.add(new TestComponent());
+        engine.addEntity(entity);
+        engine.update(10);
+
+        console.log("\n## Adding Low Priority System")
+        engine.addSystem(lowProTestSystem, 10);
+        engine.update(10);
+
+        console.log("\n## Adding Mid Priority System")
+        engine.addSystem(midProTestSystem, 5);
+        engine.update(10);
+
+        console.log("\n## Removing the system and readding")
+        engine.removeSystem(testSystem);
+        engine.update(10);
+        engine.addSystem(testSystem, 0);
+        engine.update(10);
+
+        console.log("\n## Adding a second entity")
+        var entity = new Serpentity.Entity();
+        entity.add(new TestComponent());
+        engine.addEntity(entity);
+        engine.update(10);
+
+        console.log("\n## Removing  entity")
+        engine.removeEntity(entity)
+        engine.update(10);
+
+        console.log("\n## Removing  system")
+        engine.removeSystem(testSystem)
+        engine.update(10);
+    </script>
+  </head>
+  <body>
+    <h1>404 Droids Not Found</h1>
+    Look in your console...
+  </body>
+</html>
index d86c47e49fcbf112b1255682561f2d9a8278d19a..6d3920ccd532e441c14f998b3a12c98860ca21f1 100644 (file)
@@ -1,4 +1,6 @@
-require("neon");
+if (typeof require !== "undefined") {
+    require("neon");
+}
 
 /*
 Serpentity is a simple entity framework inspired by Ash.
 
 /*
 Serpentity is a simple entity framework inspired by Ash.
@@ -249,8 +251,10 @@ Class("Serpentity")({
     }
 });
 
     }
 });
 
-require("./component.js");
-require("./entity.js");
-require("./node.js");
-require("./node_collection.js");
-require("./system.js");
+if (typeof require !== "undefined") {
+    require("./component.js");
+    require("./entity.js");
+    require("./node.js");
+    require("./node_collection.js");
+    require("./system.js");
+}
index d5468470342ea60543e9298828f4e1d69e6e4ceb..9b87907ea3904eedd89a2df3ba760168d290bcab 100644 (file)
@@ -1,7 +1,7 @@
 {
   "name" : "serpentity",
 {
   "name" : "serpentity",
-  "description" : "A simple entity frameowrk inspired by ash",
-  "version" : "0.1.2",
+  "description" : "A simple entity framework inspired by ash",
+  "version" : "0.1.3",
   "contributors" : [
     {
       "name"  : "Ben Beltran",
   "contributors" : [
     {
       "name"  : "Ben Beltran",