VimUnDoaɋG!HfF(Gu۫V13c_#VTX "use strict";var Input = require("./input");var Scene = require("./scene");function clone(obj) { if (obj === undefined) { return undefined; }( return JSON.parse(JSON.stringify(obj));}/function splitFilmStripAnimations(animations) {0 Object.keys(animations).forEach(function(key) {& var firstFrame = animations[key][0];# if (firstFrame.filmstripFrames) {, splitFilmStripAnimation(animations, key); } });}3function splitFilmStripAnimation(animations, key) {% var firstFrame = animations[key][0];Q if (firstFrame.properties.image.sourceWidth % firstFrame.filmstripFrames != 0) { console.warn("The \"" + key + "\" animation is " + firstFrame.properties.image.sourceWidth + " pixels wide and that is is not evenly divisible by " + firstFrame.filmstripFrames + " frames."); }7 for (var i = 0; i < firstFrame.filmstripFrames; i++) {X var frameWidth = firstFrame.properties.image.sourceWidth / firstFrame.filmstripFrames;# var newFrame = clone(firstFrame);5 newFrame.properties.image.sourceX = frameWidth * i;5 newFrame.properties.image.sourceWidth = frameWidth;! animations[key].push(newFrame); } animations[key].splice(0,1);}^function Game(canvas, animations, entities, images, input, require, scenes, sounds, systems) {& splitFilmStripAnimations(animations); this.animations = animations; this.canvas = canvas;( this.context = canvas.getContext("2d"); this.entities = entities; this.images = images;' this.input = new Input(input, canvas); this.require = require; this.scenes = scenes; this.sounds = sounds; this.systems = systems; this.scaleCanvasToCssSize();C window.addEventListener("resize", this.onCanvasResize.bind(this)); this.makeScenes(scenes);}1Game.prototype.makeScenes = function(sceneList) {1 Object.keys(sceneList).forEach(function(scene) { if (sceneList[scene].first) {< this.scene = this.makeScene(scene, sceneList[scene], {}); } }.bind(this));};AGame.prototype.makeScene = function(name, sceneData, sceneArgs) { var scene = new Scene();: var data = this.makeSceneData(scene.entities, sceneArgs);" scene.simulation.add(function() { data.input.processUpdates(); });L this.installSystems(name, this.systems.simulation, scene.simulation, data);H this.installSystems(name, this.systems.renderer, scene.renderer, data);1 scene.entities.load(clone(this.entities[name]));- if (typeof sceneData.onEnter === "string") {4 var enterScript = this.require(sceneData.onEnter);* if (typeof enterScript === "function") {/ enterScript = enterScript.bind(scene, data); } scene.onEnter = enterScript; }, if (typeof sceneData.onExit === "string") {2 var exitScript = this.require(sceneData.onExit);) if (typeof exitScript === "function") {- exitScript = exitScript.bind(scene, data); } scene.onExit = exitScript; } return scene;};>Game.prototype.makeSceneData = function(entities, sceneArgs) { return { animations: this.animations, arguments: sceneArgs || {}, canvas: this.canvas, context: this.context, entities: entities, images: this.images, input: this.input, require: this.require,= scaleCanvasToCssSize: this.scaleCanvasToCssSize.bind(this),G scaleCanvasToFitRectangle: this.scaleCanvasToFitRectangle.bind(this), sounds: this.sounds,* switchScene: this.switchScene.bind(this) };};EGame.prototype.installSystems = function(scene, systems, ecs, data) {# systems.forEach(function(system) {, if (system.scenes.indexOf(scene) === -1) { return; }) var script = this.require(system.name); if (script === undefined) {7 console.error("failed to load script", system.name); } script(ecs, data); }.bind(this));};8Game.prototype.switchScene = function(name, sceneArgs) { if (this.scene !== undefined) { this.scene.stop(); }A this.scene = this.makeScene(name, this.scenes[name], sceneArgs); this.scene.start(this.context);};,Game.prototype.onCanvasResize = function() { this.resizer();};2Game.prototype.scaleCanvasToCssSize = function() { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);* var width = parseInt(canvasStyle.width);, var height = parseInt(canvasStyle.height); this.canvas.width = width; this.canvas.height = height; }.bind(this); this.resizer();};DGame.prototype.scaleCanvasToFitRectangle = function(width, height) { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);- var cssWidth = parseInt(canvasStyle.width);/ var cssHeight = parseInt(canvasStyle.height);, var cssAspectRatio = cssWidth / cssHeight; var desiredWidth = width; var desiredHeight = height;* var desiredAspectRatio = width / height;, if (desiredAspectRatio > cssAspectRatio) {6 desiredHeight = Math.floor(width / cssAspectRatio);3 } else if (desiredAspectRatio < cssAspectRatio) {6 desiredWidth = Math.floor(height * cssAspectRatio); }# this.canvas.width = desiredWidth;% this.canvas.height = desiredHeight; }.bind(this); this.resizer();};module.exports = Game;5_%VUb$& this.animations = animations;5_(VU{') this.entities = entities;5_VU5_VV5_VV ,var ImageLoader = require("./image-loader");5_VV,var SoundLoader = require("./image-loader");5_ *!VV)+. this.entities = require("./data/animations");5_ +VV!*, this.images = images;5_ +VV2+- +-5_ 0VVc/1 this.sounds = sounds;5_ /VV.0 this.scenes = scenes;5_  -VV,.' this.input = new Input(input, canvas);5_ 1VWH02 this.systems = systems;5_2VWZ13 this.prefabs = prefabs;5_2 VW[13* this.prefabs = require("./data/systems");5_%VWi$&gfunction Game(canvas, animations, entities, images, input, require, scenes, sounds, systems, prefabs) {5_%VWi$&]function Game(canvas, , entities, images, input, require, scenes, sounds, systems, prefabs) {5_%VWm$&[function Game(canvas, entities, images, input, require, scenes, sounds, systems, prefabs) {5_%VWn$&Sfunction Game(canvas, , images, input, require, scenes, sounds, systems, prefabs) {5_%VWq$&Qfunction Game(canvas, images, input, require, scenes, sounds, systems, prefabs) {5_%VWq$&Kfunction Game(canvas, , input, require, scenes, sounds, systems, prefabs) {5_%VWs$&Ifunction Game(canvas, input, require, scenes, sounds, systems, prefabs) {5_%VWs$&Dfunction Game(canvas, , require, scenes, sounds, systems, prefabs) {5_%VW{$&Bfunction Game(canvas, require, scenes, sounds, systems, prefabs) {5_%VW{$&=BVBD BD5_=?>DVCF });5_>@?BVAC' this.shaders.filter(function(shader) {5_?A@DVDF DF5_@BAEVHDFC shaders.compile(this.context, shader.type, require(shader.path));5_ACBFVSFH FH5_BDCG-VFH- return shaders.link(this.context, compiled, 5_CEDBVAC6 var compiled = this.shaders.filter(function(shader) {5_DFE1VJ' 13 135_EGFGVJx FH });5_FHGF4VO^ EGJ return shaders.compile(this.context, shader.type, require(shader.path));5_GIH*VO*, *,5_HJI+VU*+ console.log(this.context);5_IKJ2VYt "use strict";,var ImageLoader = require("./image-loader");var Input = require("./input");var Scene = require("./scene");#var shaders = require("./shaders");,var SoundLoader = require("./sound-loader");function clone(obj) { if (obj === undefined) { return undefined; }( return JSON.parse(JSON.stringify(obj));}/function splitFilmStripAnimations(animations) {0 Object.keys(animations).forEach(function(key) {& var firstFrame = animations[key][0];# if (firstFrame.filmstripFrames) {, splitFilmStripAnimation(animations, key); } });}3function splitFilmStripAnimation(animations, key) {% var firstFrame = animations[key][0];Q if (firstFrame.properties.image.sourceWidth % firstFrame.filmstripFrames != 0) { console.warn("The \"" + key + "\" animation is " + firstFrame.properties.image.sourceWidth + " pixels wide and that is is not evenly divisible by " + firstFrame.filmstripFrames + " frames."); }7 for (var i = 0; i < firstFrame.filmstripFrames; i++) {X var frameWidth = firstFrame.properties.image.sourceWidth / firstFrame.filmstripFrames;# var newFrame = clone(firstFrame);5 newFrame.properties.image.sourceX = frameWidth * i;5 newFrame.properties.image.sourceWidth = frameWidth;! animations[key].push(newFrame); } animations[key].splice(0,1);}&function Game(canvas, customRequire) {6 this.animations = customRequire("./data/animations");+ splitFilmStripAnimations(this.animations); this.canvas = canvas;+ this.context = canvas.getContext("webgl");2 this.entities = customRequire("./data/entities");! this.images = new ImageLoader();> this.images.loadFromManifest(customRequire("./data/images"));@ this.input = new Input(customRequire("./data/inputs"), canvas);0 this.prefabs = customRequire("./data/prefabs"); this.require = customRequire;. this.scenes = customRequire("./data/scenes");0 this.shaders = customRequire("./data/shaders");? this.sounds = new SoundLoader(customRequire("./data/sounds"));0 this.systems = customRequire("./data/systems"); this.scaleCanvasToCssSize();C window.addEventListener("resize", this.onCanvasResize.bind(this)); this.makeScenes(this.scenes);}1Game.prototype.makeScenes = function(sceneList) {1 Object.keys(sceneList).forEach(function(scene) { if (sceneList[scene].first) {< this.scene = this.makeScene(scene, sceneList[scene], {}); } }.bind(this));};/Game.prototype.buildShaders = function(scene) {> var compiled = this.shaders.shaders.filter(function(shader) {- return shader.scenes.indexOf(scene) !== -1; }).map(function(shader) {O return shaders.compile(this.context, shader.type, this.require(shader.path)); }.bind(this));h return shaders.link(this.context, compiled, this.shaders.vertexAttribArrays, this.shaders.uniformVars);};AGame.prototype.makeScene = function(name, sceneData, sceneArgs) { var scene = new Scene();: var data = this.makeSceneData(scene.entities, sceneArgs);( data.shaders = this.buildShaders(name);" scene.simulation.add(function() { data.input.processUpdates(); });L this.installSystems(name, this.systems.simulation, scene.simulation, data);H this.installSystems(name, this.systems.renderer, scene.renderer, data);1 scene.entities.load(clone(this.entities[name]));- if (typeof sceneData.onEnter === "string") {4 var enterScript = this.require(sceneData.onEnter);* if (typeof enterScript === "function") {/ enterScript = enterScript.bind(scene, data); } scene.onEnter = enterScript; }, if (typeof sceneData.onExit === "string") {2 var exitScript = this.require(sceneData.onExit);) if (typeof exitScript === "function") {- exitScript = exitScript.bind(scene, data); } scene.onExit = exitScript; } return scene;};>Game.prototype.makeSceneData = function(entities, sceneArgs) { return { animations: this.animations, arguments: sceneArgs || {}, canvas: this.canvas, context: this.context, entities: entities, images: this.images, input: this.input, require: this.require,= scaleCanvasToCssSize: this.scaleCanvasToCssSize.bind(this),G scaleCanvasToFitRectangle: this.scaleCanvasToFitRectangle.bind(this), sounds: this.sounds,+ switchScene: this.switchScene.bind(this),6 instantiatePrefab: this.instantiatePrefab.bind(this) };};EGame.prototype.installSystems = function(scene, systems, ecs, data) {# systems.forEach(function(system) {, if (system.scenes.indexOf(scene) === -1) { return; }) var script = this.require(system.name); if (script === undefined) {7 console.error("failed to load script", system.name); } script(ecs, data); }.bind(this));};8Game.prototype.switchScene = function(name, sceneArgs) { if (this.scene !== undefined) { this.scene.stop(); }A this.scene = this.makeScene(name, this.scenes[name], sceneArgs); this.scene.start(this.context);};,Game.prototype.onCanvasResize = function() { this.resizer();};2Game.prototype.scaleCanvasToCssSize = function() { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);* var width = parseInt(canvasStyle.width);, var height = parseInt(canvasStyle.height); this.canvas.width = width; this.canvas.height = height; }.bind(this); this.resizer();};DGame.prototype.scaleCanvasToFitRectangle = function(width, height) { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);- var cssWidth = parseInt(canvasStyle.width);/ var cssHeight = parseInt(canvasStyle.height);, var cssAspectRatio = cssWidth / cssHeight; var desiredWidth = width; var desiredHeight = height;* var desiredAspectRatio = width / height;, if (desiredAspectRatio > cssAspectRatio) {6 desiredHeight = Math.floor(width / cssAspectRatio);3 } else if (desiredAspectRatio < cssAspectRatio) {6 desiredWidth = Math.floor(height * cssAspectRatio); }# this.canvas.width = desiredWidth;% this.canvas.height = desiredHeight; }.bind(this); this.resizer();};3Game.prototype.instantiatePrefab = function(name) {' var id = this.scene.entities.create();! var prefab = this.prefabs[name];, Object.keys(prefab).forEach(function(key) { if (key === "id") { return; }7 this.scene.entities.set(id, key, clone(prefab[key])); }.bind(this)); return id;};module.exports = Game;5_JLK2VY{12 <<<<<<< HEAD5_KML4VY}34=======5_LNM5VY~45? this.sounds = new SoundLoader(customRequire("./data/sounds"));!>>>>>>> Actually load the shaders5_MON4VY340 this.shaders = customRequire("./data/shaders");5_NPO2VY13235_OQPV- "use strict";,var ImageLoader = require("./image-loader");var Input = require("./input");var Scene = require("./scene");#var shaders = require("./shaders");,var SoundLoader = require("./sound-loader");function clone(obj) { if (obj === undefined) { return undefined; }( return JSON.parse(JSON.stringify(obj));}/function splitFilmStripAnimations(animations) {0 Object.keys(animations).forEach(function(key) {& var firstFrame = animations[key][0];# if (firstFrame.filmstripFrames) {, splitFilmStripAnimation(animations, key); } });}3function splitFilmStripAnimation(animations, key) {% var firstFrame = animations[key][0];Q if (firstFrame.properties.image.sourceWidth % firstFrame.filmstripFrames != 0) { console.warn("The \"" + key + "\" animation is " + firstFrame.properties.image.sourceWidth + " pixels wide and that is is not evenly divisible by " + firstFrame.filmstripFrames + " frames."); }7 for (var i = 0; i < firstFrame.filmstripFrames; i++) {X var frameWidth = firstFrame.properties.image.sourceWidth / firstFrame.filmstripFrames;# var newFrame = clone(firstFrame);5 newFrame.properties.image.sourceX = frameWidth * i;5 newFrame.properties.image.sourceWidth = frameWidth;! animations[key].push(newFrame); } animations[key].splice(0,1);}&function Game(canvas, customRequire) {6 this.animations = customRequire("./data/animations");+ splitFilmStripAnimations(this.animations); this.canvas = canvas;+ this.context = canvas.getContext("webgl");2 this.entities = customRequire("./data/entities");! this.images = new ImageLoader();> this.images.loadFromManifest(customRequire("./data/images"));@ this.input = new Input(customRequire("./data/inputs"), canvas);0 this.prefabs = customRequire("./data/prefabs"); this.require = customRequire;. this.scenes = customRequire("./data/scenes");0 this.shaders = customRequire("./data/shaders");! this.sounds = new SoundLoader();> this.sounds.loadFromManifest(customRequire("./data/sounds"));0 this.systems = customRequire("./data/systems"); this.scaleCanvasToCssSize();C window.addEventListener("resize", this.onCanvasResize.bind(this)); this.makeScenes(this.scenes);}1Game.prototype.makeScenes = function(sceneList) {1 Object.keys(sceneList).forEach(function(scene) { if (sceneList[scene].first) {< this.scene = this.makeScene(scene, sceneList[scene], {}); } }.bind(this));};/Game.prototype.buildShaders = function(scene) {> var compiled = this.shaders.shaders.filter(function(shader) {- return shader.scenes.indexOf(scene) !== -1; }).map(function(shader) {O return shaders.compile(this.context, shader.type, this.require(shader.path)); }.bind(this));h return shaders.link(this.context, compiled, this.shaders.vertexAttribArrays, this.shaders.uniformVars);};AGame.prototype.makeScene = function(name, sceneData, sceneArgs) { var scene = new Scene();: var data = this.makeSceneData(scene.entities, sceneArgs);( data.shaders = this.buildShaders(name);" scene.simulation.add(function() { data.input.processUpdates(); });L this.installSystems(name, this.systems.simulation, scene.simulation, data);H this.installSystems(name, this.systems.renderer, scene.renderer, data);1 scene.entities.load(clone(this.entities[name]));- if (typeof sceneData.onEnter === "string") {4 var enterScript = this.require(sceneData.onEnter);* if (typeof enterScript === "function") {/ enterScript = enterScript.bind(scene, data); } scene.onEnter = enterScript; }, if (typeof sceneData.onExit === "string") {2 var exitScript = this.require(sceneData.onExit);) if (typeof exitScript === "function") {- exitScript = exitScript.bind(scene, data); } scene.onExit = exitScript; } return scene;};>Game.prototype.makeSceneData = function(entities, sceneArgs) { return { animations: this.animations, arguments: sceneArgs || {}, canvas: this.canvas, context: this.context, entities: entities, images: this.images, input: this.input, require: this.require,= scaleCanvasToCssSize: this.scaleCanvasToCssSize.bind(this),G scaleCanvasToFitRectangle: this.scaleCanvasToFitRectangle.bind(this), sounds: this.sounds,+ switchScene: this.switchScene.bind(this),6 instantiatePrefab: this.instantiatePrefab.bind(this) };};EGame.prototype.installSystems = function(scene, systems, ecs, data) {# systems.forEach(function(system) {, if (system.scenes.indexOf(scene) === -1) { return; }) var script = this.require(system.name); if (script === undefined) {7 console.error("failed to load script", system.name); } script(ecs, data); }.bind(this));};8Game.prototype.switchScene = function(name, sceneArgs) { if (this.scene !== undefined) { this.scene.stop(); }A this.scene = this.makeScene(name, this.scenes[name], sceneArgs); this.scene.start(this.context);};,Game.prototype.onCanvasResize = function() { this.resizer();};2Game.prototype.scaleCanvasToCssSize = function() { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);* var width = parseInt(canvasStyle.width);, var height = parseInt(canvasStyle.height); this.canvas.width = width; this.canvas.height = height; }.bind(this); this.resizer();};DGame.prototype.scaleCanvasToFitRectangle = function(width, height) { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);- var cssWidth = parseInt(canvasStyle.width);/ var cssHeight = parseInt(canvasStyle.height);, var cssAspectRatio = cssWidth / cssHeight; var desiredWidth = width; var desiredHeight = height;* var desiredAspectRatio = width / height;, if (desiredAspectRatio > cssAspectRatio) {6 desiredHeight = Math.floor(width / cssAspectRatio);3 } else if (desiredAspectRatio < cssAspectRatio) {6 desiredWidth = Math.floor(height * cssAspectRatio); }# this.canvas.width = desiredWidth;% this.canvas.height = desiredHeight; }.bind(this); this.resizer();};3Game.prototype.instantiatePrefab = function(name) {' var id = this.scene.entities.create();! var prefab = this.prefabs[name];, Object.keys(prefab).forEach(function(key) { if (key === "id") { return; }7 this.scene.entities.set(id, key, clone(prefab[key])); }.bind(this)); return id;};module.exports = Game;5_PRQ+Ve+-+,5_QSR.Vf.0./5_RTS,Vg,/ ,.5_SUT-V-0 -/5_TVU.V.0 .05_UWV-0VI-0 -/5_VXW.)Vs-/0 var manifest = textures.reduce(function(path) {5_WYX.2V.0 .05_XZY/V/1/05_Y[Z/V./ 5_Z\[/"V.0/ var textureData = customRequire(textures[i]);5_[]\/%V/1 /15_\^]0V/1 var image = textureData.5_]_^0$V02 025_^`_3V23, for (var i = 0; i < textures.length; i++) {/ var textureData = customRequire(textures[i]);5__a`3V23 }5_`ba2V245_acb3V235_bdc5V46> this.images.loadFromManifest(customRequire("./data/images"));5_ced4V;36! this.images = new ImageLoader();5_dfeVr 5_egfVs #var shaders = require("./shaders");5_fhgVv $var textures = require("./shaders");5_gih5V58 575_hji6V685_ikj6V69675_jmk9V895_knlm7V69( var textureData = customRequire(path);% var image = textureData.meta.image;5_mon7#V68) var textureData = customRequire(path);5_npo8V8: 8:5_oqp;V:< });5_prq9 V8; textures.5_qsr:V9;4 textures.toSprites(this.context, t, textureData);5_rts&V&*&(5_sut'V'* ')5_tvu(V'). Object.keys(src).reduce(function(dest, key) {5_uwv(V(*5_vxw*V)+ });5_wyx(V(* (*5_xzy*V)*5_y{z)V)+ )+5_z|{;V%;= ;=5_{}|B V8BD BD5_|~}=V<>+ this.images = new ImageLoader(function() {5_}~=V<>* var.images = new ImageLoader(function() {5_~FVEG( this.images.loadFromManifest(manifest);5_FVEG$ .images.loadFromManifest(manifest);5_V 5_5 V 461 var textures = customRequire("./data/textures");5_6V%57: var manifest = textures.reduce(function(manifest, path) {5_>V5=?- for (var i = 0; i < textures.length; i++) {5_?*V8>@0 var textureData = customRequire(textures[i]);5_9V9; 9;5_6V57= var manifest = textureList.reduce(function(manifest, path) {5_6 V57B var imagemanifest = textureList.reduce(function(manifest, path) {5_GVFH# images.loadFromManifest(manifest);5_GVFH# images.loadFromManifest(Manifest);5_8V8: 8:5_7"V68( var textureData = customRequire(path);5_9V8: console.log(path, image, 5_6;V57B var imageManifest = textureList.reduce(function(manifest, path) {5_9&V"8:& console.log(textureDataPath, image, 5_-V5-/-/5_:3V9;L console.log(textureDataPath, image, path.resolve(textureDataPath, image));5_:OV9;Y console.log(textureDataPath, image, path.resolve(path.dirname(textureDataPath, image));5_;V@:< manifest[image] = image;;<5_;FVC:<L manifest[image] = path.resolve(path.dirname(textureDataPath), image)image;5_:VG9:Z console.log(textureDataPath, image, path.resolve(path.dirname(textureDataPath), image));5_2V224 245_3V223 console.log("get gl context");5_V images: this.images,5_V // images: this.images,5_C,VBDD var t = textures.fromImage(this.context, this.images.get(image));5_C,VBD@ var t = textures.fromImage(this.context, .images.get(image));5_3V35345_4V4:455_4V345_4V35"gl.clearColor(0.0, 0.0, 0.0, 1.0);5_5V46gl.enable(gl.DEPTH_TEST);5_6V57gl.depthFunc(gl.LESS);5_7V68#gl.blendFunc(gl.SRC_ALPHA, gl.ONE);5_8V79gl.enable(gl.BLEND);5_4 8 4 V V39,this.context.clearColor(0.0, 0.0, 0.0, 1.0);#this.context.enable(gl.DEPTH_TEST); this.context.depthFunc(gl.LESS);-this.context.blendFunc(gl.SRC_ALPHA, gl.ONE);this.context.enable(gl.BLEND);5_28 4 V V24235_99 5 V V9;9:5_69 5 V V57$ this.context.enable(gl.DEPTH_TEST);5_79 5 V V68! this.context.depthFunc(gl.LESS);5_89 5 V V79. this.context.blendFunc(gl.SRC_ALPHA, gl.ONE);5_809 5 V V798 this.context.blendFunc(this.context.SRC_ALPHA, gl.ONE);5_99 5 V V 8: this.context.enable(gl.BLEND);5_9 5 V V1 this.scene.stop();5_9 5 V V15_VV1A this.scene = this.makeScene(name, this.scenes[name], sceneArgs); this.scene.start(this.context);5_VV1B this.scene = this.makeScene(name, this.scenes[name], sceneArgs);! this.scene.start(this.context);5_VV1 });5_ VV1(5_VV1, this.scene.stop(function() {C this.scene = this.makeScene(name, this.scenes[name], sceneArgs);" this.scene.start(this.context); }.bind(this));5_VV1- this.scene.stop(function() {5_VV1- .scene.stop(function() {5_VV1- scene.stop(function() {5_VV1- .stop(function() {5_VV1- stop(function() {5_VV1. (function() {5_ VV1/ function() {5_ VV14 }.bind(this));5_VV1E function start() {5_VV1J var start = function start() {5_VV1J! var start = function () {5_VV1S 5_ VV1WC this.scene = this.makeScene(name, this.scenes[name], sceneArgs);" this.scene.start(this.context);5_VV1^A this.scene = this.makeScene(name, this.scenes[name], sceneArgs); this.scene.start(this.context);5_VV1b }5_VV1g5_VV1i# start();5_6VV;D$68+ this.context.depthFunc(this.context.LESS);57. this.context.enable(this.context.DEPTH_TEST);5_6VVD%561 // this.context.enable(this.context.DEPTH_TEST);. // this.context.depthFunc(this.context.LESS);5_6VVLM&57B this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE);5_7VVLT'7968) this.context.enable(this.context.BLEND);5_6VVN68, // this.context.enable(this.context.BLEND);57E // this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE);5_6@VVN(57B this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE);5_-VVL-1-/5_.VV-/function buildImageManifest() {5_.?#DV&V.5./5_/E#JV&V.0M var imageManifest = textureList.reduce(function(manifest, textureDataPath) {5_DE#JV&VgDG DF5_EG#LV&VEH EG5_.#I#NV&V-/*function buildImageManifest(textureList) {5_.+I#NV&V.1 .05_/K#PV&V/15_/L#QV&V/2 /15_068VV'04015_49;VV(345_18:VV-02% var image = textureData.meta.image;5_/>8:VV8.0E Object.keys(textureManifests).reduce(function(imageManifest, path) {5_0)8:VV=/1/ var textureManifest = textureManifests[path];5_28:VVH13G manifest[image] = path.resolve(path.dirname(textureDataPath), image);5_28:VVK13L imagemanifest[image] = path.resolve(path.dirname(textureDataPath), image);5_3 8:VVO24 return manifest;5_38:VVT24 return imagemanifest;5_48:VVU345_479VVW35 });5_/79VV[.0P Object.keys(textureManifests).reduce(function(imageManifest, textureDataPath) {5_55:V V_45@ return textureList.reduce(function(manifest, textureDataPath) {3 var textureData = customRequire(textureDataPath);% var image = textureData.meta.image;G manifest[image] = path.resolve(path.dirname(textureDataPath), image); return manifest; }, {});5_I55V VHKM var imageManifest = textureList.reduce(function(manifest, textureDataPath) {5_I55V VHJ var imageManifest = 5_JJ6OV<VIJ: textureList.reduce(function(manifest, textureDataPath) {3 var textureData = customRequire(textureDataPath);% var image = textureData.meta.image;G manifest[image] = path.resolve(path.dirname(textureDataPath), image); return manifest; }, {});5_5J6JV<V58575_6FJVV6<675_8KOVV79F var textureManifests = textureList.reduce(function(manifests, path) {5_66 <V V56.function loadTextureManifests(customRequire) {4 var textureList = customRequire("./data/textures");6 return textureList.reduce(function(manifests, path) {( manifests[path] = customRequire(path); return manifests; }, {});}5_.6 6V V-5./5_L= =V VKMF var textureManifests = textureList.reduce(function(manifests, path) {5_K= =V VJK4 var textureList = customRequire("./data/textures");5_LLNVVKL( manifests[path] = customRequire(path); return manifests; }, {});5_<LLVV<?<>5_=RXVV=E=>5_>Y_VVCE }BD merge(this.sprites, sprites);ACB var sprites = textures.toSprites(this.context, t, textureData);@B? var t = textures.fromImage(this.context, images.get(image));?A& var image = textureData.meta.image;>@3 var textureData = customRequire(textureList[i]);=?0 for (var i = 0; i < textureList.length; i++) {5_=Y_VV=A =?5_>\bVV =?J Object.keys(textureManifests).reduce(function(sprites, textureDataPath) {5_>\bVV >A>?5_AFHVV AEAB5_AIKVV @A 5_=.HJVV <>1function loadTextures(textureManifests, images) {5_AHJVV @B> var t = textures.fromImage(this.context, images.get(image));5_B#HJVV ACA var sprites = textures.toSprites(this.context, t, textureData);5_BHJVV AC7 var sprites = textures.toSprites(gl, t, textureData);5_CHJVV BD merge(this.sprites, sprites);5_CHJVV BD merge(this.sprites, ss);5_CHJVV BD merge(this.sprites, s);5_CHJVV BD merge(x.sprites, s);5_CHJVV BD merge(.sprites, s);5_DHJVV CE });5_ CHJVV CE CE5_  FFLVV EF/ for (var i = 0; i < textureList.length; i++) {2 var textureData = customRequire(textureList[i]);% var image = textureData.meta.image;> var t = textures.fromImage(this.context, images.get(image));A var sprites = textures.toSprites(this.context, t, textureData); merge(this.sprites, sprites); }5_   XXXVV!WY this.sprites = {};5_   ZZ/`VGV!"YZ0 for (var i = 0; i < textureList.length; i++) {3 var textureData = customRequire(textureList[i]);& var image = textureData.meta.image;? var t = textures.fromImage(this.context, images.get(image));B var sprites = textures.toSprites(this.context, t, textureData); merge(this.sprites, sprites); }5_   XZ/ZVGV!#WXE this.sprites = loadTextures(textureManifests, images, this.context);5_  XY/YVGV!$XZXY5_ YZ/ZVGV!%XZE this.sprites = loadTextures(textureManifests, images, this.context);5_WZ/ZVGV!()VW5_B+Y/YVGV!B*AC1 var s = textures.toSprites(gl, t, textureData);5_,YYVGV!{,/,.5_-[[VGV!-0 -/5_.]]VGV!.0 .05_C^^VGV!BDQ return Object.keys(textureManifests).reduce(function(sprites, textureDataPath) {5_C^^VGV!BDS return Object.values(textureManifests).reduce(function(sprites, textureDataPath) {5_C^^VGV!BDR return Objectvalues(textureManifests).reduce(function(sprites, textureDataPath) {5_C^^VGV!BDR return ObjectValues(textureManifests).reduce(function(sprites, textureDataPath) {5_CG^^VGV!BDR return objectValues(textureManifests).reduce(function(sprites, textureDataPath) {5_D^^VGV!+CD: var textureManifest = textureManifests[textureDataPath];5_  VV"m  5_  V V" function clone(obj) { if (obj === undefined) { return undefined; }( return JSON.parse(JSON.stringify(obj));}5_!   V V"  5_" !  V V"# var newFrame = clone(firstFrame);5_!#"##-VV""# function merge(dest, src) {5 return Object.keys(src).reduce(function(dest, key) { dest[key] = src[key]; return dest; }, dest);}function objectValues(obj) {, return Object.keys(obj).map(function(key) { return obj[key]; });}5_"$####VV""#5_#%$7##VV"68 merge(sprites, s);5_$&%3##VV"24R return objectValues(textureManifests).reduce(function(sprites, textureManifest) {5_%'&3##VV",24S return object.Values(textureManifests).reduce(function(sprites, textureManifest) {5_&('w##VV"vx1 scene.entities.load(clone(this.entities[name]));5_')(###VV".7 this.scene.entities.set(id, key, clone(prefab[key]));5_(*)J##VV#/JL JL5_)+*J##VV#Z0JL JL5_*,+N##VV#oNP NP5_+-,I##VV#IKIJ5_,6-J ##VV#3IK console.log(imageManifest);5_-7.6##VV&4 5_6872 ##VV(/135function loadTextures(textureManifests, images, gl) {5_798O##VV(6NPF this.sprites = loadTextures(textureManifests, images, this.context);5_8:9OE##VV(9NPG this.sprites = createSprites(textureManifests, images, this.context);5_9;:P##VV(>OP console.log(this.sprites);5_:<;O##VV(ANPU this.sprites = createSprites(textureManifests, images, this.context, this.sprites);5_;=<O##VV(ANPQ .sprites = createSprites(textureManifests, images, this.context, this.sprites);5_<>=O##VV(ANPP sprites = createSprites(textureManifests, images, this.context, this.sprites);5_=?>O##VV(BNPH = createSprites(textureManifests, images, this.context, this.sprites);5_>A?3##VV(E24S return object.values(textureManifests).reduce(function(sprites, textureManifest) {5_?B@A9##VV(K8: }, {});5_ACB23##VV(T5136function createSprites(textureManifests, images, gl) {5_BDCJ##VV(\IJ console.log(textureManifests);5_CEDK##VV(]JK console.log(imageManifest);5_DFE##VV(^7 console.log("makeSceneData");5_EGF:CEVV-:<:;5_FHG; DFVV-&:<.function loadTextureManifests(customRequire) {5_GIH;DFVV-+;= ;=5_HJI;EGVV-1:<-function loadShaderManifests(customRequire) {5_IKJ;EGVV-7;=;<5_JLK<FHVV-9;=0 this.shaders = customRequire("./data/shaders");5_KML<FHVV-=;=/ var.shaders = customRequire("./data/shaders");5_LNM<FHVV-a<? <>5_MON>HJVV->@ >@5_NPO=IKVV-=? =?5_OQP\JLVV-8[]0 this.shaders = customRequire("./data/shaders");5_PRQq4JLVV-prO return shaders.compile(this.context, shader.type, this.require(shader.path));5_QSRq4JLVV-prK return shaders.compile(this.context, shader.type, .require(shader.path));5_RTSq4JLVV-prJ return shaders.compile(this.context, shader.type, require(shader.path));5_SUTq4JLVV-prC return shaders.compile(this.context, shader.type, (shader.path));5_TVUq;JLVV-prB return shaders.compile(this.context, shader.type, shader.path));5_UWVq?JLVV-9prB return shaders.compile(this.context, shader.type, shader.text));5_VXWxJLVV3x{ xz5_WYXyJLVV3xz, data.renderer = new Renderer(this.context);5_XZYyJLVV3xz+ var.renderer = new Renderer(this.context);5_Y[ZzJLVV3yz data.5_Z\[yJLVV3y{ y{5_[]\z JLVV3y{ renderer.5_\^]zJLVV3z|z{5_]_^PJLVV4OQ< var textureManifests = loadTextureManifests(customRequire);5_^`_PJLVV4OQ> this. textureManifests = loadTextureManifests(customRequire);5__a`zJLVV4y{" renderer.loadSprites(this.images,5_`baz8JLVV4y{9 renderer.loadSprites(this.textureManifests, this.images,5_acbz9JLVV4y{9 renderer.loadSprites(this.textureManifests, this.images)5_bdcz9JLVV4z| z|5_ced{ JLVV4&z| renderer.5_dfe{)JLVV4Gz|) renderer.buildShaderProgram(this.shaders5_egf{0JLVV4f{} {}5_fhg~JLVV4}( data.shaders = this.buildShaders(name);5_gihmtmVV4su};rth return shaders.link(this.context, compiled, this.shaders.vertexAttribArrays, this.shaders.uniformVars);qs }.bind(this));prA return shaders.compile(this.context, shader.type, shader.text);oq }).map(function(shader) {np- return shader.scenes.indexOf(scene) !== -1;mo> var compiled = this.shaders.shaders.filter(function(shader) {ln/Game.prototype.buildShaders = function(scene) {5_hjiIILVV4KM) this.context.enable(this.context.BLEND);JLR this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE_MINUS_SRC_ALPHA);IK- this.context.clearColor(0.0, 0.0, 0.0, 1.0);HJ+ this.context = canvas.getContext("webgl");5_ikjRILVV4QS this.sprites = {};5_jlkTILVV5 :SUF createSprites(textureManifests, images, this.context, this.sprites);5_kmlUILVV5UWUV5_lnmTILVV5SUI // createSprites(textureManifests, images, this.context, this.sprites);5_monSSUVV5TV }.bind(this));SUF createSprites(textureManifests, images, this.context, this.sprites);RT* var images = new ImageLoader(function() {5_npoVSUVV5;UW* var images = new ImageLoader(function() {5_orpQ(SUVV5#<PR: var imageManifest = buildImageManifest(textureManifests);5_psqrSUVV575_rtsDTVVV5JCDvar path = require("path");5_sutSUVV5M=5_tvuTVVV5V #var shaders = require("./shaders");5_uwv44<VV5_>;=}:< }, spriteList);9; return sprites;8: object.merge(sprites, s);795 var s = textures.toSprites(gl, t, textureManifest);684 var t = textures.fromImage(gl, images.get(image));57) var image = textureManifest.meta.image;46L object.values(textureManifests).reduce(function(sprites, textureManifest) {35Bfunction createSprites(textureManifests, images, gl, spriteList) {5_vxw 4<VV5e@ %var textures = require("./textures");5_wyxJ4<VV9:AIK. // this.context = canvas.getContext("webgl");5_xzyJ4<VV9fIK+ this.context = canvas.getContext("webgl");5_y{zW4<VV9VX var images = new ImageLoader();5_z}{W4<VV9VX" this. images = new ImageLoader();5_{~|}X4<VV9CWY( images.loadFromManifest(imageManifest);5_}~J4<VV:DIK. // this.context = canvas.getContext("webgl");5_~v4<VV<vy// vx5_w4<VV<wywx5_x4<VV<x}xy5_x4<VV<wx5_xx{VV<z|w // return (game.images.loadedImages + game.sounds.loadedSounds) / (game.images.totalImages + game.sounds.totalSounds);y{ // }xz // return 1;wyB // if (game.images.totalImages + game.sounds.totalSounds === 0) {5_xx{VV=wy? if (game.images.totalImages + game.sounds.totalSounds === 0) {5_xx{VV=wy? if (this.images.totalImages + game.sounds.totalSounds === 0) {5_{ x{VV=z|t return (game.images.loadedImages + game.sounds.loadedSounds) / (game.images.totalImages + game.sounds.totalSounds);5_{$x{VV=z|t return (this.images.loadedImages + game.sounds.loadedSounds) / (game.images.totalImages + game.sounds.totalSounds);5_{Ax{VV= z|t return (this.images.loadedImages + this.sounds.loadedSounds) / (game.images.totalImages + game.sounds.totalSounds);5_{[x{VV="Ez|t return (this.images.loadedImages + this.sounds.loadedSounds) / (this.images.totalImages + game.sounds.totalSounds);5_nx{VV=6npno5_oy|VV=9np1Game.prototype.makeScenes = function(sceneList) {5_oy|VV==oq oq5_pz}VV=Boq }5_pz}VV=Coq }5_pz}VV=Doq}5_o+z}VV=Hnp7Game.prototype.makeLoadingScene = function(sceneList) {5_oz}VV=oop5_rrVV= });5_rrVV= if (percentLoaded() === 1) {5_ rrVV= 5_rrVV= scene.stop(function() { nextScene.start(context);5_rrVV= });5_nrrVV=npno5_ossVV=oq oq5_oimVV=or oq5_pimVV>$prpq5_oimVV>:oqop5_pimVV>;oq1 Object.keys(sceneList).forEach(function(scene) {5_p$imVV>Coq> var scenes = Object.keys(sceneList).forEach(function(scene) {5_qimVV>Fpr/ for (var i = 0; i < this.scenes.length; i++) {5_qimVV>Fpr+ for (var i = 0; i < .scenes.length; i++) {5_rimVV>Jqs if (sceneList[scene].first) {5_r imVV>Nru rt5_oimVV>\np.Game.prototype.makeLoadingScene = function() {5_imVV>j this.switchScene("");5_imVV>z 5_imVV> scene.start5_imVV> 5_wimVV>Fvx.Game.prototype.makeLoadingScene = function() {5_r imVV>qs if (scenes[scene].first) {5_simVV>Grt return scene;5_pimVV>Hoq% var scenes = Object.keys(sceneList);5_y%imVV>Ixz1 scene.renderer.add(function(entities, context) {5_yimVV>Jxz( scene.renderer.add(function(entities) {5_fimVV>fh fh5_fjnVV>ef this.makeScenes(this.scenes);5_hhnVV>Kgh1Game.prototype.makeScenes = function(sceneList) {1 Object.keys(sceneList).forEach(function(scene) { if (sceneList[scene].first) {< this.scene = this.makeScene(scene, sceneList[scene], {}); } }.bind(this));};5_qhhVV@~pr var scene = new Scene();5_qhhVV@pr this scene = new Scene();5_qhhVV@pr this. scene = new Scene();5_rhhVV@qs scene.renderer.add(function() {5_hhVV@L scene.start();5_jhhVVAgMjl jl5_lhhVVAlnlm5_mhhVVAln console.log(scenes[i]);5_mhhVVANln" console.log("first", scenes[i]);5_lhhVVAkm if (scenes[i].first) {5_j hhVVAjl jl5_lhhVVAkm console.log(scenes[i]);5_nhhVVAmn# console.log("first", scenes[i]);5_mhhVVAln if (this.scenes[i].first) {5_n hhVVAmo return scenes[i];5_lhhVVBOkl console.log(name);5_44<VVC34 E// function createSprites(textureManifests, images, gl, spriteList) {O// object.values(textureManifests).reduce(function(sprites, textureManifest) {,// var image = textureManifest.meta.image;7// var t = textures.fromImage(gl, images.get(image));8// var s = textures.toSprites(gl, t, textureManifest);// object.merge(sprites, s);// return sprites;// }, spriteList);// }5_BBDVVCAB0 // this.context.clearColor(0.0, 0.0, 0.0, 1.0);U // this.context.blendFunc(this.context.SRC_ALPHA, this.context.ONE_MINUS_SRC_ALPHA);, // this.context.enable(this.context.BLEND);5_@BBVVC?@5_FFIVVCEF // this.sprites = {};- // var images = new ImageLoader(function() {I // createSprites(textureManifests, images, this.context, this.sprites); // }.bind(this));5_zzVVCyz2// Game.prototype.buildShaders = function(scene) {A// var compiled = this.shaders.shaders.filter(function(shader) {0// return shader.scenes.indexOf(scene) !== -1;// }).map(function(shader) {D// return shaders.compile(this.context, shader.type, shader.text);// }.bind(this));k// return shaders.link(this.context, compiled, this.shaders.vertexAttribArrays, this.shaders.uniformVars);// };5_zzVVC+ // data.shaders = this.buildShaders(name);5_zzVVC&// var shaders = require("./shaders");5_ yyVVC (// var textures = require("./textures");5_ xxVVC !var object = require("./object");5_wwVVCR5_xxVVo 5_xxVVo data.renderer = renderer;5_xxVVo5_VVo+ var renderer = new Renderer(this.context);: renderer.loadSprites(this.textureManifests, this.images);1 renderer.buildShaderProgram(this.shaders, name); this.renderer = renderer;5_VVo5_VVoS5_VVp 5_$VVp35_VVp<' this.renderer.setSize(width, height);5_&VVpAT. this.renderer.setSize(desiredWidth, height);5_VVpU 5_VVq-' this.renderer.setSize(width, height);5_VVq.5_VVq3' this.renderer.setSize(width, height);5_VVq4 5_VVq>& this.renderer.setSize(width, height);5_VVq@ 5_VVqF' this.renderer.setSize(width, height);5_+VVqI3 this.renderer.setSize(this.canvas.width, height);5_VVqLX5 this.renderer.setSize(desiredWidth, desiredHeight);5_4 V46455_4V35+ shaders.shaders.forEach(function(shader) {5_4 V357 Object.keysOshaders.shaders.forEach(function(shader) {5_4V357 Object.keys(shaders.shaders.forEach(function(shader) {5_4V368 Object.keys(shaders).shaders.forEach(function(shader) {5_5V464 shaders[name].shaders.forEach(function(shader) {565_5V465 shaders[name].shaders.forEach(function(shader) {565_5V466 shaders[name].shaders.forEach(function(shader) {5_5V465 shaders[name].shaders.forEach(function(shader) {5_5V464 shaders[name].shaders.forEach(function(shader) {5_5V463 shaders[name].shaders.forEach(function(shader) {5_6V57+ shaders.shaders.forEach(function(shader) {675_6V57, shaders.shaders.forEach(function(shader) {675_7V68+ shader.text = customRequire(shader.path);785_8V79 });895_8V79 });895_7V68, shader.text = customRequire(shader.path);785_6V56- shaders.shaders.forEach(function(shader) {5_6V57- shader.text = customRequire(shader.path);5_7V79785_8V79 });5_7V68 });5_8VY79 });5_VZ "use strict";,var ImageLoader = require("./image-loader");var Input = require("./input");!var object = require("./object");var path = require("path");%var Renderer = require("./renderer");var Scene = require("./scene");,var SoundLoader = require("./sound-loader");/function splitFilmStripAnimations(animations) {0 Object.keys(animations).forEach(function(key) {& var firstFrame = animations[key][0];# if (firstFrame.filmstripFrames) {, splitFilmStripAnimation(animations, key); } });}3function splitFilmStripAnimation(animations, key) {% var firstFrame = animations[key][0];Q if (firstFrame.properties.image.sourceWidth % firstFrame.filmstripFrames != 0) { console.warn("The \"" + key + "\" animation is " + firstFrame.properties.image.sourceWidth + " pixels wide and that is is not evenly divisible by " + firstFrame.filmstripFrames + " frames."); }7 for (var i = 0; i < firstFrame.filmstripFrames; i++) {X var frameWidth = firstFrame.properties.image.sourceWidth / firstFrame.filmstripFrames;* var newFrame = object.clone(firstFrame);5 newFrame.properties.image.sourceX = frameWidth * i;5 newFrame.properties.image.sourceWidth = frameWidth;! animations[key].push(newFrame); } animations[key].splice(0,1);}.function loadTextureManifests(customRequire) {4 var textureList = customRequire("./data/textures");6 return textureList.reduce(function(manifests, path) {( manifests[path] = customRequire(path); return manifests; }, {});}/function buildImageManifest(textureManifests) {W return Object.keys(textureManifests).reduce(function(imageManifest, textureDataPath) {: var textureManifest = textureManifests[textureDataPath];) var image = textureManifest.meta.image;L imageManifest[image] = path.resolve(path.dirname(textureDataPath), image); return imageManifest; }, {});},function loadShaderManifest(customRequire) {/ var shaders = customRequire("./data/shaders");. Object.keys(shaders).forEach(function(name) {2 shaders[name].shaders.forEach(function(shader) {, shader.text = customRequire(shader.path); }); }); return shaders;}&function Game(canvas, customRequire) {6 this.animations = customRequire("./data/animations");+ splitFilmStripAnimations(this.animations); this.canvas = canvas;+ this.context = canvas.getContext("webgl");2 this.entities = customRequire("./data/entities");= this.textureManifests = loadTextureManifests(customRequire);? var imageManifest = buildImageManifest(this.textureManifests);! this.images = new ImageLoader();- this.images.loadFromManifest(imageManifest);@ this.input = new Input(customRequire("./data/inputs"), canvas);0 this.prefabs = customRequire("./data/prefabs"); this.require = customRequire;. this.scenes = customRequire("./data/scenes");2 this.shaders = loadShaderManifest(customRequire);! this.sounds = new SoundLoader();> this.sounds.loadFromManifest(customRequire("./data/sounds"));0 this.systems = customRequire("./data/systems"); this.scaleCanvasToCssSize();C window.addEventListener("resize", this.onCanvasResize.bind(this)); this.startLoadingScene();}(Game.prototype.firstScene = function() {' var scenes = Object.keys(this.scenes);* for (var i = 0; i < scenes.length; i++) { var name = scenes[i]; if (this.scenes[name].first) { return name; } }};/Game.prototype.startLoadingScene = function() { this.scene = new Scene();% this.scene.renderer.add(function() {# // context.fillStyle = "#000000";9 // context.fillRect(0, 0, canvas.width, canvas.height);5 // var quarterWidth = Math.floor(canvas.width / 4);2 // var halfWidth = Math.floor(canvas.width / 2);4 // var halfHeight = Math.floor(canvas.height / 2);# // context.fillStyle = "#ffffff";D // context.fillRect(quarterWidth, halfHeight - 15, halfWidth, 30);# // context.fillStyle = "#000000";L // context.fillRect(quarterWidth + 3, halfHeight - 12, halfWidth - 6, 24);# // context.fillStyle = "#ffffff";6 // var barWidth = (halfWidth - 6) * percentLoaded();G // context.fillRect(quarterWidth + 3, halfHeight - 12, barWidth, 24);# if (this.percentLoaded() === 1) {' this.switchScene(this.firstScene()); } }.bind(this)); this.scene.start();};+Game.prototype.percentLoaded = function() {? if (this.images.totalImages + this.sounds.totalSounds === 0) { return 1; }t return (this.images.loadedImages + this.sounds.loadedSounds) / (this.images.totalImages + this.sounds.totalSounds);};AGame.prototype.makeScene = function(name, sceneData, sceneArgs) { var scene = new Scene();+ var renderer = new Renderer(this.context);: renderer.loadSprites(this.textureManifests, this.images);1 renderer.buildShaderProgram(this.shaders, name);9 renderer.setSize(this.canvas.width, this.canvas.height); this.renderer = renderer;: var data = this.makeSceneData(scene.entities, sceneArgs); data.renderer = renderer;" scene.simulation.add(function() { data.input.processUpdates(); });L this.installSystems(name, this.systems.simulation, scene.simulation, data);H this.installSystems(name, this.systems.renderer, scene.renderer, data);8 scene.entities.load(object.clone(this.entities[name]));- if (typeof sceneData.onEnter === "string") {4 var enterScript = this.require(sceneData.onEnter);* if (typeof enterScript === "function") {/ enterScript = enterScript.bind(scene, data); } scene.onEnter = enterScript; }, if (typeof sceneData.onExit === "string") {2 var exitScript = this.require(sceneData.onExit);) if (typeof exitScript === "function") {- exitScript = exitScript.bind(scene, data); } scene.onExit = exitScript; } return scene;};>Game.prototype.makeSceneData = function(entities, sceneArgs) { return { animations: this.animations, arguments: sceneArgs || {}, canvas: this.canvas, context: this.context, entities: entities, input: this.input, require: this.require,= scaleCanvasToCssSize: this.scaleCanvasToCssSize.bind(this),G scaleCanvasToFitRectangle: this.scaleCanvasToFitRectangle.bind(this), sounds: this.sounds, sprites: this.sprites,+ switchScene: this.switchScene.bind(this),6 instantiatePrefab: this.instantiatePrefab.bind(this) };};EGame.prototype.installSystems = function(scene, systems, ecs, data) {# systems.forEach(function(system) {, if (system.scenes.indexOf(scene) === -1) { return; }) var script = this.require(system.name); if (script === undefined) {7 console.error("failed to load script", system.name); } script(ecs, data); }.bind(this));};8Game.prototype.switchScene = function(name, sceneArgs) { var start = function() {B this.scene = this.makeScene(name, this.scenes[name], sceneArgs);! this.scene.start(this.context); }.bind(this); if (this.scene !== undefined) { this.scene.stop(function() { start(); }.bind(this)); } else { start(); }};,Game.prototype.onCanvasResize = function() { this.resizer(); if (this.renderer) {? this.renderer.setSize(this.canvas.width, this.canvas.height); }};2Game.prototype.scaleCanvasToCssSize = function() { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);* var width = parseInt(canvasStyle.width);, var height = parseInt(canvasStyle.height); this.canvas.width = width; this.canvas.height = height; }.bind(this); this.resizer();};DGame.prototype.scaleCanvasToFitRectangle = function(width, height) { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);- var cssWidth = parseInt(canvasStyle.width);/ var cssHeight = parseInt(canvasStyle.height);, var cssAspectRatio = cssWidth / cssHeight; var desiredWidth = width; var desiredHeight = height;* var desiredAspectRatio = width / height;, if (desiredAspectRatio > cssAspectRatio) {6 desiredHeight = Math.floor(width / cssAspectRatio);3 } else if (desiredAspectRatio < cssAspectRatio) {6 desiredWidth = Math.floor(height * cssAspectRatio); }# this.canvas.width = desiredWidth;% this.canvas.height = desiredHeight; }.bind(this); this.resizer();};3Game.prototype.instantiatePrefab = function(name) {' var id = this.scene.entities.create();! var prefab = this.prefabs[name];, Object.keys(prefab).forEach(function(key) { if (key === "id") { return; }> this.scene.entities.set(id, key, object.clone(prefab[key])); }.bind(this)); return id;};module.exports = Game;5_V)F[ 5_V*Y\ 5_V*] console.log("switch scene");5_V,\5_V,^5_V,a 5_V,x 5_ V,y 5_  V,y 5_   V,y 5_   V, }5_   V, }5_  V, }5_ V,5_V, 5_V, 5_V, return;5_V, return;5_V,return;5_V,` return;5_V-fa 5_&V.b 5_V0 "use strict";,var ImageLoader = require("./image-loader");var Input = require("./input");!var object = require("./object");var path = require("path");%var Renderer = require("./renderer");var Scene = require("./scene");,var SoundLoader = require("./sound-loader");/function splitFilmStripAnimations(animations) {0 Object.keys(animations).forEach(function(key) {& var firstFrame = animations[key][0];# if (firstFrame.filmstripFrames) {, splitFilmStripAnimation(animations, key); } });}3function splitFilmStripAnimation(animations, key) {% var firstFrame = animations[key][0];Q if (firstFrame.properties.image.sourceWidth % firstFrame.filmstripFrames != 0) { console.warn("The \"" + key + "\" animation is " + firstFrame.properties.image.sourceWidth + " pixels wide and that is is not evenly divisible by " + firstFrame.filmstripFrames + " frames."); }7 for (var i = 0; i < firstFrame.filmstripFrames; i++) {X var frameWidth = firstFrame.properties.image.sourceWidth / firstFrame.filmstripFrames;* var newFrame = object.clone(firstFrame);5 newFrame.properties.image.sourceX = frameWidth * i;5 newFrame.properties.image.sourceWidth = frameWidth;! animations[key].push(newFrame); } animations[key].splice(0,1);}.function loadTextureManifests(customRequire) {4 var textureList = customRequire("./data/textures");6 return textureList.reduce(function(manifests, path) {( manifests[path] = customRequire(path); return manifests; }, {});}/function buildImageManifest(textureManifests) {W return Object.keys(textureManifests).reduce(function(imageManifest, textureDataPath) {: var textureManifest = textureManifests[textureDataPath];) var image = textureManifest.meta.image;L imageManifest[image] = path.resolve(path.dirname(textureDataPath), image); return imageManifest; }, {});},function loadShaderManifest(customRequire) {/ var shaders = customRequire("./data/shaders");. Object.keys(shaders).forEach(function(name) {2 shaders[name].shaders.forEach(function(shader) {, shader.text = customRequire(shader.path); }); }); return shaders;}&function Game(canvas, customRequire) {6 this.animations = customRequire("./data/animations");+ splitFilmStripAnimations(this.animations); this.canvas = canvas;+ this.context = canvas.getContext("webgl");2 this.entities = customRequire("./data/entities");= this.textureManifests = loadTextureManifests(customRequire);? var imageManifest = buildImageManifest(this.textureManifests);! this.images = new ImageLoader();- this.images.loadFromManifest(imageManifest);@ this.input = new Input(customRequire("./data/inputs"), canvas);0 this.prefabs = customRequire("./data/prefabs"); this.require = customRequire;. this.scenes = customRequire("./data/scenes");2 this.shaders = loadShaderManifest(customRequire);! this.sounds = new SoundLoader();> this.sounds.loadFromManifest(customRequire("./data/sounds"));0 this.systems = customRequire("./data/systems"); this.scaleCanvasToCssSize();C window.addEventListener("resize", this.onCanvasResize.bind(this)); this.startLoadingScene();}(Game.prototype.firstScene = function() {' var scenes = Object.keys(this.scenes);* for (var i = 0; i < scenes.length; i++) { var name = scenes[i]; if (this.scenes[name].first) { return name; } }};/Game.prototype.startLoadingScene = function() { this.scene = new Scene();% this.scene.renderer.add(function() {# // context.fillStyle = "#000000";9 // context.fillRect(0, 0, canvas.width, canvas.height);5 // var quarterWidth = Math.floor(canvas.width / 4);2 // var halfWidth = Math.floor(canvas.width / 2);4 // var halfHeight = Math.floor(canvas.height / 2);# // context.fillStyle = "#ffffff";D // context.fillRect(quarterWidth, halfHeight - 15, halfWidth, 30);# // context.fillStyle = "#000000";L // context.fillRect(quarterWidth + 3, halfHeight - 12, halfWidth - 6, 24);# // context.fillStyle = "#ffffff";6 // var barWidth = (halfWidth - 6) * percentLoaded();G // context.fillRect(quarterWidth + 3, halfHeight - 12, barWidth, 24);# if (this.percentLoaded() === 1) {' this.switchScene(this.firstScene()); } }.bind(this)); this.scene.start();};+Game.prototype.percentLoaded = function() {? if (this.images.totalImages + this.sounds.totalSounds === 0) { return 1; }t return (this.images.loadedImages + this.sounds.loadedSounds) / (this.images.totalImages + this.sounds.totalSounds);};AGame.prototype.makeScene = function(name, sceneData, sceneArgs) { var scene = new Scene();+ var renderer = new Renderer(this.context);: renderer.loadSprites(this.textureManifests, this.images);1 renderer.buildShaderProgram(this.shaders, name);9 renderer.setSize(this.canvas.width, this.canvas.height); this.renderer = renderer;: var data = this.makeSceneData(scene.entities, sceneArgs); data.renderer = renderer;" scene.simulation.add(function() { data.input.processUpdates(); });L this.installSystems(name, this.systems.simulation, scene.simulation, data);H this.installSystems(name, this.systems.renderer, scene.renderer, data);8 scene.entities.load(object.clone(this.entities[name]));- if (typeof sceneData.onEnter === "string") {4 var enterScript = this.require(sceneData.onEnter);* if (typeof enterScript === "function") {/ enterScript = enterScript.bind(scene, data); } scene.onEnter = enterScript; }, if (typeof sceneData.onExit === "string") {2 var exitScript = this.require(sceneData.onExit);) if (typeof exitScript === "function") {- exitScript = exitScript.bind(scene, data); } scene.onExit = exitScript; } return scene;};>Game.prototype.makeSceneData = function(entities, sceneArgs) { return { animations: this.animations, arguments: sceneArgs || {}, canvas: this.canvas, context: this.context, entities: entities, input: this.input, require: this.require,= scaleCanvasToCssSize: this.scaleCanvasToCssSize.bind(this),G scaleCanvasToFitRectangle: this.scaleCanvasToFitRectangle.bind(this), sounds: this.sounds, sprites: this.sprites,+ switchScene: this.switchScene.bind(this),6 instantiatePrefab: this.instantiatePrefab.bind(this) };};EGame.prototype.installSystems = function(scene, systems, ecs, data) {# systems.forEach(function(system) {, if (system.scenes.indexOf(scene) === -1) { return; }) var script = this.require(system.name); if (script === undefined) {7 console.error("failed to load script", system.name); } script(ecs, data); }.bind(this));};8Game.prototype.switchScene = function(name, sceneArgs) {$ console.log("switch scene", name);' if (this.scenes[name] === undefined) {( console.error("No such scene:", name); return; } var start = function() {B this.scene = this.makeScene(name, this.scenes[name], sceneArgs);" console.log("starting", name);! this.scene.start(this.context); }.bind(this); if (this.scene !== undefined) { this.scene.stop(function() {) console.log("stop done, starting"); start(); }.bind(this)); } else { start(); }};,Game.prototype.onCanvasResize = function() { this.resizer(); if (this.renderer) {? this.renderer.setSize(this.canvas.width, this.canvas.height); }};2Game.prototype.scaleCanvasToCssSize = function() { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);* var width = parseInt(canvasStyle.width);, var height = parseInt(canvasStyle.height); this.canvas.width = width; this.canvas.height = height; }.bind(this); this.resizer();};DGame.prototype.scaleCanvasToFitRectangle = function(width, height) { this.resizer = function() {9 var canvasStyle = window.getComputedStyle(this.canvas);- var cssWidth = parseInt(canvasStyle.width);/ var cssHeight = parseInt(canvasStyle.height);, var cssAspectRatio = cssWidth / cssHeight; var desiredWidth = width; var desiredHeight = height;* var desiredAspectRatio = width / height;, if (desiredAspectRatio > cssAspectRatio) {6 desiredHeight = Math.floor(width / cssAspectRatio);3 } else if (desiredAspectRatio < cssAspectRatio) {6 desiredWidth = Math.floor(height * cssAspectRatio); }- console.log(desiredWidth, desiredHeight);# this.canvas.width = desiredWidth;% this.canvas.height = desiredHeight; }.bind(this); this.resizer();};3Game.prototype.instantiatePrefab = function(name) {' var id = this.scene.entities.create();! var prefab = this.prefabs[name];, Object.keys(prefab).forEach(function(key) { if (key === "id") { return; }> this.scene.entities.set(id, key, object.clone(prefab[key])); }.bind(this)); return id;};module.exports = Game;5_V12c$ console.log("switch scene", name);5_V,_5_ V, 5_V, 5_V,W5_4 VR35- Object.keysshaders).forEach(function(name) {5_8V79 );5_9V8: retun shaders;5_4V455_3 V34 35 u5_VVqU@ 4this.renderer.setSize(this.canvas.width, this.canvas.height);5_lhhVVAqlm ln console lof5_EhhVVA{DF'ufunction Game(canvas, customRequire) {5_y'imVV>xz6 scene.renderer.add(function(entities, this.context) {5_imVV>  return scene5_{}|X4<VV9WY' mages.loadFromManifest(imageManifest);5_prqSUVV56+vfunction() {ar Input = require("./input");5_?A@3##VV(F24F .values(textureManifests).reduce(function(sprites, textureManifest) {5_-/6.22##VV$13Afunction loadTextures(textureManifests, images, gl, spriteList) {5_.0/9##VV$$8: }, spriteList);5_/103##VV$724L object.values(textureManifests).reduce(function(sprites, textureManifest) {5_021O##VV$>NPB .sprites = loadTextures(textureManifests, images, this.context);5_132O##VV$>NPA sprites = loadTextures(textureManifests, images, this.context);5_243O##VV$>NP9 = loadTextures(textureManifests, images, this.context);5_354O##VV$?NP7 loadTextures(textureManifests, images, this.context);5_45O5##VV$B2NPE loadTextures(textureManifests, images, this.context, this.sprites);5_!   V V"5_1^^VGV!1213object;5_B+Y/YVGV!>AC- var s = textures.toSprites(gl, t, texture);5_BY/YVGV!?AC0 vnifar s = textures.toSprites(gl, t, texture);5_3 8:VVM24 return ;5_2.8:VV313< manifest[image] = path.resolve(path.dirname(path), image);5_.#E#JV&V -//function buildImageManifest(textureManifests) {5_/E#JV&V.0E return textureManifests.reduce(function(manifest, textureDataPath) {5_/>E#JV&V.0A return textureManifests.reduce(function(manifest, textureData) {5_0D#IV&V/15_BVVAC "use strict";function Renderer() {}5_ VVG]E game.context.viewport(0, 0, game.canvas.width, game.canvas.height);T game.context.clear(game.context.COLOR_BUFFER_BIT | game.context.DEPTH_BUFFER_BIT); var pMatrix = mat4.create();J mat4.ortho(pMatrix, 0, game.canvas.width, game.canvas.height, 0, -1, 1);5_4V4535http://localhost:4000/5_5 V460 var texturs = customRequire("./data/textures");5_kml8V79& var image = textureData.meta.image;5_576hV_hi hj shaders: 5_2430V01 027 this.shaders = customRequire("./data/shaders");shaders5_%'&%V_$&"wwfunction Game(canvas, require) {5