VimŸUnDoå’tÌÄ4®í+ÞTð3S_De5ˆw‚JþtqÂ]® function Game(canvas, require) {%0000V„_=_Ð#ÿÿÿÿV„TXõž "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_Ð%ÿÿÿÿV„Ubõ$&« this.animations = animations;5_Ð(ÿÿÿÿV„U{õ')« this.entities = entities;5_ÐÿÿÿÿV„UÏõ¬õ«5_ÐÿÿÿÿV„Võ¬õ¬5_ÐÿÿÿÿV„V õ­,var ImageLoader = require("./image-loader");5_ÐÿÿÿÿV„Võ­,var SoundLoader = require("./image-loader");5_Ð *!ÿÿÿÿV„Võ)+­. this.entities = require("./data/animations");5_Ð +ÿÿÿÿV„V!õ*,­ this.images = images;5_Ð +ÿÿÿÿV„V2õ+-® õ+-­5_Ð 0ÿÿÿÿV„Vcõ/1® this.sounds = sounds;5_Ð /ÿÿÿÿV„V“õ.0® this.scenes = scenes;5_Ð  -ÿÿÿÿV„V¬õ,.®' this.input = new Input(input, canvas);5_Ð 1ÿÿÿÿV„WHõ02® this.systems = systems;5_Ð2ÿÿÿÿV„WZõ13® this.prefabs = prefabs;5_Ð2 ÿÿÿÿV„W[õ13®* this.prefabs = require("./data/systems");5_Ð%ÿÿÿÿV„Wiõ$&®gfunction Game(canvas, animations, entities, images, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wiõ$&®]function Game(canvas, , entities, images, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wmõ$&®[function Game(canvas, entities, images, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wnõ$&®Sfunction Game(canvas, , images, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wqõ$&®Qfunction Game(canvas, images, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wqõ$&®Kfunction Game(canvas, , input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wsõ$&®Ifunction Game(canvas, input, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„Wsõ$&®Dfunction Game(canvas, , require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„W{õ$&®Bfunction Game(canvas, require, scenes, sounds, systems, prefabs) {5_Ð%ÿÿÿÿV„W{õ$&®