From 3ebd5165f0449bdde2c98d9b9ec52a4dac4cdd0f Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 1 Dec 2010 01:45:21 -0800 Subject: [PATCH] Checkpoint in module refactor for the new server git repo. --- bin/cjs.py | 131 ++++++++++++++------- doc/gameplay.md | 122 ++++++++++++------- index.php | 2 +- lib/cjs/require.js | 2 +- lib/jquery.hotkeys.js | 1 + lib/jquery.hotkeys.min.js | 1 + lib/jquery.sparkline.js | 1 + lib/jquery.sparkline.min.js | 2 +- src/Y/class.cjs | 20 +++- src/Y/core.cjs | 5 +- src/Y/index.cjs | 12 +- src/Y/modules/y.event.cjs | 13 ++- src/Y/type.cjs | 4 +- src/Y/types/function.cjs | 13 +- src/evt/class.cjs | 246 +++++++++++++++++++++++++++++++++++++++ src/evt/evt.class.js | 246 --------------------------------------- src/ezl/loop/eventloop.cjs | 2 - src/ezl/math/rect.cjs | 3 +- src/ezl/math/vec.cjs | 5 +- src/ezl/shape/circle.cjs | 9 +- src/ezl/shape/line.cjs | 11 ++- src/ezl/shape/rect.cjs | 2 +- src/ezl/shape/shape.cjs | 8 +- src/ezl/util/tree/quadtree.cjs | 3 +- src/tanks/config.cjs | 5 +- src/tanks/game.cjs | 45 +++++--- src/tanks/globals.cjs | 52 -------- src/tanks/globals.js | 34 ++++++ src/tanks/index.cjs | 26 ++++- src/tanks/map/index.cjs | 8 ++ src/tanks/map/level.cjs | 70 ++--------- src/tanks/map/pathmap.cjs | 20 ++-- src/tanks/map/trajectory.cjs | 26 +++-- src/tanks/map/wall.cjs | 61 ++++++++++ src/tanks/thing/bullet.cjs | 14 ++- src/tanks/thing/custom-tank.cjs | 8 -- src/tanks/thing/customtank.cjs | 13 ++ src/tanks/thing/index.cjs | 10 +- src/tanks/thing/player.cjs | 18 ++- src/tanks/thing/tank.cjs | 19 ++- src/tanks/thing/thing.cjs | 18 ++- src/tanks/ui/config.cjs | 88 ++++++++++++++ src/tanks/ui/grid.cjs | 10 ++- src/tanks/ui/index.cjs | 3 + src/tanks/ui/main.cjs | 47 ++++++-- src/tanks/ui/ui-config.cjs | 90 -------------- src/tanks/ui/ui.cjs | 1 - src/tanks/util/config.cjs | 13 ++- tags.php | 58 +++++++++ tanks.php | 16 ++- 50 files changed, 967 insertions(+), 670 deletions(-) create mode 100644 src/evt/class.cjs delete mode 100644 src/evt/evt.class.js delete mode 100644 src/tanks/globals.cjs create mode 100644 src/tanks/globals.js create mode 100644 src/tanks/map/wall.cjs delete mode 100644 src/tanks/thing/custom-tank.cjs create mode 100644 src/tanks/thing/customtank.cjs create mode 100644 src/tanks/ui/config.cjs delete mode 100644 src/tanks/ui/ui-config.cjs delete mode 100644 src/tanks/ui/ui.cjs create mode 100644 tags.php diff --git a/bin/cjs.py b/bin/cjs.py index dbdbc72..1bd5429 100755 --- a/bin/cjs.py +++ b/bin/cjs.py @@ -7,11 +7,12 @@ __version__ = (0, 0, 1) __all__ = ('ResolutionError', 'Module', 'JSResolver',) -import sys, re, json +import sys, re, jsond as json from itertools import chain, repeat from collections import defaultdict from subprocess import Popen, check_output, STDOUT, PIPE from glob import glob +from pprint import pprint, pformat from bunch import * from path import path @@ -72,6 +73,8 @@ def partition(it, sep): return (before, None, []) return (before, sep, list(it)) + + def canonicalise(query, base=None): """ query: A module ID (relative or absolute) or filepath base: Optional. The referring module ID. @@ -185,6 +188,9 @@ class Module(Bunch): def requires(self): return self.calcRequires('_at_requires') + self._requires + def __json_default__(self): + return dict( (k,self[k]) for k in 'id file name _requires _at_requires'.split(' ') ) + def __hash__(self): return hash(self.id) @@ -206,32 +212,12 @@ class Module(Bunch): class CommonJS(object): """ Compiles JS modules into browser-safe JS files. """ - @staticmethod - def discover(files, repos, **options): - "Discover listed modules and their dependencies." - cjs = CommonJS(repos, **options) - queue = [ cjs.lookup(f) for f in files ] - seen = set() - while queue: - mod = queue.pop(0) - seen.add(mod) - # print mod, "requirements:", mod.requires - for query in mod.requires: - # print mod, "requires", query - req = cjs.lookup(query, mod) - if req not in seen: - queue.append(req) - if cjs.deps_name: - cjs.genDepLoader() - return cjs - - repos = [] modules = {} # id -> Module _graph = None # id -> set(dependants) _at_graph = None # id -> set(dependants) - def __init__(self, repos, out='build', deps_name=None, clean=True, **options): + def __init__(self, repos, out='build', save='build', deps_name=None, clean=True, **options): self.modules = {} self.options = options self.deps_name = deps_name @@ -274,6 +260,11 @@ class CommonJS(object): for k, mod in self.modules.iteritems(): yield k, mod + def reset(self): + self._graph = None + self._at_graph = None + return self + def calcGraph(self, attr): if self._graph is None: graph = self._graph = defaultdict(set) @@ -294,31 +285,38 @@ class CommonJS(object): return self.calcGraph('_at_graph') def tsort(self, graph): - p = Popen(['tsort'], stderr=STDOUT, stdin=PIPE, stdout=PIPE) + p = Popen(['tsort'], stderr=sys.stderr, stdin=PIPE, stdout=PIPE) deps = '\n'.join( '%s %s' % (id, dep.id) for (id, deps) in graph.iteritems() for dep in deps ) p.stdin.write(deps) p.stdin.close() if p.wait() != 0: raise ResolutionError('Cannot resolve dependencies! Requirements must be acyclic!') - return p.stdout.read() + return p.stdout.read().strip().split('\n') @property def dependencies(self): - deps = (self.tsort(self.atGraph)+self.tsort(self.graph)).strip().split('\n') - for i, dep in reversed(list(enumerate(deps[:]))): - try: - idx = deps.index(dep, 0, i-1) - if i != idx: - del deps[idx] - except ValueError: pass - return deps + atg = self.tsort(self.atGraph) + nog = self.tsort(self.graph) + atdeps = self.atGraph.keys() + + for dep in atg[:]: + if dep not in atdeps: + try: atg.remove(dep) + except ValueError: pass + else: + try: nog.remove(dep) + except ValueError: pass + + # print '\nAtKeys:\n', pformat(atdeps), '\n' + # print '\nAtDeps:\n', pformat(atg), '\n' + # print '\nNoKeys:\n', pformat(nog), '\n' + return atg+nog def dumpDependencies(self): column = Popen(['column', '-s', '\t', '-t'], stderr=sys.stderr, stdin=PIPE, stdout=PIPE) - mods = self.modules.values() - for mod in sorted(mods, key=lambda m: len(m.requires), reverse=True): + # for mod in sorted(self.modules.values(), key=lambda m: len(m.requires), reverse=True): + for mod in sorted(self.modules.values()): column.stdin.write('%s\t->\t%r\n' % (mod, sorted(mod.requires))) - # print '%s\t->\t%r' % (mod, sorted(mod.requires)) column.stdin.close() if column.wait() != 0: print >> sys.stderr, 'Some sort of error has occurred!' @@ -335,6 +333,54 @@ class CommonJS(object): @property def scriptTags(self): return '\n'.join( ''.format(uri) for uri in self.uris ) + + def save(self, dir): + with (path(dir)/'.modules.json').open('w') as f: + json.dump({ + 'modules' : self.modules, + 'ensure' : dict( (id, list(mod.id for mod in mods)) for id,mods in self.atGraph.iteritems() ), + 'graph' : dict( (id, list(mod.id for mod in mods)) for id,mods in self.graph.iteritems() ), + }, f, indent=4) + return self + + @staticmethod + def discover(files, repos, **options): + "Discover listed modules and their dependencies." + cjs = CommonJS(repos, **options) + + # print >> sys.stderr, '\n[ %s ]' % f + + queue = [ cjs.reset().lookup(f) for f in files ] + seen = set() + while queue: + mod = queue.pop(0) + seen.add(mod) + # print mod, "requirements:", mod.requires + for query in mod.requires: + # print mod, "requires", query + req = cjs.lookup(query, mod) + if req not in seen: + queue.append(req) + + if options.get('deps_name', None): + cjs.genDepLoader() + + if options.get('print_deps', None): + print >> sys.stderr, '\n[ %s ]' % f + print >> sys.stderr, 'All Dependencies:' + print >> sys.stderr, cjs.dumpDependencies() + print >> sys.stderr, '' + print >> sys.stderr, 'Resolution:' + print >> sys.stderr, '\n'.join(cjs.dependencies) + + if options.get('script_tags', None): + print cjs.scriptTags + + if options.get('state', None): + cjs.save(options['state']) + + return cjs + @@ -360,6 +406,9 @@ def main(): help="Generates a JS script with the given name which doc-writes tags for this set of modules.") parser.add_option("-s", "--script-tags", default=False, action="store_true", help="Emits script-tags for this set of modules in dependency order. [default: %default]") + parser.add_option("-S", "--state", default='build', + help="Directory to save build state. [default: %default]") + (options, args) = parser.parse_args() @@ -373,21 +422,11 @@ def main(): # print 'files:', files, 'repos:', (repos or ['.']) try: - js = CommonJS.discover(files=files, repos=repos or ['.'], **options.__dict__) + cjs = CommonJS.discover(files=files, repos=repos or ['.'], **options.__dict__) except ResolutionError as ex: print >> sys.stderr, str(ex) return 1 - if options.script_tags: - print js.scriptTags - - if options.print_deps: - print >> sys.stderr, 'All Dependencies:' - print >> sys.stderr, js.dumpDependencies() - print >> sys.stderr, '' - print >> sys.stderr, 'Resolution:' - print >> sys.stderr, '\n'.join(js.dependencies) - return 0 if __name__ == '__main__': diff --git a/doc/gameplay.md b/doc/gameplay.md index 02a1ac4..fd3a511 100644 --- a/doc/gameplay.md +++ b/doc/gameplay.md @@ -1,63 +1,93 @@ # The Littlest Battletank -Inspired by Tanks minigame off Wii Play. +Inspired by the Tanks minigame in Wii Play. + ## The Basics - Your tank has 1hp. - Your basic cannon shoots bullets. A bullet lives for one bounce or until it kills something. You can have up to 5 bullets at a time in the air. - When you die, you respawn after a few seconds. (In single player, it restarts the level.) + ## Controls -- wasd, arrows: move your tank. -- mouse: aim your reticule. -- click, space, enter: fire a shot. -- 0-9: use items. -- All controls can be configured. - -## Ideas -- Simplicity is king. -- Only bosses have more than 1hp -- Always on one screen -- No stats: all items are qualitative -- AI makes commentary on situations. "That was close. Sucker." "loool, you always die here." -- Use TruRank-style player rating system, but the point of multiplayer will not be the ladder -- Optional registration (Flash cookie every user) -- Badges, awards, stats -- Virtual currency from various in-game activities - -## Power-Ups -- Missiles (fast, no bounce) -- Refractor Rounds (slow, infi bounces) -- Flamethrower (Cone AOE) -- Shrapnel Rounds (splits once on impact) -- Mortar Rounds (Projectile AOE) -- Mines (Stationary Prox AOE) -- Heatseekers (Projectile Prox) -- Nukes (Absurd AOE which often kills you) -- Portal Cannon (Exchanges your position with your cursor) -- K-Boss Shield (Absorbs 1 damage) -- Gin & Tonic / iPhone 3G / Hannah Montana Lamp (Extra Life) -- Deuschund Trebuchet (Parabolic Arc lulz) -- Light Cannon (Faster Move, -1 Shots in Air) -- EMP Device (aka, the "Stunna") (Freezes everyone in place. Including you.) - -## Mechanics -- AOE -- Shot Travel Speed -- Shot Bounces -- Shot Cooldown -- Shots in Air -- Move Speed -- HP (Bosses only) -- Allies -- companion AI tanks which play for your side, but they can still damage you -- Can use Items -- AI type, quality -- Mutable Environment? + +### Desktop Controls + +- Move: wasd, arrows for cardinal directions; combine for 45-degree moves +- Shoot: + - Aim your reticule with the mouse + - Click, or press space to fire a shot +- Items: Press `12345zxc +- Zoom: Mouse wheel +- Customization: + - Keyboard controls can be rebound + - Multiple UI trays + +### iOS Controls +- Move: Trace a path from your tank with your finger +- Shoot: + - Tap once somewhere sufficiently far from your tank to shoot one bullet on a trajectory aimed at that point + - Tap once and hold to see the trajectory line + - Move your finger to drag the line at a new point + - Release the tap to shoot along that trajectory + - Tap with your other hand sufficiently far from your tank and the current trajectory point to cancel +- Items: On-screen buttons, possibly modal +- Zoom: Pinch +- Customization: + - Modal buttons used to switch between multiple UI "trays" with buttons + - Free gestures can be rebound (two/three finger swipe, double-tap, triple-tap) + + +## Gameplay Ideas +- No camera control: camera centers on tank and moves with it, though player can zoom the map +- No number games: all items are qualitative (so, ex: only bosses have more than 1hp, but items (like shields) might absorb damage) +- Allies: companion AI tanks which play for your side (beware friendly fire)- Mutable Environment: obstacles can be destroyed with the right weapons, enemies can be pushed +## Items +### Cannons +- Missiles: Faster projectile, but no bounce +- Refractor Rounds: Slower projectile, but infi bounces +- Shrapnel Rounds: Projectile that splits instead of bounce +### Heavy Munitions +- Flamethrower: Cone AOE +- Mortar Rounds: Projectile with AOE on detonation +- Proximity Missiles: Projectile that explodes on prox +- Mines: Stationary prox AOE +### Special Weapons +- Heatseekers: Projectile that will guide around walls to get to your target point, and then explodes even if no one is there +- Nuke: Slow projectile with enormous AOE (reminder: friendly fire) +- Trebuchet Rounds: Projectile which only collides when it reaches its destination (as if it was fired in a parabolic arc) +- Portal Cannon: Makes source/dest wormholes +### Passives +- Light Ordinance: Faster move, fewer shots in air +- Tactical Driver: Attempts to automatically move your tank out of harm's way when a bullet is imminent +- Chameleon Engine: Makes enemies unable to see you for a limited time, confusing pathing + +### Shields +- Turret Shield: extends 45-degrees around tour tank, centered on the barrel; impact pushes your tank back +- Orbital Shield: small pellet-shield that orbits your tank +- Stationary Shield: stationary shield sphere, passable to tanks but not bullets +- Imprinted Stationary Shield: as the stationary shield, but passable only to your team and not others + +### Consumables +- Cloudpot: Your tank deploys an emergency zeppelin to float quickly from your current position to your cursor. Tank can only be hit by Trebuchet Rounds during that time. +- The Stunna Shocka (EMP Device): Freezes all tanks in place (including you) + + +## Tank Attributes +- Movement: speed, turning speed +- Cannon: cooldown, max in air, recoil? +- Bullets: speed, num bounces, proximity, AOE explosion +- Toughness: hp (Bosses only), shields, resistance to certain classes of weapons + + +## Flavor +- AI makes commentary on situations. "That was close. Sucker." "loool, you always die here." +- Papercraft art style, vector graphics diff --git a/index.php b/index.php index 3ac3f78..8d435d9 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ diff --git a/lib/cjs/require.js b/lib/cjs/require.js index 98d77d7..586ad3e 100644 --- a/lib/cjs/require.js +++ b/lib/cjs/require.js @@ -10,7 +10,7 @@ function require(id){ if ( !modules.hasOwnProperty(id) ) throw new Error('No such module "'+id+'"!'); - var module = modules[ids] + var module = modules[id] , exports = module.exports = {}; // TODO: load the module diff --git a/lib/jquery.hotkeys.js b/lib/jquery.hotkeys.js index fbd71c7..315014f 100644 --- a/lib/jquery.hotkeys.js +++ b/lib/jquery.hotkeys.js @@ -1,3 +1,4 @@ +//@require('jquery') /* * jQuery Hotkeys Plugin * Copyright 2010, John Resig diff --git a/lib/jquery.hotkeys.min.js b/lib/jquery.hotkeys.min.js index 6689e7a..90a601f 100644 --- a/lib/jquery.hotkeys.min.js +++ b/lib/jquery.hotkeys.min.js @@ -1 +1,2 @@ +//@require('jquery') (function(b){b.fn.__bind__=b.fn.bind;b.fn.__unbind__=b.fn.unbind;b.fn.__find__=b.fn.find;var a={version:"0.7.9",override:/keypress|keydown|keyup/g,triggersMap:{},specialKeys:{27:"esc",9:"tab",32:"space",13:"return",8:"backspace",145:"scroll",20:"capslock",144:"numlock",19:"pause",45:"insert",36:"home",46:"del",35:"end",33:"pageup",34:"pagedown",37:"left",38:"up",39:"right",40:"down",109:"-",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",191:"/"},shiftNums:{"`":"~","1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")","-":"_","=":"+",";":":","'":'"',",":"<",".":">","/":"?","\\":"|"},newTrigger:function(e,d,f){var c={};c[e]={};c[e][d]={cb:f,disableInInput:false};return c}};a.specialKeys=b.extend(a.specialKeys,{96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/"});b.fn.find=function(c){this.query=c;return b.fn.__find__.apply(this,arguments)};b.fn.unbind=function(h,e,g){if(b.isFunction(e)){g=e;e=null}if(e&&typeof e==="string"){var f=((this.prevObject&&this.prevObject.query)||(this[0].id&&this[0].id)||this[0]).toString();var d=h.split(" ");for(var c=0;c=0;i--){var el=pending[i][0];if($(el).is(':visible')&&!$(el).parents().is(':hidden')){pending[i][1].call(el);pending.splice(i,1);}}};$.fn.sparkline.line=function(values,options,width,height){var options=$.extend({spotColor:'#f80',spotRadius:1.5,minSpotColor:'#f80',maxSpotColor:'#f80',lineWidth:1,normalRangeMin:undefined,normalRangeMax:undefined,normalRangeColor:'#ccc',chartRangeMin:undefined,chartRangeMax:undefined,chartRangeMinX:undefined,chartRangeMaxX:undefined},options?options:{});var xvalues=[],yvalues=[],yminmax=[];for(i=0;i') .append(this.canvas) diff --git a/src/ezl/shape/rect.cjs b/src/ezl/shape/rect.cjs index b61641b..6222886 100644 --- a/src/ezl/shape/rect.cjs +++ b/src/ezl/shape/rect.cjs @@ -1,4 +1,4 @@ -var Shape = require('ezl/shape').Shape +var Shape = require('ezl/shape/shape').Shape , Rect = diff --git a/src/ezl/shape/shape.cjs b/src/ezl/shape/shape.cjs index 7b24a8d..1c3aa8c 100644 --- a/src/ezl/shape/shape.cjs +++ b/src/ezl/shape/shape.cjs @@ -1,4 +1,10 @@ -Shape = new Y.Class('Shape', Layer, { +var Y = require('Y').Y +, Layer = require('ezl/layer').Layer +, + +Shape = +exports['Shape'] = +Layer.subclass('Shape', { _cssClasses : 'ezl layer shape', fillStyle : 'rgba(231,48,117, 1)', strokeStyle : 'transparent', diff --git a/src/ezl/util/tree/quadtree.cjs b/src/ezl/util/tree/quadtree.cjs index 8ff0636..16d6f83 100644 --- a/src/ezl/util/tree/quadtree.cjs +++ b/src/ezl/util/tree/quadtree.cjs @@ -1,4 +1,5 @@ -var CAPACITY = 8 +var Y = require('Y').Y +, CAPACITY = 8 , REGION_ID = 0 , diff --git a/src/tanks/config.cjs b/src/tanks/config.cjs index e905a6b..953ca74 100644 --- a/src/tanks/config.cjs +++ b/src/tanks/config.cjs @@ -1,5 +1,7 @@ // -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*- -var defaults = +var Y = require('Y').Y + +, defaults = exports.defaults = { ui : { showGridCoords : false, @@ -11,4 +13,5 @@ exports.defaults = { traceTrajectories : false } }; + exports.values = Y(defaults).clone().end(); diff --git a/src/tanks/game.cjs b/src/tanks/game.cjs index f7a07f5..3f9da2f 100644 --- a/src/tanks/game.cjs +++ b/src/tanks/game.cjs @@ -1,20 +1,28 @@ -var tanks = require('tanks') -, map = require('tanks/map') -, thing = require('tanks/thing') -, Grid = require('tanks/ui/grid').Grid +//@require('lessly/future') +//@require('jquery') -, Level = map.Level -, Thing = thing.Thing, Tank = thing.Tank, Bullet = thing.Bullet +var Y = require('Y').Y +, Event = require('Y/modules/y.event').Event +, EventLoop = require('ezl/loop').EventLoop -; +, config = require('tanks/config') +, map = require('tanks/map') +, thing = require('tanks/thing') +, Grid = require('tanks/ui/grid').Grid -exports.Game = Y.subclass('Game', { +, Level = map.Level +, Thing = thing.Thing, Tank = thing.Tank, Bullet = thing.Bullet +, + + +Game = +exports['Game'] = +Y.subclass('Game', { overlayPathmap : false, - init : function init(viewport){ + init : function initGame(viewport){ Y.bindAll(this); - tanks.resetGlobals(); this.byId = {}; this.active = new Y.YArray(); @@ -46,14 +54,22 @@ exports.Game = Y.subclass('Game', { destroy : function destroy(){ this.stop(); - tanks.resetGlobals(); + this.resetGlobals(); + }, + + resetGlobals : function resetGlobals(){ + NOW = new Date().getTime(); + ELAPSED = MS_PER_FRAME; + TICKS = 0; + SECONDTH = ELAPSED / 1000; + SQUARETH = REF_SIZE * SECONDTH; }, draw : function draw(){ this.root.draw(); this.pathmap.removeOverlay(this.viewport); - if (tanks.config.values.pathing.overlayPathmap) + if (config.values.pathing.overlayPathmap) this.pathmap.overlay(this.viewport); }, @@ -94,7 +110,7 @@ exports.Game = Y.subclass('Game', { // *** Agent Management *** // addUnit : function addUnit(unit, col,row){ - if (unit instanceof Y.event.YEvent) + if (unit instanceof Event) unit = unit.instance; unit.game = this; @@ -126,7 +142,7 @@ exports.Game = Y.subclass('Game', { }, killUnit : function killUnit(unit){ - if (unit instanceof Y.event.YEvent) + if (unit instanceof Event) unit = unit.instance; // console.log('killUnit(', unit, ')'); @@ -190,4 +206,3 @@ exports.Game = Y.subclass('Game', { }); - diff --git a/src/tanks/globals.cjs b/src/tanks/globals.cjs deleted file mode 100644 index 67dfe05..0000000 --- a/src/tanks/globals.cjs +++ /dev/null @@ -1,52 +0,0 @@ -var undefined -, GRID_ELEMENT = '#viewport' - -, REF_SIZE = 50 -, CELL_SIZE = REF_SIZE -, SCALE = CELL_SIZE / REF_SIZE -, GRID_OFFSET = 0 - -, COLUMNS = 10 -, ROWS = 10 -, CAPACITY = 32 - -, FRAME_RATE = 30 -, MS_PER_FRAME = 1000 / FRAME_RATE - -, NOW = new Date().getTime() // Current tick's timestamp (ms) -, ELAPSED = MS_PER_FRAME // Time (ms) since previous tick -, TICKS = 0 // Ticks since start of game - - -/// Common Components of Computation /// - -, SECONDTH = ELAPSED / 1000 // Amount of second completed in this tick -, SQUARETH = REF_SIZE * SECONDTH // Amount of square/second covered in this tick - -, PI = Math.PI -, QUARTER_PI = PI/4 -, HALF_PI = PI/2 -, PI_AND_HALF = PI + HALF_PI -, TWO_PI = PI*2 - -; - -tanks.resetGlobals = function resetGlobals(){ - NOW = new Date().getTime(); - ELAPSED = MS_PER_FRAME; - TICKS = 0; - - SECONDTH = ELAPSED / 1000; - SQUARETH = REF_SIZE * SECONDTH; -}; - -if (!window.console) { - console = { - log : Y.op.nop, - info : Y.op.nop, - warn : Y.op.nop, - error : Y.op.nop, - dir : Y.op.nop, - debug : Y.op.nop - }; -} diff --git a/src/tanks/globals.js b/src/tanks/globals.js new file mode 100644 index 0000000..cb949e5 --- /dev/null +++ b/src/tanks/globals.js @@ -0,0 +1,34 @@ + +var undefined +, Y = require('Y').Y +, GRID_ELEMENT = '#viewport' + +, REF_SIZE = 50 +, CELL_SIZE = REF_SIZE +, SCALE = CELL_SIZE / REF_SIZE +, GRID_OFFSET = 0 + +, COLUMNS = 10 +, ROWS = 10 +, CAPACITY = 32 + +, FRAME_RATE = 30 +, MS_PER_FRAME = 1000 / FRAME_RATE + +, NOW = new Date().getTime() // Current tick's timestamp (ms) +, ELAPSED = MS_PER_FRAME // Time (ms) since previous tick +, TICKS = 0 // Ticks since start of game + + +/// Common Components of Computation /// + +, SECONDTH = ELAPSED / 1000 // Amount of second completed in this tick +, SQUARETH = REF_SIZE * SECONDTH // Amount of square/second covered in this tick + +, PI = Math.PI +, QUARTER_PI = PI/4 +, HALF_PI = PI/2 +, PI_AND_HALF = PI + HALF_PI +, TWO_PI = PI*2 + +; diff --git a/src/tanks/index.cjs b/src/tanks/index.cjs index 4b77f3b..b9ac483 100644 --- a/src/tanks/index.cjs +++ b/src/tanks/index.cjs @@ -1,2 +1,24 @@ -var tanks = exports.tanks = {}; -tanks.config = require('tanks/config'); +//@ require('tanks/globals') +var Y = require('Y').Y; + +require('tanks/globals'); + +tanks = exports.tanks = { + 'config' : require('tanks/config'), + 'ui' : require('tanks/ui'), + 'Game' : require('tanks/game').Game, + + 'currentGame' : null, + +}; + +if (!window.console) { + console = { + log : Y.op.nop, + info : Y.op.nop, + warn : Y.op.nop, + error : Y.op.nop, + dir : Y.op.nop, + debug : Y.op.nop + }; +} diff --git a/src/tanks/map/index.cjs b/src/tanks/map/index.cjs index e69de29..7a345f6 100644 --- a/src/tanks/map/index.cjs +++ b/src/tanks/map/index.cjs @@ -0,0 +1,8 @@ +var Y = require('Y').Y; + +Y.extend(exports, { + 'Level' : require('tanks/map/level').Level, + 'Wall' : require('tanks/map/wall').Wall, + 'PathMap' : require('tanks/map/pathmap').PathMap, + 'Trajectory' : require('tanks/map/trajectory').Trajectory +}); diff --git a/src/tanks/map/level.cjs b/src/tanks/map/level.cjs index 12a6989..66075d0 100644 --- a/src/tanks/map/level.cjs +++ b/src/tanks/map/level.cjs @@ -1,4 +1,14 @@ -Level = Rect.subclass('Level', { +var Y = require('Y').Y +, Rect = require('ezl/shape').Rect +, Tank = require('tanks/thing/tank').Tank +, PlayerTank = require('tanks/thing/player').PlayerTank +, PathMap = require('tanks/map/pathmap').PathMap +, + + +Level = +exports['Level'] = +Rect.subclass('Level', { _cssClasses : 'ezl layer level', init : function init(game, w,h){ @@ -35,7 +45,7 @@ Level = Rect.subclass('Level', { }, addWall : function addWall(x,y, w,h, isBoundary){ - var wall = new Level.Wall(x,y, w,h, isBoundary); + var wall = new Wall(x,y, w,h, isBoundary); this.pathmap.addBlocker(wall); this.append( wall.render(this).shape ); @@ -47,58 +57,4 @@ Level = Rect.subclass('Level', { drawShape : Y.op.nop -}); - -Level.Wall = Thing.subclass('Wall', { - isBoundary : false, - blocking : true, - active : false, - - stats : { - hp : Infinity, - move : 0, - power : 0, - speed : 0, - shots : 0 - }, - - - init : function initWall(x,y, w,h, isBoundary){ - this.width = w; - this.height = h; - this.isBoundary = !!isBoundary; - Thing.init.call(this); - this.setLocation(x,y); - }, - - // inactive - createCooldowns : Y.op.nop, - - // indestructable - dealDamage : Y.op.nop, - - - render : function render(parent){ - if (this.isBoundary) - return this; - - if (this.shape) - this.shape.remove(); - - this.shape = - new Rect(this.width, this.height) - .position(this.loc.x, this.loc.y) - .fill('rgba(255,255,255, 0.25)') - .appendTo( parent ); - - return this; - }, - - toString : function(){ - var loc = this.loc - , x1 = loc.x, y1 = loc.y - , x2 = x1+this.width, y2 = y1 + this.height; - return this.className+'['+x1+','+y1+', '+x2+','+y2+'](w='+this.width+', h='+this.height+')'; - } -}); - +}); \ No newline at end of file diff --git a/src/tanks/map/pathmap.cjs b/src/tanks/map/pathmap.cjs index 7284034..afa0177 100644 --- a/src/tanks/map/pathmap.cjs +++ b/src/tanks/map/pathmap.cjs @@ -1,9 +1,13 @@ // -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*- -(function(){ +var Y = require('Y').Y +, QuadTree = require('ezl/util/tree/quadtree').QuadTree +, -PathMap = QuadTree.subclass('PathMap', { +PathMap = +exports['PathMap'] = +QuadTree.subclass('PathMap', { gridSquareSize : REF_SIZE, - gridSquareMidPt : new math.Vec(REF_SIZE/2, REF_SIZE/2), + gridSquareMidPt : new Vec(REF_SIZE/2, REF_SIZE/2), @@ -136,10 +140,10 @@ PathMap = QuadTree.subclass('PathMap', { for (var x=0; x x2 ? -REF_SIZE : REF_SIZE+pm.width ) @@ -33,8 +43,8 @@ Trajectory = math.Line.subclass('Trajectory', { // Move goal point beyond far wall to avoid rotations x2 = this.x2 = edge.x; y2 = this.y2 = edge.y; - this.p2 = new math.Vec(x2,y2); - math.Vec.init.call(this, x2-x1, y2-y1); + this.p2 = new Vec(x2,y2); + Vec.init.call(this, x2-x1, y2-y1); this.elapsed = 0; this.resetBound(); @@ -58,10 +68,10 @@ Trajectory = math.Line.subclass('Trajectory', { if (o instanceof Thing) return o.boundingBox.intersects(this); - if (o instanceof Loc.Rect) + if (o instanceof Rect) return o.intersects(this); - return math.Line.prototype.intersects.call(this, x,y); + return Line.prototype.intersects.call(this, x,y); }, @@ -163,7 +173,7 @@ Trajectory = math.Line.subclass('Trajectory', { if (this.halt) break; // FIXME: bb.add? - bb = new Loc.Rect(to.x,to.y, to.x+bw,to.y+bh); + bb = new Rect(to.x,to.y, to.x+bw,to.y+bh); } while (dt > 0); @@ -224,4 +234,4 @@ Trajectory = math.Line.subclass('Trajectory', { toString : function toString(){ return 'T['+this.p1+', '+this.p2+', slope='+this.slope.toFixed(3)+']'; } -}); \ No newline at end of file +}); diff --git a/src/tanks/map/wall.cjs b/src/tanks/map/wall.cjs new file mode 100644 index 0000000..0f79275 --- /dev/null +++ b/src/tanks/map/wall.cjs @@ -0,0 +1,61 @@ +var Y = require('Y').Y +, Rect = require('ezl/shape').Rect +, Thing = require('tanks/thing/thing').Thing +, + + +Wall = +exports['Wall'] = +Thing.subclass('Wall', { + isBoundary : false, + blocking : true, + active : false, + + stats : { + hp : Infinity, + move : 0, + power : 0, + speed : 0, + shots : 0 + }, + + + init : function initWall(x,y, w,h, isBoundary){ + this.width = w; + this.height = h; + this.isBoundary = !!isBoundary; + Thing.init.call(this); + this.setLocation(x,y); + }, + + // inactive + createCooldowns : Y.op.nop, + + // indestructable + dealDamage : Y.op.nop, + + + render : function render(parent){ + if (this.isBoundary) + return this; + + if (this.shape) + this.shape.remove(); + + this.shape = + new Rect(this.width, this.height) + .position(this.loc.x, this.loc.y) + .fill('rgba(255,255,255, 0.25)') + .appendTo( parent ); + + return this; + }, + + toString : function(){ + var loc = this.loc + , x1 = loc.x, y1 = loc.y + , x2 = x1+this.width, y2 = y1 + this.height; + return this.className+'['+x1+','+y1+', '+x2+','+y2+'](w='+this.width+', h='+this.height+')'; + } +}); + diff --git a/src/tanks/thing/bullet.cjs b/src/tanks/thing/bullet.cjs index 2dc640d..89d2a89 100644 --- a/src/tanks/thing/bullet.cjs +++ b/src/tanks/thing/bullet.cjs @@ -1,5 +1,15 @@ // -*- mode: JavaScript; tab-width: 4; indent-tabs-mode: nil; -*- -Bullet = Thing.subclass('Bullet', { +var Y = require('Y').Y +, shape = require('ezl/shape') +, Wall = require('tanks/map/wall').Wall +, Thing = require('tanks/thing/thing').Thing +, Line = shape.Line +, Circle = shape.Circle +, + +Bullet = +exports['Bullet'] = +Thing.subclass('Bullet', { traceTrajectories : true, @@ -78,7 +88,7 @@ Bullet = Thing.subclass('Bullet', { var agent = evt.trigger , trj = this.trajectory; - if ( agent instanceof Level.Wall && trj.bounces <= this.bounceLimit ) + if ( agent instanceof Wall && trj.bounces <= this.bounceLimit ) return; agent.dealDamage(this.stats.power, this); diff --git a/src/tanks/thing/custom-tank.cjs b/src/tanks/thing/custom-tank.cjs deleted file mode 100644 index c9a7267..0000000 --- a/src/tanks/thing/custom-tank.cjs +++ /dev/null @@ -1,8 +0,0 @@ -CustomTank = Tank.subclass('CustomTank', { - - init : function initCustomTank(align, script){ - Tank.init.call(this, align); - this.act = eval('(function(){ with(this){'+script+'} })'); - } - -}); \ No newline at end of file diff --git a/src/tanks/thing/customtank.cjs b/src/tanks/thing/customtank.cjs new file mode 100644 index 0000000..97dcecf --- /dev/null +++ b/src/tanks/thing/customtank.cjs @@ -0,0 +1,13 @@ +var Tank = require('tanks/thing/tank').Tank +, + +CustomTank = +exports['CustomTank'] = +Tank.subclass('CustomTank', { + + init : function initCustomTank(align, script){ + Tank.init.call(this, align); + this.act = eval('(function(){ with(this){'+script+'} })'); + } + +}); diff --git a/src/tanks/thing/index.cjs b/src/tanks/thing/index.cjs index 34bd5c2..43a7d85 100644 --- a/src/tanks/thing/index.cjs +++ b/src/tanks/thing/index.cjs @@ -1,5 +1,5 @@ -exports.Thing = require('tanks/thing/thing').Thing; -exports.Bullet = require('tanks/thing/bullet').Bullet; -exports.Tank = require('tanks/thing/tank').Tank; -exports.PlayerTank = require('tanks/thing/player').PlayerTank; - +exports['Thing'] = require('tanks/thing/thing').Thing; +exports['Bullet'] = require('tanks/thing/bullet').Bullet; +exports['Tank'] = require('tanks/thing/tank').Tank; +exports['PlayerTank'] = require('tanks/thing/player').PlayerTank; +// exports['CustomTank'] = require('tanks/thing/customtank').CustomTank; diff --git a/src/tanks/thing/player.cjs b/src/tanks/thing/player.cjs index 26d276c..7dd5775 100644 --- a/src/tanks/thing/player.cjs +++ b/src/tanks/thing/player.cjs @@ -1,6 +1,13 @@ +//@require('jquery') +//@require('jquery.hotkeys.min') -var PlayerTank = -exports.PlayerTank = +var Y = require('Y').Y +, Tank = require('tanks/thing/tank').Tank +, + + +PlayerTank = +exports['PlayerTank'] = Tank.subclass('PlayerTank', { bodyColor : '#E73075', @@ -172,10 +179,11 @@ Tank.subclass('PlayerTank', { this.rotateBarrelRelPage(evt.pageX, evt.pageY); } -}); - +}) +, -var Key = { +Key = +exports['Key'] = { fire : 32, _dirFromKey : { diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index 543d456..34c1644 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -1,11 +1,20 @@ -(function(){ +var Y = require('Y').Y +, Thing = require('tanks/thing/thing').Thing +, Bullet = require('tanks/thing/bullet').Bullet +, Trajectory = require('tanks/map/trajectory').Trajectory +, Vec = require('ezl/math/vec').Vec +, shape = require('ezl/shape') +, Rect = shape.Rect +, Circle = shape.Circle -var BULLET_MOVE_PER_FRAME = MS_PER_FRAME * Bullet.prototype.stats.move*REF_SIZE/1000 , isBullet = Y.is(Bullet) -; +, BULLET_MOVE_PER_FRAME = MS_PER_FRAME * Bullet.prototype.stats.move*REF_SIZE/1000 +, -Tank = Thing.subclass('Tank', { +Tank = +exports['Tank'] = +Thing.subclass('Tank', { projectile : Bullet, blocking : true, @@ -420,5 +429,3 @@ Tank = Thing.subclass('Tank', { }); - -})(); \ No newline at end of file diff --git a/src/tanks/thing/thing.cjs b/src/tanks/thing/thing.cjs index c29f1e0..d269d3f 100644 --- a/src/tanks/thing/thing.cjs +++ b/src/tanks/thing/thing.cjs @@ -1,11 +1,15 @@ -var loc = require('tanks/map/loc') -, Cooldown = require('ezl/loop/cooldown').Cooldown -, Loc = loc.Loc, BoundingBox = loc.BoundingBox -; +var Y = require('Y').Y +, Class = require('evt/class').Class -var Thing = -exports.Thing = -new Evt.Class('Thing', { +, Loc = require('ezl/loc/loc').Loc +, BoundingBox = require('ezl/loc/boundingbox').BoundingBox +, Cooldown = require('ezl/loop').Cooldown +, + + +Thing = +exports['Thing'] = +new Class('Thing', { init : function init(align){ this.id = Thing.THING_ID++; diff --git a/src/tanks/ui/config.cjs b/src/tanks/ui/config.cjs new file mode 100644 index 0000000..0c443d7 --- /dev/null +++ b/src/tanks/ui/config.cjs @@ -0,0 +1,88 @@ +//@require('jquery') + + +// TODO +// ==== +// - store at tanks.config.values, but clone at start to t.c.defaults +// - need Config class to run triggers on changes +// - button to clear saved config +// +// init +// - For each item in tanks.config (recursive): +// - Create a UI box based on type, with a name based on its dotted path +// - Check cookies -- fill it with the value from cookies or default +// +// update +// - For each config element: +// - Extract value, typecast based on default's type +// - If different from default, set cookie +// - Update tanks.config.values + +var Y = require('Y').Y +, config = require('tanks/config') +, c = config.values +, p = c.pathing +; + + + + +exports['init'] = function initConfigUi(){ + $('#config [name=pathmap]').attr('checked', p.overlayPathmap); + $('#config [name=aipaths]').attr('checked', p.overlayAIPaths); + $('#config [name=trajectories]').attr('checked', p.traceTrajectories); + + $('#config [name=gridCoords]').attr('checked', c.ui.showGridCoords); + $('#viewport .layer.grid')[(c.ui.showGridCoords ? 'add' : 'remove')+'Class']('showGridCoords'); +}; + +exports['update'] = function updateConfigUi(evt){ + p.overlayPathmap = $('#config [name=pathmap]').attr('checked'); + p.overlayAIPaths = $('#config [name=aipaths]').attr('checked'); + p.traceTrajectories = $('#config [name=trajectories]').attr('checked'); + + c.ui.showGridCoords = $('#config [name=gridCoords]').attr('checked'); + $('#viewport .layer.grid')[(c.ui.showGridCoords ? 'add' : 'remove')+'Class']('showGridCoords'); +}; + +// var templates = { +// 'label' : { html:'' }, +// 'input' : { html:'' }, +// 'text' : { include:'input', type:'text' }, +// 'checkbox' : { include:'input', type:'checkbox', props:{ 'checked':false } }, +// 'radio' : { include:'input', type:'radio' } +// // 'select' : '', +// // 'textarea' : '', +// // 'hidden' : '', +// // 'button' : '' +// }; +// +// var type2el = { +// 'Boolean' +// 'Number' : +// 'String' : 'text' +// // 'Array' +// // 'Date' +// // 'RegExp' +// // 'Function' +// // 'Object' +// }; +// exports['makeField'] = function makeField(key, value){ +// +// }; + +var upperPat = /^[A-Z]+$/ +, symbolPat = /^[^a-zA-Z]+$/ +; + +Y.YString.prototype.splitCamel = + function splitCamel(s){ + return this.reduce( + function(acc, ch, i){ + return acc + ( + symbolPat.test(ch) ? '' : + (upperPat.test(ch) ? ' '+ch : ch) ); + }, '') + .split(' '); + }; + diff --git a/src/tanks/ui/grid.cjs b/src/tanks/ui/grid.cjs index 55c391b..5183abf 100644 --- a/src/tanks/ui/grid.cjs +++ b/src/tanks/ui/grid.cjs @@ -1,4 +1,10 @@ -Grid = new Y.Class('Grid', Rect, { +var Y = require('Y').Y +, Rect = require('ezl/shape').Rect +, + +Grid = +exports['Grid'] = +Rect.subclass('Grid', { _cssClasses : 'ezl layer shape rect grid', lineWidth : 0.5, @@ -63,4 +69,4 @@ Grid = new Y.Class('Grid', Rect, { } } -}); \ No newline at end of file +}); diff --git a/src/tanks/ui/index.cjs b/src/tanks/ui/index.cjs index e69de29..9fe937d 100644 --- a/src/tanks/ui/index.cjs +++ b/src/tanks/ui/index.cjs @@ -0,0 +1,3 @@ +var Y = require('Y').Y; +Y.extend(exports, require('tanks/ui/config')); +exports['main'] = require('tanks/ui/main'); diff --git a/src/tanks/ui/main.cjs b/src/tanks/ui/main.cjs index 7f697b2..acdff0f 100644 --- a/src/tanks/ui/main.cjs +++ b/src/tanks/ui/main.cjs @@ -1,13 +1,21 @@ -(function(){ +//@require('jquery') +//@require('jquery.hotkeys.min') -jQuery(main); +var Y = require('Y').Y +, config = require('tanks/config') +, uiconfig = require('tanks/ui/config') +, Game = require('tanks/game').Game +, Tank = require('tanks/thing').Tank +, FpsSparkline = require('ezl/loop').FpsSparkline +; + +qkv = Y(window.location.search.slice(1)).fromKV().end(); -this.main = main; +jQuery(main); // Main method is only executed once, so we'll setup things // that don't change between games. function main(){ - qkv = Y(window.location.search.slice(1)).fromKV().end(); /// Debug /// if (qkv.ai) { @@ -19,7 +27,7 @@ function main(){ $('#ai .ready').bind('click', function(evt){ try { - var script = $('#custom-tank').val(); + var script = $('#customtank').val(); Tank.prototype.act = eval('(function(){ with(this){'+script+'} })'); $('#ai').hide(); startGame(); @@ -35,7 +43,7 @@ function main(){ $('#debug').bind('mousedown', Y.op.K(false)); // Update config when changed - $('#debug input').bind('change', tanks.ui.config.update); + $('#debug input').bind('change', uiconfig.update); // Create #pause box @@ -72,7 +80,7 @@ function gameExists(){ return !!tanks.currentGame; } function setupGame(){ if ( gameExists() ) teardownGame(); - LBT = tanks.currentGame = new tanks.Game(); + LBT = tanks.currentGame = new Game(); LBT.addEventListener('win', gameover('You Win!', 'Play Again', '')); LBT.addEventListener('lose', gameover('You Lose :(', 'Try Again', '')); @@ -92,7 +100,7 @@ function setupUI(){ if (!qkv.ai) $('#welcome').show(); LBT.loop.spark = new FpsSparkline(LBT.loop, '.fps-sparkline', 0,0); - tanks.ui.config.init(); + uiconfig.init(); LBT.root.draw(); // Start button (click or return key) @@ -124,8 +132,8 @@ function startGame(evt){ $('#welcome').hide(); - if ( tanks.config.values.ui.showCountdown ) - countdownToStart(3, readyToStart); + if ( config.values.ui.showCountdown ) + countdown(3, readyToStart); else readyToStart(); } @@ -165,7 +173,7 @@ function gameover(headline, button, body, evt){ gameover = Y(gameover).curry(); -function countdownToStart(n, fn){ +function countdown(n, fn){ var el , showFor = 750 , pauseFor = 500 @@ -245,6 +253,19 @@ function updateInfo(){ } - -}).call(tanks.ui); +exports['main'] = main; +exports['gameExists'] = gameExists; +exports['setupGame'] = setupGame; +exports['teardownGame'] = teardownGame; +exports['setupUI'] = setupUI; +exports['teardownUI'] = teardownUI; +exports['startGame'] = startGame; +exports['pauseGame'] = pauseGame; +exports['toggleGame'] = toggleGame; +exports['resizeGame'] = resizeGame; +exports['gameover'] = gameover; +exports['countdown'] = countdown; +exports['tickDown'] = tickDown; +exports['readyToStart'] = readyToStart; +exports['updateInfo'] = updateInfo; diff --git a/src/tanks/ui/ui-config.cjs b/src/tanks/ui/ui-config.cjs deleted file mode 100644 index c32d26b..0000000 --- a/src/tanks/ui/ui-config.cjs +++ /dev/null @@ -1,90 +0,0 @@ -(function(){ - -// TODO -// ==== -// - store at tanks.config.values, but clone at start to t.c.defaults -// - need Config class to run triggers on changes -// - button to clear saved config -// -// init -// - For each item in tanks.config (recursive): -// - Create a UI box based on type, with a name based on its dotted path -// - Check cookies -- fill it with the value from cookies or default -// -// update -// - For each config element: -// - Extract value, typecast based on default's type -// - If different from default, set cookie -// - Update tanks.config.values - - -var ns = tanks.ui.config = {} -, c = tanks.config.values -, p = c.pathing -; - - - - -ns.init = function initConfigUi(){ - $('#config [name=pathmap]').attr('checked', p.overlayPathmap); - $('#config [name=aipaths]').attr('checked', p.overlayAIPaths); - $('#config [name=trajectories]').attr('checked', p.traceTrajectories); - - $('#config [name=gridCoords]').attr('checked', c.ui.showGridCoords); - $('#viewport .layer.grid')[(c.ui.showGridCoords ? 'add' : 'remove')+'Class']('showGridCoords'); -}; - -ns.update = function updateConfigUi(evt){ - p.overlayPathmap = $('#config [name=pathmap]').attr('checked'); - p.overlayAIPaths = $('#config [name=aipaths]').attr('checked'); - p.traceTrajectories = $('#config [name=trajectories]').attr('checked'); - - c.ui.showGridCoords = $('#config [name=gridCoords]').attr('checked'); - $('#viewport .layer.grid')[(c.ui.showGridCoords ? 'add' : 'remove')+'Class']('showGridCoords'); -}; - -// var templates = { -// 'label' : { html:'' }, -// 'input' : { html:'' }, -// 'text' : { include:'input', type:'text' }, -// 'checkbox' : { include:'input', type:'checkbox', props:{ 'checked':false } }, -// 'radio' : { include:'input', type:'radio' } -// // 'select' : '', -// // 'textarea' : '', -// // 'hidden' : '', -// // 'button' : '' -// }; -// -// var type2el = { -// 'Boolean' -// 'Number' : -// 'String' : 'text' -// // 'Array' -// // 'Date' -// // 'RegExp' -// // 'Function' -// // 'Object' -// }; -// ns.makeField = function makeField(key, value){ -// -// }; - -var upperPat = /^[A-Z]+$/ -, symbolPat = /^[^a-zA-Z]+$/ -; - -Y.YString.prototype.splitCamel = - function splitCamel(s){ - return this.reduce( - function(acc, ch, i){ - return acc + ( - symbolPat.test(ch) ? '' : - (upperPat.test(ch) ? ' '+ch : ch) ); - }, '') - .split(' '); - }; - - - -})(); diff --git a/src/tanks/ui/ui.cjs b/src/tanks/ui/ui.cjs deleted file mode 100644 index a1ca700..0000000 --- a/src/tanks/ui/ui.cjs +++ /dev/null @@ -1 +0,0 @@ -tanks.ui = {}; diff --git a/src/tanks/util/config.cjs b/src/tanks/util/config.cjs index 822e579..f4b319d 100644 --- a/src/tanks/util/config.cjs +++ b/src/tanks/util/config.cjs @@ -1,11 +1,18 @@ -Config = Y.YObject.subclass('Config', function(){ +var Y = require('Y').Y +, Emitter = require('Y/modules/y.event').Emitter +, + + +Config = +exports.Config = +Y.YObject.subclass('Config', function(){ Y.op.extend(this, { init : function initConfig(defaults){ this._defaults = defaults; this._o = Y({}, defaults); - this.__emitter__ = new Y.event.Emitter(this); + this.__emitter__ = new Emitter(this); }, set : function set(key, value, def){ @@ -90,4 +97,4 @@ Config = Y.YObject.subclass('Config', function(){ }); -}); \ No newline at end of file +}); diff --git a/tags.php b/tags.php new file mode 100644 index 0000000..f9e48c9 --- /dev/null +++ b/tags.php @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tanks.php b/tanks.php index e88b37d..da77d84 100644 --- a/tanks.php +++ b/tanks.php @@ -12,7 +12,8 @@ class Tanks { const BUILD_DIR = "build"; static $modules = array( - array( "main" => "src/Y/index.cjs", "loader" => "y-loader.js" ) + // array( "main" => "src/Y/index.cjs", "loader" => "y-loader.js" ) + array( "main" => "src/tanks/index.cjs", "loader" => "tanks-loader.js" ) ); @@ -32,7 +33,7 @@ class Tanks { "src/tanks/thing/thing.js", "src/tanks/thing/bullet.js", "src/tanks/thing/tank.js", - "src/tanks/thing/custom-tank.js", + "src/tanks/thing/customtank.js", "src/tanks/thing/player.js", "src/tanks/map/loc.js", @@ -42,7 +43,7 @@ class Tanks { "src/tanks/ui/ui.js", "src/tanks/ui/grid.js", - "src/tanks/ui/ui-config.js", + "src/tanks/ui/config.js", "src/tanks/game.js" ); @@ -102,13 +103,14 @@ class Tanks { static function compile($modules=null) { $modules = ($modules ? $modules : self::$modules); $PYTHONPATH = "PYTHONPATH='/Users/dsc/.python/lib/python:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.6/site-packages'"; - // error_reporting(E_ALL); - // echo ""; + echo "-->"; + include "tags.php"; } static function writeLoaders($modules=null, $recompile=true){ -- 1.7.0.4