VimUnDo> d܃d毷1:(RIIIIVU_#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_HI+VU*+ console.log(this.context);5_576hV_hi hj shaders: 5_2430V01 027 this.shaders = customRequire("./data/shaders");shaders5_%'&%V_$&"wwfunction Game(canvas, require) {5