diff --git a/example/assets/entities/client/boulder.json b/example/assets/entities/client/boulder.json deleted file mode 100644 index 7b37794..0000000 --- a/example/assets/entities/client/boulder.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Transform2D" : null, - "Sprite" : { "width" : 100, "height" : 100, "url" : "assets/images/boulder.png" } -} \ No newline at end of file diff --git a/example/assets/entities/client/particle.json b/example/assets/entities/client/particle.json deleted file mode 100644 index a7cfef4..0000000 --- a/example/assets/entities/client/particle.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Transform2D" : null, - "Sprite" : { "width" : 10, "height" : 10, "url" : "assets/images/particle.png" }, - "Physics" : null, - "Lifetime" : 500 -} \ No newline at end of file diff --git a/example/assets/entities/client/player.json b/example/assets/entities/client/player.json deleted file mode 100644 index b0c8985..0000000 --- a/example/assets/entities/client/player.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "Transform2D" : null, - "Sprite" : { "width" : 100, "height" : 100, "url" : "assets/images/player.png" }, - "PlayerController" : null, - "PlayerLogic" : null, - "Physics" : null -} \ No newline at end of file diff --git a/example/assets/entities/client/scene.json b/example/assets/entities/client/scene.json deleted file mode 100644 index f64aa61..0000000 --- a/example/assets/entities/client/scene.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Transform2D" : null, - "GameLogic" : null -} \ No newline at end of file diff --git a/example/assets/entities/server/player.json b/example/assets/entities/server/player.json deleted file mode 100644 index c83bd8a..0000000 --- a/example/assets/entities/server/player.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "Transform2D" : null, - "PlayerSync" : { "mode" : "source"}, - "PlayerLogic" : null -} \ No newline at end of file diff --git a/example/assets/entities/server/scene.json b/example/assets/entities/server/scene.json deleted file mode 100644 index 65b7b27..0000000 --- a/example/assets/entities/server/scene.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Transform2D" : null, - "Synchronizer" : { "mode" : "source"} -} \ No newline at end of file diff --git a/example/assets/images/boulder.png b/example/assets/images/boulder.png deleted file mode 100644 index f6b8017..0000000 Binary files a/example/assets/images/boulder.png and /dev/null differ diff --git a/example/assets/images/particle.png b/example/assets/images/particle.png deleted file mode 100644 index 1bbce8a..0000000 Binary files a/example/assets/images/particle.png and /dev/null differ diff --git a/example/assets/images/player.png b/example/assets/images/player.png deleted file mode 100644 index 2a68c96..0000000 Binary files a/example/assets/images/player.png and /dev/null differ diff --git a/example/assets/test.json b/example/assets/test.json deleted file mode 100644 index cdb4ed4..0000000 --- a/example/assets/test.json +++ /dev/null @@ -1 +0,0 @@ -{"test":12} \ No newline at end of file diff --git a/example/assets/test.png b/example/assets/test.png deleted file mode 100644 index bd7c8e6..0000000 Binary files a/example/assets/test.png and /dev/null differ diff --git a/example/assets/test.txt b/example/assets/test.txt deleted file mode 100644 index a49f6bd..0000000 --- a/example/assets/test.txt +++ /dev/null @@ -1,3 +0,0 @@ -H E L L O -L E O -: ^ ) \ No newline at end of file diff --git a/example/assets/world01.json b/example/assets/world01.json deleted file mode 100644 index af32f8a..0000000 --- a/example/assets/world01.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [100, 100] - } -}, - -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [-100, 100] - } -}, - -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [-100, -100] - } -}, - -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [100, -100] - } -}, -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [0, 200] - } -}, -{ - "type" : "Boulder", - "Transform2D" : { - "position" : [0, -200] - } -} - - - - -] \ No newline at end of file diff --git a/example/bootstrap.js b/example/bootstrap.js deleted file mode 100644 index 5df7e3c..0000000 --- a/example/bootstrap.js +++ /dev/null @@ -1,6 +0,0 @@ -var traceur = require('traceur'); -traceur.require.makeDefault(function(filename) { - // don't transpile our dependencies, just our app - return filename.indexOf('node_modules') === -1; -}); -require('./dist/server.js'); \ No newline at end of file diff --git a/example/bower.json b/example/bower.json deleted file mode 100644 index 80d651e..0000000 --- a/example/bower.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "CruftEngine", - "homepage": "https://github.com/mjneil/CruftEngine", - "description": "cruft", - "main": "", - "moduleType": [ - "amd" - ], - "license": "MIT", - "private": true, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "dependencies": { - "traceur": "^0.0.95", - "peerjs": "^0.3.14" - } -} diff --git a/example/build/client.js b/example/build/client.js new file mode 100644 index 0000000..2fbe5ab --- /dev/null +++ b/example/build/client.js @@ -0,0 +1,58 @@ +"use strict"; +var $__js_47_client_47_initialize__, + $__engine_47_Engine__, + $__engine_47_graphics_47_Camera2D__, + $__engine_47_core_47_Actor__, + $__engine_47_processes_47_Script__; +var initialize = ($__js_47_client_47_initialize__ = require("./js/client/initialize"), $__js_47_client_47_initialize__ && $__js_47_client_47_initialize__.__esModule && $__js_47_client_47_initialize__ || {default: $__js_47_client_47_initialize__}).default; +var engine = ($__engine_47_Engine__ = require("engine/Engine"), $__engine_47_Engine__ && $__engine_47_Engine__.__esModule && $__engine_47_Engine__ || {default: $__engine_47_Engine__}).default; +var Camera2D = ($__engine_47_graphics_47_Camera2D__ = require("engine/graphics/Camera2D"), $__engine_47_graphics_47_Camera2D__ && $__engine_47_graphics_47_Camera2D__.__esModule && $__engine_47_graphics_47_Camera2D__ || {default: $__engine_47_graphics_47_Camera2D__}).default; +var Actor = ($__engine_47_core_47_Actor__ = require("engine/core/Actor"), $__engine_47_core_47_Actor__ && $__engine_47_core_47_Actor__.__esModule && $__engine_47_core_47_Actor__ || {default: $__engine_47_core_47_Actor__}).default; +var Script = ($__engine_47_processes_47_Script__ = require("engine/processes/Script"), $__engine_47_processes_47_Script__ && $__engine_47_processes_47_Script__.__esModule && $__engine_47_processes_47_Script__ || {default: $__engine_47_processes_47_Script__}).default; +initialize(); +var main = function() { + engine.camera = new Camera2D(window.innerWidth, window.innerHeight); + var player = engine.factory.create(Actor, "Player"); + engine.scene.addChild(player); + engine.scene.addChild(engine.camera); + engine.scene.getComponent("GameLogic").player = player; + engine.scheduler.addChild(new Script(function() { + engine.camera.render(); + })); +}; +engine.running.then(main); +window.engine = engine; +window.kill = function() { + engine.scheduler.kill(); +}; +window.onbeforeonload = function() { + engine.network.peer.destroy(); +}; +engine.cache.get("assets/world01.json").then(function(world) { + var $__9 = true; + var $__10 = false; + var $__11 = undefined; + try { + for (var $__7 = void 0, + $__6 = (world)[Symbol.iterator](); !($__9 = ($__7 = $__6.next()).done); $__9 = true) { + var actor = $__7.value; + { + var boulder = engine.factory.create(Actor, "Boulder", actor); + engine.scene.addChild(boulder); + } + } + } catch ($__12) { + $__10 = true; + $__11 = $__12; + } finally { + try { + if (!$__9 && $__6.return != null) { + $__6.return(); + } + } finally { + if ($__10) { + throw $__11; + } + } + } +}); diff --git a/example/build/js/client/Physics.js b/example/build/js/client/Physics.js new file mode 100644 index 0000000..eb8d6e8 --- /dev/null +++ b/example/build/js/client/Physics.js @@ -0,0 +1,32 @@ +"use strict"; +var $__engine_47_core_47_Component__, + $__engine_47_lib_47_gl_45_matrix__; +var Component = ($__engine_47_core_47_Component__ = require("engine/core/Component"), $__engine_47_core_47_Component__ && $__engine_47_core_47_Component__.__esModule && $__engine_47_core_47_Component__ || {default: $__engine_47_core_47_Component__}).default; +var vec2 = ($__engine_47_lib_47_gl_45_matrix__ = require("engine/lib/gl-matrix"), $__engine_47_lib_47_gl_45_matrix__ && $__engine_47_lib_47_gl_45_matrix__.__esModule && $__engine_47_lib_47_gl_45_matrix__ || {default: $__engine_47_lib_47_gl_45_matrix__}).vec2; +var Physics = function($__super) { + function Physics() { + $traceurRuntime.superConstructor(Physics).call(this, "Physics"); + this.velocity = [0, 0]; + } + return ($traceurRuntime.createClass)(Physics, { + update: function(deltaMs) { + var transform = this.actor.getComponent("transform"); + var position = transform.position; + var tmp = vec2.create(); + vec2.add(position, position, vec2.scale(tmp, this.velocity, deltaMs)); + transform.position = position; + }, + setFromJSON: function(json) { + if (!json) + return; + this.velocity = json.velocity; + } + }, {}, $__super); +}(Component); +var $__default = Physics; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/client/PlayerController.js b/example/build/js/client/PlayerController.js new file mode 100644 index 0000000..534f095 --- /dev/null +++ b/example/build/js/client/PlayerController.js @@ -0,0 +1,70 @@ +"use strict"; +var $__engine_47_core_47_Component__, + $__engine_47_lib_47_gl_45_matrix__, + $__engine_47_Engine__; +var Component = ($__engine_47_core_47_Component__ = require("engine/core/Component"), $__engine_47_core_47_Component__ && $__engine_47_core_47_Component__.__esModule && $__engine_47_core_47_Component__ || {default: $__engine_47_core_47_Component__}).default; +var vec2 = ($__engine_47_lib_47_gl_45_matrix__ = require("engine/lib/gl-matrix"), $__engine_47_lib_47_gl_45_matrix__ && $__engine_47_lib_47_gl_45_matrix__.__esModule && $__engine_47_lib_47_gl_45_matrix__ || {default: $__engine_47_lib_47_gl_45_matrix__}).vec2; +var engine = ($__engine_47_Engine__ = require("engine/Engine"), $__engine_47_Engine__ && $__engine_47_Engine__.__esModule && $__engine_47_Engine__ || {default: $__engine_47_Engine__}).default; +var PlayerController = function($__super) { + function PlayerController(connection) { + var $__5, + $__6, + $__7, + $__8; + $traceurRuntime.superConstructor(PlayerController).call(this, "PlayerController"); + this.keyStates = {}; + this.last = {}; + this.fire = false; + this.mouse = [window.innerWidth / 2, window.innerHeight / 2]; + addEventListener("keydown", ($__5 = this, function(e) { + $__5.keyStates[String.fromCharCode(e.which)] = true; + })); + addEventListener("keyup", ($__6 = this, function(e) { + $__6.keyStates[String.fromCharCode(e.which)] = false; + })); + addEventListener("mousemove", ($__7 = this, function(e) { + $__7.mouse[0] = e.pageX; + $__7.mouse[1] = e.pageY; + })); + addEventListener("mousedown", ($__8 = this, function(e) { + $__8.fire = true; + })); + } + return ($traceurRuntime.createClass)(PlayerController, {update: function(deltaMs) { + var events = {}; + var keyStates = this.keyStates; + var last = this.last; + for (var key in keyStates) { + if (keyStates[key] !== last[key]) { + if (key == "W") { + events["SET_MOVING_UP"] = keyStates[key]; + } + if (key == "A") { + events["SET_MOVING_LEFT"] = keyStates[key]; + } + if (key == "S") { + events["SET_MOVING_DOWN"] = keyStates[key]; + } + if (key == "D") { + events["SET_MOVING_RIGHT"] = keyStates[key]; + } + } + } + if (Object.keys(events).length) { + engine.emit("PlayerController:events", events); + this.last = JSON.parse(JSON.stringify(this.keyStates)); + } + engine.emit("PlayerController:mouse", engine.camera.mouseToWorld(this.mouse)); + if (this.fire) { + this.fire = false; + engine.emit("PlayerController:events", {FIRE: true}); + } + }}, {}, $__super); +}(Component); +var $__default = PlayerController; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/client/initialize.js b/example/build/js/client/initialize.js new file mode 100644 index 0000000..b39c9a1 --- /dev/null +++ b/example/build/js/client/initialize.js @@ -0,0 +1,51 @@ +"use strict"; +var $__engine_47_Initialize__, + $__engine_47_components_47_Transform2D__, + $___46__46__47_shared_47_PlayerLogic__, + $__PlayerController__, + $___46__46__47_shared_47_GameLogic__, + $__engine_47_components_47_Sprite__, + $__Physics__, + $__engine_47_components_47_Lifetime__, + $___46__46__47_shared_47_constants__; +var Initialize = ($__engine_47_Initialize__ = require("engine/Initialize"), $__engine_47_Initialize__ && $__engine_47_Initialize__.__esModule && $__engine_47_Initialize__ || {default: $__engine_47_Initialize__}).default; +var Transform2D = ($__engine_47_components_47_Transform2D__ = require("engine/components/Transform2D"), $__engine_47_components_47_Transform2D__ && $__engine_47_components_47_Transform2D__.__esModule && $__engine_47_components_47_Transform2D__ || {default: $__engine_47_components_47_Transform2D__}).default; +var PlayerLogic = ($___46__46__47_shared_47_PlayerLogic__ = require("../shared/PlayerLogic"), $___46__46__47_shared_47_PlayerLogic__ && $___46__46__47_shared_47_PlayerLogic__.__esModule && $___46__46__47_shared_47_PlayerLogic__ || {default: $___46__46__47_shared_47_PlayerLogic__}).default; +var PlayerController = ($__PlayerController__ = require("./PlayerController"), $__PlayerController__ && $__PlayerController__.__esModule && $__PlayerController__ || {default: $__PlayerController__}).default; +var GameLogic = ($___46__46__47_shared_47_GameLogic__ = require("../shared/GameLogic"), $___46__46__47_shared_47_GameLogic__ && $___46__46__47_shared_47_GameLogic__.__esModule && $___46__46__47_shared_47_GameLogic__ || {default: $___46__46__47_shared_47_GameLogic__}).default; +var Sprite = ($__engine_47_components_47_Sprite__ = require("engine/components/Sprite"), $__engine_47_components_47_Sprite__ && $__engine_47_components_47_Sprite__.__esModule && $__engine_47_components_47_Sprite__ || {default: $__engine_47_components_47_Sprite__}).default; +var Physics = ($__Physics__ = require("./Physics"), $__Physics__ && $__Physics__.__esModule && $__Physics__ || {default: $__Physics__}).default; +var Lifetime = ($__engine_47_components_47_Lifetime__ = require("engine/components/Lifetime"), $__engine_47_components_47_Lifetime__ && $__engine_47_components_47_Lifetime__.__esModule && $__engine_47_components_47_Lifetime__ || {default: $__engine_47_components_47_Lifetime__}).default; +var PEERJS_API_KEY = ($___46__46__47_shared_47_constants__ = require("../shared/constants"), $___46__46__47_shared_47_constants__ && $___46__46__47_shared_47_constants__.__esModule && $___46__46__47_shared_47_constants__ || {default: $___46__46__47_shared_47_constants__}).PEERJS_API_KEY; +var $__default = function() { + Initialize({ + scene: { + id: 1, + type: "Scene" + }, + scheduler: {deltaMs: 17}, + factory: { + skeletons: { + "assets/entities/client/player.json": "Player", + "assets/entities/client/scene.json": "Scene", + "assets/entities/client/particle.json": "Particle", + "assets/entities/client/boulder.json": "Boulder" + }, + components: { + "Transform2D": Transform2D, + "PlayerLogic": PlayerLogic, + "PlayerController": PlayerController, + "GameLogic": GameLogic, + "Sprite": Sprite, + "Physics": Physics, + "Lifetime": Lifetime + } + } + }); +}; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/server/initialize.js b/example/build/js/server/initialize.js new file mode 100644 index 0000000..45ac968 --- /dev/null +++ b/example/build/js/server/initialize.js @@ -0,0 +1,41 @@ +"use strict"; +var $__engine_47_Initialize__, + $__engine_47_components_47_Transform2D__, + $__engine_47_components_47_Synchronizer__, + $___46__46__47_shared_47_constants__, + $___46__46__47_shared_47_PlayerLogic__; +var Initialize = ($__engine_47_Initialize__ = require("engine/Initialize"), $__engine_47_Initialize__ && $__engine_47_Initialize__.__esModule && $__engine_47_Initialize__ || {default: $__engine_47_Initialize__}).default; +var Transform2D = ($__engine_47_components_47_Transform2D__ = require("engine/components/Transform2D"), $__engine_47_components_47_Transform2D__ && $__engine_47_components_47_Transform2D__.__esModule && $__engine_47_components_47_Transform2D__ || {default: $__engine_47_components_47_Transform2D__}).default; +var Synchronizer = ($__engine_47_components_47_Synchronizer__ = require("engine/components/Synchronizer"), $__engine_47_components_47_Synchronizer__ && $__engine_47_components_47_Synchronizer__.__esModule && $__engine_47_components_47_Synchronizer__ || {default: $__engine_47_components_47_Synchronizer__}).default; +var PEERJS_API_KEY = ($___46__46__47_shared_47_constants__ = require("../shared/constants"), $___46__46__47_shared_47_constants__ && $___46__46__47_shared_47_constants__.__esModule && $___46__46__47_shared_47_constants__ || {default: $___46__46__47_shared_47_constants__}).PEERJS_API_KEY; +var PlayerLogic = ($___46__46__47_shared_47_PlayerLogic__ = require("../shared/PlayerLogic"), $___46__46__47_shared_47_PlayerLogic__ && $___46__46__47_shared_47_PlayerLogic__.__esModule && $___46__46__47_shared_47_PlayerLogic__ || {default: $___46__46__47_shared_47_PlayerLogic__}).default; +var $__default = function() { + Initialize({ + network: { + name: "game", + key: PEERJS_API_KEY + }, + scene: { + id: 1, + type: "Scene" + }, + scheduler: {deltaMs: 33}, + factory: { + skeletons: { + "assets/entities/server/player.json": "Player", + "assets/entities/server/scene.json": "Scene" + }, + components: { + "Transform2D": Transform2D, + "Synchronizer": Synchronizer, + "PlayerLogic": PlayerLogic + } + } + }); +}; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/shared/GameLogic.js b/example/build/js/shared/GameLogic.js new file mode 100644 index 0000000..b5aca17 --- /dev/null +++ b/example/build/js/shared/GameLogic.js @@ -0,0 +1,31 @@ +"use strict"; +var $__engine_47_core_47_Component__, + $__engine_47_Engine__; +var Component = ($__engine_47_core_47_Component__ = require("engine/core/Component"), $__engine_47_core_47_Component__ && $__engine_47_core_47_Component__.__esModule && $__engine_47_core_47_Component__ || {default: $__engine_47_core_47_Component__}).default; +var engine = ($__engine_47_Engine__ = require("engine/Engine"), $__engine_47_Engine__ && $__engine_47_Engine__.__esModule && $__engine_47_Engine__ || {default: $__engine_47_Engine__}).default; +var GameLogic = function($__super) { + function GameLogic() { + var $__5, + $__6; + $traceurRuntime.superConstructor(GameLogic).call(this, "GameLogic"); + this.player = null; + engine.on("PlayerController:events", ($__5 = this, function(events) { + if ($__5.player) { + $__5.player.getComponent("PlayerLogic").handleEvents(events); + } + })); + engine.on("PlayerController:mouse", ($__6 = this, function(events) { + if ($__6.player) { + $__6.player.getComponent("PlayerLogic").handleMouse(events); + } + })); + } + return ($traceurRuntime.createClass)(GameLogic, {}, {}, $__super); +}(Component); +var $__default = GameLogic; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/shared/PlayerLogic.js b/example/build/js/shared/PlayerLogic.js new file mode 100644 index 0000000..f9157ce --- /dev/null +++ b/example/build/js/shared/PlayerLogic.js @@ -0,0 +1,89 @@ +"use strict"; +var $__engine_47_core_47_Component__, + $__engine_47_lib_47_gl_45_matrix__, + $__engine_47_core_47_Actor__, + $__engine_47_processes_47_Interval__, + $__engine_47_math_47_random__; +var Component = ($__engine_47_core_47_Component__ = require("engine/core/Component"), $__engine_47_core_47_Component__ && $__engine_47_core_47_Component__.__esModule && $__engine_47_core_47_Component__ || {default: $__engine_47_core_47_Component__}).default; +var vec2 = ($__engine_47_lib_47_gl_45_matrix__ = require("engine/lib/gl-matrix"), $__engine_47_lib_47_gl_45_matrix__ && $__engine_47_lib_47_gl_45_matrix__.__esModule && $__engine_47_lib_47_gl_45_matrix__ || {default: $__engine_47_lib_47_gl_45_matrix__}).vec2; +var Actor = ($__engine_47_core_47_Actor__ = require("engine/core/Actor"), $__engine_47_core_47_Actor__ && $__engine_47_core_47_Actor__.__esModule && $__engine_47_core_47_Actor__ || {default: $__engine_47_core_47_Actor__}).default; +var Interval = ($__engine_47_processes_47_Interval__ = require("engine/processes/Interval"), $__engine_47_processes_47_Interval__ && $__engine_47_processes_47_Interval__.__esModule && $__engine_47_processes_47_Interval__ || {default: $__engine_47_processes_47_Interval__}).default; +var randomRange = ($__engine_47_math_47_random__ = require("engine/math/random"), $__engine_47_math_47_random__ && $__engine_47_math_47_random__.__esModule && $__engine_47_math_47_random__ || {default: $__engine_47_math_47_random__}).randomRange; +var PlayerLogic = function($__super) { + function PlayerLogic() { + var $__8; + $traceurRuntime.superConstructor(PlayerLogic).call(this, "PlayerLogic"); + this.movingLeft = false; + this.movingRight = false; + this.movingUp = false; + this.movingDown = false; + this.target = [1, 0]; + this.speed = .7; + this.fire = false; + this.processes = new Interval(($__8 = this, function(now, deltaMs) { + var world = $__8.target; + for (var i = 0; i < 10; i++) { + var actor = engine.factory.create(Actor, "Particle", { + Transform2D: {position: world}, + Physics: {velocity: [randomRange(-.5, .5), randomRange(-.5, .5)]} + }); + engine.scene.addChild(actor); + } + }), 500); + engine.scheduler.addChild(this.processes); + } + return ($traceurRuntime.createClass)(PlayerLogic, { + destructor: function() { + $traceurRuntime.superGet(this, PlayerLogic.prototype, "destructor").call(this); + this.processes.succeed(); + }, + update: function(deltaMs) { + var actor = this.actor; + var transform = actor.getComponent("transform"); + var position = transform.position; + var speed = this.speed; + if (this.movingLeft) { + position[0] -= speed * deltaMs; + } + if (this.movingRight) { + position[0] += speed * deltaMs; + } + if (this.movingUp) { + position[1] += speed * deltaMs; + } + if (this.movingDown) { + position[1] -= speed * deltaMs; + } + transform.position = position; + var world = this.actor.getComponent("transform").getWorldPosition(); + var dif = vec2.create(); + vec2.sub(dif, this.target, position); + transform.setDirection(dif); + if (this.fire) { + this.fire = false; + } + }, + handleEvents: function(events) { + if (events["SET_MOVING_UP"] !== undefined) + this.movingUp = events["SET_MOVING_UP"]; + if (events["SET_MOVING_DOWN"] !== undefined) + this.movingDown = events["SET_MOVING_DOWN"]; + if (events["SET_MOVING_LEFT"] !== undefined) + this.movingLeft = events["SET_MOVING_LEFT"]; + if (events["SET_MOVING_RIGHT"] !== undefined) + this.movingRight = events["SET_MOVING_RIGHT"]; + if (events["FIRE"]) + this.fire = true; + }, + handleMouse: function(mouse) { + this.target = mouse; + } + }, {}, $__super); +}(Component); +var $__default = PlayerLogic; +Object.defineProperties(module.exports, { + default: {get: function() { + return $__default; + }}, + __esModule: {value: true} +}); diff --git a/example/build/js/shared/constants.js b/example/build/js/shared/constants.js new file mode 100644 index 0000000..8d9cdfe --- /dev/null +++ b/example/build/js/shared/constants.js @@ -0,0 +1,8 @@ +"use strict"; +var PEERJS_API_KEY = "vu5babwam1tnjyvi"; +Object.defineProperties(module.exports, { + PEERJS_API_KEY: {get: function() { + return PEERJS_API_KEY; + }}, + __esModule: {value: true} +}); diff --git a/example/build/server.js b/example/build/server.js new file mode 100644 index 0000000..cc53ef1 --- /dev/null +++ b/example/build/server.js @@ -0,0 +1,17 @@ +"use strict"; +var $__js_47_server_47_initialize__, + $__engine_47_Engine__; +var initialize = ($__js_47_server_47_initialize__ = require("./js/server/initialize"), $__js_47_server_47_initialize__ && $__js_47_server_47_initialize__.__esModule && $__js_47_server_47_initialize__ || {default: $__js_47_server_47_initialize__}).default; +var engine = ($__engine_47_Engine__ = require("engine/Engine"), $__engine_47_Engine__ && $__engine_47_Engine__.__esModule && $__engine_47_Engine__ || {default: $__engine_47_Engine__}).default; +initialize(); +var main = function() { + console.info("Cruft Running"); +}; +engine.running.then(main); +window.engine = engine; +window.kill = function() { + engine.scheduler.kill(); +}; +window.onbeforeonload = function() { + engine.network.peer.destroy(); +}; diff --git a/example/client.html b/example/client.html deleted file mode 100644 index 111a5d3..0000000 --- a/example/client.html +++ /dev/null @@ -1,20 +0,0 @@ - -
- - - - - - - - - \ No newline at end of file diff --git a/example/client.js b/example/client.js index 00a86d9..91e9d5f 100644 --- a/example/client.js +++ b/example/client.js @@ -10,7 +10,6 @@ initialize(); //think about map loading in terms of syncing id's of every asset. Like what if a rock needs to be of the sync. - var main = () => { engine.camera = new Camera2D(window.innerWidth, window.innerHeight); //also todo make a real camera class. diff --git a/example/css/style.css b/example/css/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/example/js/client/initialize.js b/example/js/client/initialize.js index 35204fe..cfe2c2b 100644 --- a/example/js/client/initialize.js +++ b/example/js/client/initialize.js @@ -1,14 +1,14 @@ //engine import Initialize from "engine/Initialize"; import Transform2D from "engine/components/Transform2D"; -import PlayerLogic from "../server/PlayerLogic"; +import PlayerLogic from "../shared/PlayerLogic"; import PlayerController from "./PlayerController"; -import GameLogic from "../server/GameLogic" +import GameLogic from "../shared/GameLogic" import Sprite from "engine/components/Sprite"; import Physics from "./Physics"; import Lifetime from "engine/components/Lifetime"; //example -import {PEERJS_API_KEY} from "../constants"; +import {PEERJS_API_KEY} from "../shared/constants"; //maybe include some of this stuff within the Map File? //No reason map file can't be valid javacript //could just have like a //map.get.init() or somthing diff --git a/example/js/server/initialize.js b/example/js/server/initialize.js index 8354731..6eb98d6 100644 --- a/example/js/server/initialize.js +++ b/example/js/server/initialize.js @@ -4,8 +4,8 @@ import Transform2D from "engine/components/Transform2D"; import Synchronizer from "engine/components/Synchronizer"; //example -import {PEERJS_API_KEY} from "../constants"; -import PlayerLogic from "./PlayerLogic"; +import {PEERJS_API_KEY} from "../shared/constants"; +import PlayerLogic from "../shared/PlayerLogic"; export default () =>{ diff --git a/example/js/server/GameLogic.js b/example/js/shared/GameLogic.js similarity index 100% rename from example/js/server/GameLogic.js rename to example/js/shared/GameLogic.js diff --git a/example/js/server/PlayerLogic.js b/example/js/shared/PlayerLogic.js similarity index 100% rename from example/js/server/PlayerLogic.js rename to example/js/shared/PlayerLogic.js diff --git a/example/js/constants.js b/example/js/shared/constants.js similarity index 100% rename from example/js/constants.js rename to example/js/shared/constants.js diff --git a/example/package.json b/example/package.json deleted file mode 100644 index 6957fd1..0000000 --- a/example/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "example", - "version": "0.0.0", - "description": "", - "main": "client.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node server.js" - }, - "author": "", - "license": "BSD-2-Clause", - "dependencies": { - "express": "~4.13.4", - "socket.io": "~1.4.5" - } -} diff --git a/example/server.html b/example/server.html deleted file mode 100644 index 3da497f..0000000 --- a/example/server.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 74a9a61..a8259ed 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,11 +6,32 @@ var concat = require("gulp-concat"); var del = require("del"); var gls = require('gulp-live-server'); var runSequence = require('run-sequence'); +var cache = require('gulp-cached'); var server = gls.new("server.js"); + var ENGINE_SRC = ["engine/**/*.js"]; -var GAME_SRC = ["example/js/**/**.js", "example/server.js", "example/client.js"]; +var RAW_SRC = [ + "example/js/client/**/*.js", + "example/js/server/**/*.js", + "example/js/shared/**/*.js", + "example/client.js", + "example/server.js" + ]; + +var CLIENT_SRC = [ + "example/build/js/client/**/*.js", + "example/build/js/shared/**/*.js", + "example/build/client.js", + "example/build/node_modules/engine/**/*.js" + ]; +var SERVER_SRC = [ + "example/build/js/server/**/*.js", + "example/build/js/shared/**/*.js", + "example/build/server.js", + "example/build/node_modules/engine/**/*.js" + ]; var onerror = function (e) { console.log("\033[31m WARNING: YOUR STUFF ISNT TRANSPILING") @@ -18,74 +39,63 @@ var onerror = function (e) { this.emit("end"); } -gulp.task("js:clean:tmp", function () { - return del(["tmp/"]); -}) -gulp.task("js:clean:dist", function () { - return del(["example/dist/**.js"]); +gulp.task("js:clean", function () { + return del(["example/build/"]); }) gulp.task("js:engine", function () { return gulp.src(ENGINE_SRC) + .pipe(cache('engine')) .pipe(tracuer()) .on("error", onerror) - .pipe(gulp.dest("tmp/node_modules/engine")) + .pipe(gulp.dest("example/build/node_modules/engine/")) }) -gulp.task("js:game", function () { - return gulp.src(GAME_SRC, {base :"./example"}) +gulp.task("js:tracuer", function () { + return gulp.src(RAW_SRC, {base :"./example"}) + .pipe(cache('source')) .pipe(tracuer()) .on("error", onerror) - .pipe(gulp.dest("tmp/")) + .pipe(gulp.dest("example/build/")) }) -gulp.task("js:browserify:client", function () { - return browserify("tmp/client.js") +gulp.task("js:client", function () { + return browserify("example/build/client.js") .bundle() .on("error", onerror) .pipe(source('client.js')) .pipe(gulp.dest("example/dist/")) }) -gulp.task("js:browserify:server", function () { - return browserify("tmp/server.js") +gulp.task("js:server", function () { + return browserify("example/build/server.js") .bundle() .on("error", onerror) - .pipe(source('server.js')) + .pipe(source("server.js")) .pipe(gulp.dest("example/dist/")) }) -gulp.task("js:build:client", function () { - return gulp.src(["engine/lib/gl-matrix.js", "tmp/dist/client.js"]) - .pipe(concat("client.js")) - .pipe(gulp.dest("example/dist")) -}) - -gulp.task("js:build:server", function () { - return gulp.src(["engine/lib/gl-matrix.js", "tmp/dist/server.js"]) - .pipe(concat("server.js")) - .pipe(gulp.dest("example/dist/")) -}) -gulp.task("js:all", function () { - //server.start(server); - runSequence( - ["js:clean:tmp", "js:clean:dist"], - ["js:engine", "js:game"], - ["js:browserify:client", "js:browserify:server"], - "server" - ); +gulp.task("js:watch", function () { + gulp.watch(ENGINE_SRC, ["js:engine"]); + gulp.watch(RAW_SRC, ["js:tracuer"]); + gulp.watch(CLIENT_SRC, ["js:client"]) + gulp.watch(SERVER_SRC, ["js:server"]); }) gulp.task("server", function () { - server.start.bind(server)(); + var server = gls.static('example/dist', 8888); + server.start(); }) //echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p -gulp.task("default", ["js:all"], function () { - - gulp.watch(ENGINE_SRC, ["js:all"]); - gulp.watch(GAME_SRC, ["js:all"]); - //gulp.watch(SERVER_SRC, ["js:all"]); +gulp.task("default", function () { + runSequence( + "js:clean", + ["js:engine", "js:tracuer"], + ["js:client", "js:server"], + "js:watch", + "server" + ); }) \ No newline at end of file diff --git a/package.json b/package.json index 228f8c2..5d58fb7 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ "example": "example" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "node server.js" + "test": "gulp" }, "repository": { "type": "git", @@ -28,9 +27,7 @@ "browserify": "~13.0.0", "gulp-live-server": "0.0.29", "express": "~4.13.4", - "run-sequence": "~1.1.5" - }, - "scripts" : { - "test" : "gulp" + "run-sequence": "~1.1.5", + "gulp-cached": "~1.1.0" } } diff --git a/server.js b/server.js deleted file mode 100644 index c03bff9..0000000 --- a/server.js +++ /dev/null @@ -1,8 +0,0 @@ - -var express = require("express"); - -var app = express(); - app.use(express.static(__dirname + "/example/")); - app.listen(8080); - -console.log("Server listening on Port 8080") \ No newline at end of file