Refactor namespace to be less verbose
This commit is contained in:
parent
2cba724224
commit
28d2d49b1c
|
@ -1 +1 @@
|
||||||
../closure-library/closure/bin/build/closurebuilder.py --root=../closure-library/ --root=js-lib/ --namespace="asciiflow.launch" --compiler_flags="--warning_level=VERBOSE" --compiler_flags="--formatting=PRETTY_PRINT" --compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" --compiler_flags="--externs=jquery-1.9-externs.js" --output_mode=compiled --compiler_jar=closure-compiler.jar > js-compiled.js
|
../closure-library/closure/bin/build/closurebuilder.py --root=../closure-library/ --root=js-lib/ --namespace="ascii.launch" --compiler_flags="--warning_level=VERBOSE" --compiler_flags="--formatting=PRETTY_PRINT" --compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" --compiler_flags="--externs=jquery-1.9-externs.js" --output_mode=compiled --compiler_jar=closure-compiler.jar > js-compiled.js
|
||||||
|
|
|
@ -1,12 +1,23 @@
|
||||||
/**
|
/**
|
||||||
* Common classes.
|
* Common classes.
|
||||||
*/
|
*/
|
||||||
goog.provide('asciiflow.common');
|
goog.provide('ascii.Position');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
asciiflow.common.Position = function(x, y) {
|
ascii.Position = function(x, y) {
|
||||||
/** type {Number} */ this.x = x;
|
/** type {Number} */ this.x = x;
|
||||||
/** type {Number} */ this.y = y;
|
/** type {Number} */ this.y = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
goog.provide('ascii.Blah');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
ascii.Blah = function(x, y) {
|
||||||
|
/** type {Number} */ this.x = x;
|
||||||
|
/** type {Number} */ this.y = y;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,46 +2,47 @@
|
||||||
* Handles user input events and modifies state.
|
* Handles user input events and modifies state.
|
||||||
* Core logic comes through this class.
|
* Core logic comes through this class.
|
||||||
*/
|
*/
|
||||||
goog.provide('asciiflow.Controller');
|
goog.provide('ascii.Controller');
|
||||||
|
|
||||||
goog.require('asciiflow.View');
|
goog.require('ascii.Position');
|
||||||
|
goog.require('ascii.View');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
asciiflow.Controller = function(view) {
|
ascii.Controller = function(view) {
|
||||||
/** type {asciiflow.View} */
|
/** type {ascii.View} */
|
||||||
this.view = view;
|
this.view = view;
|
||||||
/** type {asciiflow.common.Position} */
|
/** type {ascii.Position} */
|
||||||
this.clickPosition;
|
this.clickPosition;
|
||||||
|
|
||||||
this.installDesktopBindings();
|
this.installDesktopBindings();
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.Controller.prototype.handlePress = function(x, y) {
|
ascii.Controller.prototype.handlePress = function(x, y) {
|
||||||
this.clickPosition = new asciiflow.common.Position(x, y);
|
this.clickPosition = new ascii.Position(x, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.Controller.prototype.handleMove = function(x, y) {
|
ascii.Controller.prototype.handleMove = function(x, y) {
|
||||||
if (this.clickPosition) {
|
if (this.clickPosition) {
|
||||||
// Drag has started.
|
// Drag has started.
|
||||||
this.view.offset.x -= (x - this.clickPosition.x)/this.view.zoom;
|
this.view.offset.x -= (x - this.clickPosition.x)/this.view.zoom;
|
||||||
this.view.offset.y -= (y - this.clickPosition.y)/this.view.zoom;
|
this.view.offset.y -= (y - this.clickPosition.y)/this.view.zoom;
|
||||||
this.clickPosition = new asciiflow.common.Position(x, y);
|
this.clickPosition = new ascii.Position(x, y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.Controller.prototype.handleRelease = function(x, y) {
|
ascii.Controller.prototype.handleRelease = function(x, y) {
|
||||||
this.clickPosition = null;
|
this.clickPosition = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.Controller.prototype.handleZoom = function(delta) {
|
ascii.Controller.prototype.handleZoom = function(delta) {
|
||||||
this.view.zoom *= delta > 0 ? 1.1 : 0.9;
|
this.view.zoom *= delta > 0 ? 1.1 : 0.9;
|
||||||
this.view.zoom = Math.max(Math.min(this.view.zoom, 5), 0.2);
|
this.view.zoom = Math.max(Math.min(this.view.zoom, 5), 0.2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
asciiflow.Controller.prototype.installDesktopBindings = function() {
|
ascii.Controller.prototype.installDesktopBindings = function() {
|
||||||
var controller = this;
|
var controller = this;
|
||||||
$(this.view.canvas).bind('mousewheel', function(e) {
|
$(this.view.canvas).bind('mousewheel', function(e) {
|
||||||
controller.handleZoom(e.originalEvent.wheelDelta);
|
controller.handleZoom(e.originalEvent.wheelDelta);
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
/**
|
/**
|
||||||
* Application main entry point.
|
* Application main entry point.
|
||||||
*/
|
*/
|
||||||
goog.provide('asciiflow.launch');
|
goog.provide('ascii.launch');
|
||||||
|
|
||||||
goog.require('asciiflow.Controller');
|
goog.require('ascii.Controller');
|
||||||
goog.require('asciiflow.State');
|
goog.require('ascii.State');
|
||||||
goog.require('asciiflow.View');
|
goog.require('ascii.View');
|
||||||
|
|
||||||
asciiflow.launch = function() {
|
/**
|
||||||
var state = new asciiflow.State();
|
* @private
|
||||||
var view = new asciiflow.View(state);
|
*/
|
||||||
var controller = new asciiflow.Controller(view);
|
ascii.launch = function() {
|
||||||
|
var state = new ascii.State();
|
||||||
|
var view = new ascii.View(state);
|
||||||
|
var controller = new ascii.Controller(view);
|
||||||
view.animate();
|
view.animate();
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.launch();
|
ascii.launch();
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
/**
|
/**
|
||||||
* Classes holding the state of the ascii-diagram.
|
* Classes holding the state of the ascii-diagram.
|
||||||
*/
|
*/
|
||||||
goog.provide('asciiflow.State');
|
goog.provide('ascii.State');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
asciiflow.Cell = function() {
|
ascii.Cell = function() {
|
||||||
/** @type {string|null} */ // Uses the string "#" for lines.
|
/** @type {string|null} */ // Uses the string "#" for lines.
|
||||||
this.value = null;
|
this.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.Cell.prototype.setValue = function(value) {
|
ascii.Cell.prototype.setValue = function(value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
asciiflow.State = function() {
|
ascii.State = function() {
|
||||||
/** @type {Array.<Array.<asciiflow.Cell>>} */
|
/** @type {Array.<Array.<ascii.Cell>>} */
|
||||||
this.cells = new Array(asciiflow.State.MAX_SIZE);
|
this.cells = new Array(ascii.State.MAX_SIZE);
|
||||||
|
|
||||||
for (var i = 0; i < this.cells.length; i++) {
|
for (var i = 0; i < this.cells.length; i++) {
|
||||||
this.cells[i] = new Array(asciiflow.State.MAX_SIZE);
|
this.cells[i] = new Array(ascii.State.MAX_SIZE);
|
||||||
for (var j = 0; j < this.cells[i].length; j++) {
|
for (var j = 0; j < this.cells[i].length; j++) {
|
||||||
this.cells[i][j] = new asciiflow.Cell();
|
this.cells[i][j] = new ascii.Cell();
|
||||||
// Hack: Just fill image with random stuff for now.
|
// Hack: Just fill image with random stuff for now.
|
||||||
if ((i % 10 == 0) && (j % 10 == 0)) {
|
if ((i % 10 == 0) && (j % 10 == 0)) {
|
||||||
var jstr = ("" + j);
|
var jstr = ("" + j);
|
||||||
|
@ -35,7 +35,7 @@ asciiflow.State = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @const */ asciiflow.State.MAX_SIZE = 1000;
|
/** @const */ ascii.State.MAX_SIZE = 1000;
|
||||||
|
|
||||||
asciiflow.State.prototype.blah = function() {
|
ascii.State.prototype.blah = function() {
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
/**
|
/**
|
||||||
* Functions relating to view operations and management of the screen.
|
* Functions relating to view operations and management of the screen.
|
||||||
*/
|
*/
|
||||||
goog.provide('asciiflow.View');
|
goog.provide('ascii.View');
|
||||||
|
|
||||||
goog.require('asciiflow.common');
|
goog.require('ascii.Position');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
asciiflow.View = function(state) {
|
ascii.View = function(state) {
|
||||||
/** type {Element} */ this.canvas = document.getElementById('ascii-canvas');
|
/** type {Element} */ this.canvas = document.getElementById('ascii-canvas');
|
||||||
/** type {Object} */ this.context = this.canvas.getContext('2d');
|
/** type {Object} */ this.context = this.canvas.getContext('2d');
|
||||||
/** type {number} */ this.zoom = 1;
|
/** type {number} */ this.zoom = 1;
|
||||||
/** type {asciiflow.common.Position} */ this.offset = new asciiflow.common.Position(0, 0);
|
/** type {ascii.Position} */ this.offset = new ascii.Position(0, 0);
|
||||||
/** type {asciiflow.State} */ this.state = state;
|
/** type {ascii.State} */ this.state = state;
|
||||||
this.resizeCanvas();
|
this.resizeCanvas();
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.View.prototype.resizeCanvas = function() {
|
ascii.View.prototype.resizeCanvas = function() {
|
||||||
this.canvas.width = document.documentElement.clientWidth;
|
this.canvas.width = document.documentElement.clientWidth;
|
||||||
this.canvas.height = document.documentElement.clientHeight;
|
this.canvas.height = document.documentElement.clientHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.View.prototype.animate = function() {
|
ascii.View.prototype.animate = function() {
|
||||||
this.render();
|
this.render();
|
||||||
var view = this;
|
var view = this;
|
||||||
window.requestAnimationFrame(function() { view.animate(); });
|
window.requestAnimationFrame(function() { view.animate(); });
|
||||||
};
|
};
|
||||||
|
|
||||||
asciiflow.View.prototype.render = function() {
|
ascii.View.prototype.render = function() {
|
||||||
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
// Clear the visible area.
|
// Clear the visible area.
|
||||||
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
@ -49,7 +49,7 @@ asciiflow.View.prototype.render = function() {
|
||||||
/**
|
/**
|
||||||
* Given a screen coordinate, find the integer cell position that it relates to.
|
* Given a screen coordinate, find the integer cell position that it relates to.
|
||||||
*/
|
*/
|
||||||
asciiflow.View.prototype.getCell = function(x, y) {
|
ascii.View.prototype.getCell = function(x, y) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue