diff options
Diffstat (limited to 'browser_test')
| -rw-r--r-- | browser_test/index.html | 161 |
1 files changed, 161 insertions, 0 deletions
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> |