From 074eb4119876a0e8cd44f1ce5a1e485c7fb5b95c Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 17 Jan 2011 01:41:03 -0800 Subject: [PATCH] Fixes direction of cooldown animation --- data/types/items.yaml | 6 +- src/ezl/index.cjs | 1 + src/ezl/mixins/index.cjs | 4 + src/ezl/mixins/speciated.cjs | 135 +++++++++++++++++++++++++++++++++++ src/ezl/util/data/datafile.cjs | 23 +------ src/ezl/widget/cooldown.cjs | 4 +- src/tanks/effects/buff.cjs | 2 +- src/tanks/game.cjs | 8 -- src/tanks/map/level.cjs | 2 +- src/tanks/mixins/index.cjs | 1 - src/tanks/mixins/speciated.cjs | 97 ------------------------- src/tanks/thing/thing.cjs | 2 +- src/tanks/ui/inventory/backpack.cjs | 3 +- src/tanks/ui/main.cjs | 6 +- 14 files changed, 155 insertions(+), 139 deletions(-) create mode 100644 src/ezl/mixins/index.cjs create mode 100644 src/ezl/mixins/speciated.cjs delete mode 100644 src/tanks/mixins/speciated.cjs diff --git a/data/types/items.yaml b/data/types/items.yaml index 90e0e87..9b2505e 100644 --- a/data/types/items.yaml +++ b/data/types/items.yaml @@ -7,9 +7,9 @@ types: desc: Speeds up your tank temporarily. tags: [ 'movement' ] passives: [] - effects: [ 'speedup' ] - # effects: - # - include: speedup + # effects: [ 'speedup' ] + effects: + - include: tanks/effects/buff.Buff:speedup cooldowns: activate: 30.0 art: diff --git a/src/ezl/index.cjs b/src/ezl/index.cjs index 112295b..bca3143 100644 --- a/src/ezl/index.cjs +++ b/src/ezl/index.cjs @@ -8,6 +8,7 @@ var Y = require('Y').Y; Y.extend(exports, { 'math' : require('ezl/math'), 'loc' : require('ezl/loc'), + 'mixins' : require('ezl/mixins'), 'util' : require('ezl/util'), 'loop' : require('ezl/loop'), diff --git a/src/ezl/mixins/index.cjs b/src/ezl/mixins/index.cjs new file mode 100644 index 0000000..51f696d --- /dev/null +++ b/src/ezl/mixins/index.cjs @@ -0,0 +1,4 @@ +require('Y').Y.core +.extend(exports, { + 'Speciated' : require('ezl/mixins/speciated').Speciated +}); \ No newline at end of file diff --git a/src/ezl/mixins/speciated.cjs b/src/ezl/mixins/speciated.cjs new file mode 100644 index 0000000..13357f3 --- /dev/null +++ b/src/ezl/mixins/speciated.cjs @@ -0,0 +1,135 @@ +var Y = require('Y').Y +, getNested = require('Y/types/object').getNested +, deepcopy = require('Y/types/object').deepcopy +, Mixin = require('evt').Mixin +, + +resolve = +exports['resolve'] = +function resolve(spec){ + var idx = spec.indexOf('.') + , modName = spec.slice(0, idx !== -1 ? idx : spec.length) + , objName = spec.slice(idx+1) + , module, speciesName, symbol ; + + if (idx === 0) { + module = window; + objName = spec.slice(1); + } else + module = require(modName); + + idx = objName.indexOf(':'); + if (idx !== -1) { + speciesName = objName.slice(idx+1); + objName = objName.slice(0, idx); + } + + if (!objName) + this.die('Cannot resolve symbol: '+spec); + + symbol = getNested(module, objName) + if (!symbol) + this.die('Unable to locate class specified by symbol (symbol="'+spec+'", module='+module+', object="'+objName+'" --> '+symbol+')!'); + + if (speciesName) { + symbol = symbol.lookup(speciesName); + if (!symbol) this.die('Unable to locate species specified by symbol (symbol="'+spec+'", module='+module+', object="'+objName+'", species="'+speciesName+'" --> '+symbol+')!'); + } + + return symbol; +} +, + + +Speciated = +exports['Speciated'] = +Mixin.subclass('Speciated', { + name : "", + desc : "", + tags : [], + + __static__ : { + __species_id__ : 0, + + id2name : function id2name(id){ + if (typeof id === 'number') + return this.className+id; + var name = id+''; + // TODO: all YString methods to return YString :P But it'll proally break shit + name = Y(name).capitalize(); + name = Y(name).snakeToCamel(); + return name+this.className; + }, + + register : function register(id, cls){ + id = (id+'').toLowerCase(); + if ( this.__known__[id] ) + throw new Error('A species of '+this.className+' already exists with the id '+id+'!'); + this.__known__[id] = cls; + return cls; + }, + + speciate : function speciate(id, props){ + if ( arguments.length === 1 ) { + props = id; + id = this.__species_id__++; + } + + if ( this.__known__[id] ) + throw new Error('A species of '+this.className+' already exists with the id '+id+'!'); + + props = props || {}; + props.__species__ = id; + + if (props.include) { + var parent = resolve(props.include); + props = deepcopy(Y.extend({}, parent.__species_props__, props)); + delete props.include; + } + + var cls = this + , speciesName = this.id2name(id) + , Species = this.__known__[id] = cls.subclass(speciesName, props) + ; + Species.__species_props__ = props; + + cls.fire('speciate', Species, { 'id':id, 'species':Species, 'cls':cls }); + return Species; + }, + + lookup : function lookup(id){ + id = (id+'').toLowerCase(); + return this.__known__[id]; + }, + + lookupOrSpeciate : function lookupOrSpeciate(id){ + if ( Y.isPlainObject(id) ) + return this.speciate(id); + else + return this.lookup(id+''); + }, + + create : function create(id){ + var args = Y(arguments,1) + , Species = this.lookup(id); + if (!Species) + throw new Error('Unknown Species of '+this.className+' with id "'+id+'"!'); + return Species.instantiate.apply(Species, args); + }, + + createApply : function createApply(id, args){ + return this.create.apply(this, [id].concat(args)); + } + + }, + + onMixin : function mixSpeciated(evt){ + var cls = evt.data.cls; + cls.__known__ = {}; + }, + + toString : function(){ + return this.className+'(name='+this.name+', id='+this.__id__+', tags=['+this.tags+'])'; + } + +}); diff --git a/src/ezl/util/data/datafile.cjs b/src/ezl/util/data/datafile.cjs index 699ddf4..093afb4 100644 --- a/src/ezl/util/data/datafile.cjs +++ b/src/ezl/util/data/datafile.cjs @@ -3,6 +3,7 @@ var Y = require('Y').Y , evt = require('evt') , getNested = require('Y/types/object').getNested , deepcopy = require('Y/types/object').deepcopy +, resolve = require('ezl/mixins/speciated').resolve , @@ -25,26 +26,6 @@ new evt.Class('DataFile', { return this; }, - resolve : function resolve(spec){ - var nameParts = spec.split('.') - , modName = nameParts.shift() - , module ; - - if (!modName) - module = window; - else - module = require(modName); - - if (!nameParts.length) - this.die('Cannot resolve symbol: '+spec); - - var symbol = getNested(module, nameParts) - if (!symbol) - this.die('Unable to locate class specified by symbol (symbol="'+spec+'", module='+module+' --> '+symbol+')!'); - - return symbol; - }, - process : function process(data){ this.data = data; this.fire('process', data); @@ -64,7 +45,7 @@ new evt.Class('DataFile', { this.die('No symbol defined for type "'+id+'" at '+this.path+'!'); delete props.symbol; - var base = this.resolve(symbol); + var base = resolve(symbol); if (!Y.isFunction(base.speciate)) this.die('Cannot create types from data (symbol-class '+base+' from "'+symbol+'" is not Speciated)!'); diff --git a/src/ezl/widget/cooldown.cjs b/src/ezl/widget/cooldown.cjs index d7429a4..61e1c0b 100644 --- a/src/ezl/widget/cooldown.cjs +++ b/src/ezl/widget/cooldown.cjs @@ -46,9 +46,9 @@ Layer.subclass('CooldownGauge', function setupCooldownGauge(CooldownGauge){ var p = cool.ratio() , w = this.layerWidth, h = this.layerHeight , x = w*0.5, y = h*0.5 - , amt = -HALF_PI + (1 - p)*TWO_PI; + , amt = p*TWO_PI - HALF_PI; - ctx.arc(x,y, w, -HALF_PI, amt, false); + ctx.arc(x,y, w, -HALF_PI, amt, true); ctx.lineTo(x,y); ctx.lineTo(x,0); ctx.fill(); diff --git a/src/tanks/effects/buff.cjs b/src/tanks/effects/buff.cjs index 0841194..cd8b6e4 100644 --- a/src/tanks/effects/buff.cjs +++ b/src/tanks/effects/buff.cjs @@ -2,7 +2,7 @@ var Y = require('Y').Y , evt = require('evt') , mul = Y.op.curried.mul -, Speciated = require('tanks/mixins/speciated').Speciated +, Speciated = require('ezl/mixins/speciated').Speciated , Meronomic = require('tanks/mixins/meronomic').Meronomic , Quantified = require('tanks/mixins/quantified').Quantified , diff --git a/src/tanks/game.cjs b/src/tanks/game.cjs index 08c7d0a..5fea328 100644 --- a/src/tanks/game.cjs +++ b/src/tanks/game.cjs @@ -48,19 +48,15 @@ Y.subclass('Game', { this.bullets = new Y.YArray(); this.animations = new Y.YArray(); - // this.el = $(GAME_ELEMENT); this.loop = new EventLoop(FRAME_RATE, this); this.root = new Layer({ hasCanvas:false }, { 'id':'game' }) .prependTo( $('body') ); - // this.root.shape.remove(); - // this.root.layer.attr('id', 'viewport'); this.viewport = new Layer({ hasCanvas:false }, { 'id':'viewport' }) .appendTo( this.root ); - this.level = Level.create(this.levelId, this, CAPACITY, REF_SIZE) .appendTo( this.viewport ); @@ -98,7 +94,6 @@ Y.subclass('Game', { Thing.removeEventListener('created', this.addUnit); Thing.removeEventListener('destroy', this.killUnit); this.root.remove(); - // this.backpack && this.backpack.remove(); this.stop(); this.resetGlobals(); }, @@ -111,9 +106,6 @@ Y.subclass('Game', { SQUARETH = REF_SIZE * SECONDTH; }, - // get width(){ return this.level.width; }, - // get height(){ return this.level.height; }, - draw : function draw(){ this.root.draw(); // this.backpack.draw(); diff --git a/src/tanks/map/level.cjs b/src/tanks/map/level.cjs index 21944c9..1093e53 100644 --- a/src/tanks/map/level.cjs +++ b/src/tanks/map/level.cjs @@ -11,7 +11,7 @@ var Y = require('Y').Y , Item = require('tanks/thing/item').Item , Player = require('tanks/thing/player').Player , Wall = require('tanks/map/wall').Wall -, Speciated = require('tanks/mixins/speciated').Speciated +, Speciated = require('ezl/mixins/speciated').Speciated , min = Y(Math.min).limit(2) , max = Y(Math.max).limit(2) diff --git a/src/tanks/mixins/index.cjs b/src/tanks/mixins/index.cjs index ea351cc..efdab04 100644 --- a/src/tanks/mixins/index.cjs +++ b/src/tanks/mixins/index.cjs @@ -1,6 +1,5 @@ require('Y').Y.core .extend(exports, { - 'Speciated' : require('tanks/mixins/speciated').Speciated, 'Meronomic' : require('tanks/mixins/meronomic').Meronomic, 'Quantified' : require('tanks/mixins/quantified').Quantified, 'Inventoried' : require('tanks/mixins/inventoried').Inventoried diff --git a/src/tanks/mixins/speciated.cjs b/src/tanks/mixins/speciated.cjs deleted file mode 100644 index c204417..0000000 --- a/src/tanks/mixins/speciated.cjs +++ /dev/null @@ -1,97 +0,0 @@ -var Y = require('Y').Y -, deepcopy = require('Y/types/object').deepcopy -, Mixin = require('evt').Mixin -, - -Speciated = -exports['Speciated'] = -Mixin.subclass('Speciated', { - name : "", - desc : "", - tags : [], - - __static__ : { - __species_id__ : 0, - - id2name : function id2name(id){ - if (typeof id === 'number') - return this.className+id; - var name = id+''; - // TODO: all YString methods to return YString :P But it'll proally break shit - name = Y(name).capitalize(); - name = Y(name).snakeToCamel(); - return name+this.className; - }, - - register : function register(id, cls){ - id = (id+'').toLowerCase(); - if ( this.__known__[id] ) - throw new Error('A species of '+this.className+' already exists with the id '+id+'!'); - this.__known__[id] = cls; - return cls; - }, - - speciate : function speciate(id, props){ - if ( arguments.length === 1 ) { - props = id; - id = this.__species_id__++; - } - - if ( this.__known__[id] ) - throw new Error('A species of '+this.className+' already exists with the id '+id+'!'); - - props = props || {}; - props.__species__ = id; - - if (props.include) { - var parent = this.lookup(props.inherit); - props = deepcopy(Y.extend({}, parent.__species_props__, props)); - delete props.include; - } - - var cls = this - , speciesName = this.id2name(id) - , Species = this.__known__[id] = cls.subclass(speciesName, props) - ; - Species.__species_props__ = props; - - cls.fire('speciate', Species, { 'id':id, 'species':Species, 'cls':cls }); - return Species; - }, - - lookup : function lookup(id){ - id = (id+'').toLowerCase(); - return this.__known__[id]; - }, - - lookupOrSpeciate : function lookupOrSpeciate(id){ - if ( Y.isPlainObject(id) ) - return this.speciate(id); - else - return this.lookup(id+''); - }, - - create : function create(id){ - var args = Y(arguments,1) - , Species = this.lookup(id); - if (!Species) - throw new Error('Unknown Species of '+this.className+' with id "'+id+'"!'); - return Species.instantiate.apply(Species, args); - }, - - createApply : function createApply(id, args){ - return this.create.apply(this, [id].concat(args)); - } - - }, - - onMixin : function mixSpeciated(evt){ - var cls = evt.data.cls; - cls.__known__ = {}; - }, - - toString : function(){ - return this.className+'(name='+this.name+', id='+this.__id__+', tags=['+this.tags+'])'; - } - -}); diff --git a/src/tanks/thing/thing.cjs b/src/tanks/thing/thing.cjs index e184dc3..1e4f577 100644 --- a/src/tanks/thing/thing.cjs +++ b/src/tanks/thing/thing.cjs @@ -14,7 +14,7 @@ var Y = require('Y').Y , DensityType = constants.DensityType , stat = require('tanks/effects/stat') , Quantified = require('tanks/mixins/quantified').Quantified -, Speciated = require('tanks/mixins/speciated').Speciated +, Speciated = require('ezl/mixins/speciated').Speciated , diff --git a/src/tanks/ui/inventory/backpack.cjs b/src/tanks/ui/inventory/backpack.cjs index 44be452..e62271c 100644 --- a/src/tanks/ui/inventory/backpack.cjs +++ b/src/tanks/ui/inventory/backpack.cjs @@ -102,7 +102,6 @@ Layer.subclass('BackpackSlot', { this.layer.bind('click', this.onActivate); this.inner.append(item.activateGauge); - // item.activateGauge.draw(); return this; }, @@ -117,7 +116,7 @@ Layer.subclass('BackpackSlot', { }, onActivate : function onActivate(evt){ - console.log(this+'.onActivate()!'); + // console.log(this+'.onActivate()!'); this.item.activate(); }, diff --git a/src/tanks/ui/main.cjs b/src/tanks/ui/main.cjs index d1994d6..a2fbafb 100644 --- a/src/tanks/ui/main.cjs +++ b/src/tanks/ui/main.cjs @@ -25,6 +25,8 @@ function stopProp(evt){ evt.stopPropagation(); } qkv = Y(window.location.search.slice(1)).fromKV(); hkv = Y(window.location.hash.slice(1)).fromKV(); + + // Main method is only executed once, so we'll setup things // that don't change between games. function main(){ @@ -201,8 +203,8 @@ gameover = Y(gameover).curry(); function countdown(n, fn){ var el - , showFor = 750 - , pauseFor = 500 + , showFor = 550 + , pauseFor = 400 , body = $('body') , sizeRatio = 0.6 -- 1.7.0.4