aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bower.json31
-rw-r--r--browser_test/index.html161
-rw-r--r--lib/serpentity/serpentity.js16
-rw-r--r--package.json4
5 files changed, 205 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index da23d0d..e5a4385 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
+bower_modules
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..985e6c8
--- /dev/null
+++ b/bower.json
@@ -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
index 0000000..9133ed5
--- /dev/null
+++ b/browser_test/index.html
@@ -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>
diff --git a/lib/serpentity/serpentity.js b/lib/serpentity/serpentity.js
index d86c47e..6d3920c 100644
--- a/lib/serpentity/serpentity.js
+++ b/lib/serpentity/serpentity.js
@@ -1,4 +1,6 @@
-require("neon");
+if (typeof require !== "undefined") {
+ require("neon");
+}
/*
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");
+}
diff --git a/package.json b/package.json
index d546847..9b87907 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"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",