Created
October 14, 2014 04:48
-
-
Save FatalCatharsis/989734c390de8a61e853 to your computer and use it in GitHub Desktop.
Plugin (super alpha)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
###* | |
# @ngdoc service | |
# @name webvisApp.droids | |
# @description | |
# # droids | |
# Service in the webvisApp. | |
### | |
webvisApp = angular.module('webvisApp') | |
webvisApp.service 'Plugin', (PluginBase)-> | |
class Droids extends PluginBase.BasePlugin | |
webvisApp.parser = {} | |
webvisApp.parser.SPAWN = 0 | |
webvisApp.parser.REPAIR = 1 | |
webvisApp.parser.MOVE = 2 | |
webvisApp.parser.HACK = 3 | |
webvisApp.parser.ORBITALDROP = 4 | |
webvisApp.parser.ATTACK = 5 | |
webvisApp.parser.Player = class Player | |
constructor: () -> | |
@id = null | |
@playerName = null | |
@time = null | |
@scrapAmount = null | |
webvisApp.parser.Mappable = class Mappable | |
constructor: () -> | |
@id = null | |
@x = null | |
@y = null | |
webvisApp.parser.Droid = class Droid extends Mappable | |
constructor: () -> | |
@owner = null | |
@variant = null | |
@attacksLeft = null | |
@maxAttacks = null | |
@healthLeft = null | |
@maxHealth = null | |
@maxMovement = null | |
@range = null | |
@attack = null | |
@armor = null | |
@maxArmor = null | |
@scrapWorth = null | |
@turnsToBeHacked = null | |
@hackedTurnsLeft = null | |
@hackets = null | |
@hacketsMax = null | |
webvisApp.parser.Tile = class Tile extends Mappable | |
constructor: () -> | |
@owner = null | |
@turnsUntilAssembled = null | |
@variantToAssemble = null | |
webvisApp.parser.ModelVariant = class ModelVariant | |
constructor: () -> | |
@id = null | |
@name = null | |
@variant = null | |
@cost = null | |
@maxAttacks = null | |
@maxHealth = null | |
@maxMovement = null | |
@range = null | |
@attack = null | |
@maxArmor = null | |
@scrapWorth = null | |
@turnsToBeHacked = null | |
@hacketsMax = null | |
webvisApp.parser.Animation = class Animation | |
constructor: () -> | |
@id = null | |
webvisApp.parser.Spawn = class Spawn extends Animation | |
constructor: () -> | |
@sourceID = null | |
@unitID = null | |
webvisApp.parser.Repair = class Repair extends Animation | |
constructor: () -> | |
@actingID = null | |
@targetID = null | |
webvisApp.parser.Move = class Move extends Animation | |
constructor: () -> | |
@actingID = null | |
@fromX = null | |
@fromY = null | |
@toX = null | |
@toY = null | |
webvisApp.parser.Hack = class Hack extends Animation | |
constructor: () -> | |
@actingID = null | |
@targetID = null | |
webvisApp.parser.OrbitalDrop = class OrbitalDrop extends Animation | |
constructor: () -> | |
@sourceID = null | |
webvisApp.parser.Attack = class Attack extends Animation | |
constructor: () -> | |
@actingID = null | |
@targetID = null | |
webvisApp.parser.AnimOwner = class AnimOwner extends Animation | |
constructor: () -> | |
@owner = null | |
webvisApp.parser.GameState = class GameState | |
constructor: () -> | |
@players = {} | |
@mappables = {} | |
@droids = {} | |
@tiles = {} | |
@modelVariants = {} | |
@animations = {} | |
@mapWidth = null | |
@mapHeight = null | |
@turnNumber = null | |
@maxDroids = null | |
@playerID = null | |
@gameNumber = null | |
@scrapRate = null | |
@maxScrap = null | |
@dropTime = null | |
webvisApp.parser.Game = class Game | |
constructor: () -> | |
@states = [] | |
@gameID = null | |
@gameName = null | |
@result = null | |
webvisApp.service 'Plugin', ($log, Parser, PluginBase)-> | |
class Droid extends PluginBase.BaseEntity | |
constructor: () -> | |
@animations = [] | |
@texture = null | |
@sprite = null | |
@gridPos = {x:0, y:0} | |
setX: (x) -> | |
@gridPos.x = x | |
@sprite.position.x = | |
(x/@game.states[0].mapWidth) * Plugin.getWidth() | |
setY: (y) -> | |
@gridPos.y = y | |
@sprite.position.y = | |
(y/@game.states[0].mapHeight) * Plugin.getHeight() | |
x: (x) -> @gridPos.x | |
y: (y) -> @gridPos.y | |
resize: () -> | |
@sprite.position.x = | |
x/@game.states[0].mapWidth * Game.getWidth() | |
@sprite.position.y = | |
y/@game.states[0].mapHeight * Game.getHeight() | |
getSprite: () -> @sprite | |
getAnimations: () => @animations | |
class Droids extends PluginBase.BasePlugin | |
constructor: () -> | |
@width = 0 | |
@height = 0 | |
@game = null | |
@entities = {} | |
setDimensions: (width, height) -> | |
@width = width | |
@height = height | |
parse: (logfile) -> | |
$log.info "wakka" | |
gamelog = Parser.SexpParser.parse logfile | |
@game = @createGameData gamelog | |
#@createGame() | |
return @game | |
getName: () -> "Droids" | |
getMaxTurns: () -> @game.states.length | |
getEntities: () -> @entities | |
createGame: () -> | |
for state in @game.states | |
for id, droid of state.droids | |
if !@entities[id]? | |
@entities[id] = new Droid | |
switch droid.variant | |
when "hacker" | |
@entities.texture = | |
new PIXI.Texture("images/hacker.png") | |
when "claw" | |
@entities.texture = | |
new PIXI.Texture("images/claw.png") | |
when "archer" | |
@entities.texture = | |
new PIXI.Texture("images/archer.png") | |
when "repairer" | |
@entities.texture = | |
new PIXI.Texture("images/welder.png") | |
when "turret" | |
@entities.texture = | |
new PIXI.Texture("images/turret.png") | |
when "terminator" | |
@entities.texture = | |
new PIXI.Texture("images/terminator.png") | |
when "hangar" | |
@entities.texture = | |
new PIXI.Texture("images/hub.png") | |
when "wall" | |
@entities.texture = | |
new PIXI.Texture("images/wall.png") | |
@entities[id].sprite = | |
new PIXI.Sprite(@entities[id].texture) | |
@entities[id].setX(droid.x) | |
@entities[id].setY(droid.y) | |
@addAnimations state, droid | |
addAnimations: (state, droid) -> | |
index = state.turnNumber | |
droidRef = state[index].droids[droid.id] | |
while state[index].droids[droid.id]? | |
if state[index].animations[droid.id]? | |
for anim in state[index].animations[droid.id] | |
@entities[droid.id].push createAnim | |
createAnim: () -> | |
a = null | |
switch anim.type | |
when webvisApp.parser.SPAWN | |
if droid.variant != "hangar" | |
a = new PluginBase.Animation state-1,state, | |
(turn, progress) => | |
curPosX = droid.x - (3*(1-progress)) | |
curPosY = droid.y - (droid.y - -1)*progress | |
@entities[droid.id].setX(curPosX) | |
@entities[droid.id].setY(curPosY) | |
#when webvisApp.parser.REPAIR | |
#not implemented | |
#when webvisApp.parser.MOVE | |
#not implemented | |
#when webvisApp.parser.HACK | |
#not implemented | |
#when webvisApp.parser.ORBITALDROP | |
#not implemented | |
#when webvisApp.parser.ATTACK | |
#not implemented | |
return a | |
createGameData: (gamelog) -> | |
GameData = new webvisApp.parser.Game | |
GameData.gameID = gamelog.gameID | |
GameData.gameName = gamelog.gameName | |
GameData.result = gamelog.result | |
for turn in gamelog.turns | |
state = @parseGame turn.status.game[0][1..] | |
if turn.status.Droid? | |
for d in turn.status.Droid | |
state.droids[d[0]] = @parseDroid d | |
if turn.status.ModelVariant? | |
for m in turn.status.ModelVariant | |
state.modelVariants[m[0]] = @parseModelVariant m | |
if turn.status.Mappable? | |
for a in turn.status.Mappable | |
state.mappables[a[0]] = @parseMappable m | |
if turn.status.Player? | |
for p in turn.status.Player | |
state.players[p[0]] = @parsePlayer p | |
if turn.status.Tile? | |
for t in turn.status.Tile | |
state.tiles[t[0]] = @parseTile t | |
if turn.animations? | |
for anim in turn.animations | |
switch anim[0] | |
when "add" | |
state.animations[anim[1]] = @parseSpawn anim | |
when "repair" | |
state.animations[anim[1]] = @parseRepair anim | |
when "move" | |
state.animations[anim[1]] = @parseMove anim | |
when "hack" | |
state.animations[anim[1]] = @parseHack anim | |
when "orbitalDrop" | |
state.animations[anim[1]] = | |
@parseOrbitalDrop anim | |
when "attack" | |
state.animations[anim[1]] = @parseAttack anim | |
GameData.states.push state | |
return GameData | |
parseGame: (elements) -> | |
gamedata = new webvisApp.parser.GameState | |
gamedata.mapWidth = elements[0] | |
gamedata.mapHeight = elements[1] | |
gamedata.turnNumber = elements[2] | |
gamedata.maxDroids = elements[3] | |
gamedata.playerID = elements[4] | |
gamedata.gameNumber = elements[5] | |
gamedata.scrapRate = elements[6] | |
gamedata.maxScrap = elements[7] | |
gamedata.dropTime = elements[8] | |
return gamedata | |
#models | |
parsePlayer: (elements) -> | |
player = new webvisApp.parser.Player | |
player.id = elements[0] | |
player.playerName = elements[1] | |
player.time = elements[2] | |
player.scrapAmount = elements[3] | |
return player | |
parseMappable: (elements) -> | |
mappable = new webvisApp.parser.Mappable | |
mappable.id = elements[0] | |
mappable.x = elements[1] | |
mappable.y = elements[2] | |
return mappable | |
parseDroid: (elements) -> | |
droid = new webvisApp.parser.Droid | |
droid.id = elements[0] | |
droid.x = elements[1] | |
droid.y = elements[2] | |
droid.owner = elements[3] | |
droid.variant = elements[4] | |
droid.attacksLeft = elements[5] | |
droid.maxAttacks = elements[6] | |
droid.healthLeft = elements[7] | |
droid.maxHealth = elements[8] | |
droid.movementLeft = elements[9] | |
droid.maxMovement = elements[10] | |
droid.range = elements[11] | |
droid.attack = elements[12] | |
droid.armor = elements[13] | |
droid.maxArmor = elements[14] | |
droid.scrapWorth = elements[15] | |
droid.turnsToBeHacked = elements[16] | |
droid.hackedTurnsLeft = elements[17] | |
droid.hackets = elements[18] | |
droid.hacketsMax = elements[19] | |
return droid | |
webvisApp.service 'Plugin', (Parser, PluginBase)-> | |
class Droid extends PluginBase.BaseEntity | |
constructor: () -> | |
@animations = [] | |
@texture = null | |
@gridLoc = {x:0, y:0} | |
getSprite: () -> @sprite | |
getAnimations: () => @animations | |
class Droids extends PluginBase.BasePlugin | |
constructor: () -> | |
@game = null | |
@entities = null | |
parse: (logfile) -> | |
gamelog = Parser.SexpParser.parse logfile | |
@game = @createGameData gamelog | |
@createGame() | |
return @game | |
getName: () -> "Droids" | |
getMaxTurns: () -> | |
getEntities: () -> @entities | |
createGame: () -> | |
#To be implemented | |
createGameData: (gamelog) -> | |
GameData = new webvisApp.parser.Game | |
GameData.gameID = gamelog.gameID | |
GameData.gameName = gamelog.gameName | |
GameData.result = gamelog.result | |
for turn in gamelog.turns | |
state = @parseGame turn.status.game[0][1..] | |
if turn.status.Droid? | |
for d in turn.status.Droid | |
state.droids[d[0]] = @parseDroid d | |
if turn.status.ModelVariant? | |
for m in turn.status.ModelVariant | |
state.modelVariants[m[0]] = @parseModelVariant m | |
if turn.status.Mappable? | |
for a in turn.status.Mappable | |
state.mappables[a[0]] = @parseMappable m | |
if turn.status.Player? | |
for p in turn.status.Player | |
state.players[p[0]] = @parsePlayer p | |
if turn.status.Tile? | |
for t in turn.status.Tile | |
state.tiles[t[0]] = @parseTile t | |
if turn.animations? | |
for anim in turn.animations | |
switch anim[0] | |
when "add" | |
state.animations[anim[1]] = @parseSpawn anim | |
when "repair" | |
state.animations[anim[1]] = @parseRepair anim | |
when "move" | |
state.animations[anim[1]] = @parseMove anim | |
when "hack" | |
state.animations[anim[1]] = @parseHack anim | |
when "orbitalDrop" | |
state.animations[anim[1]] = | |
@parseOrbitalDrop anim | |
when "attack" | |
state.animations[anim[1]] = @parseAttack anim | |
GameData.states.push state | |
return GameData | |
parseGame: (elements) -> | |
gamedata = new webvisApp.parser.GameState | |
gamedata.mapWidth = elements[0] | |
gamedata.mapHeight = elements[1] | |
gamedata.turnNumber = elements[2] | |
gamedata.maxDroids = elements[3] | |
gamedata.playerID = elements[4] | |
gamedata.gameNumber = elements[5] | |
gamedata.scrapRate = elements[6] | |
gamedata.maxScrap = elements[7] | |
gamedata.dropTime = elements[8] | |
return gamedata | |
#models | |
parsePlayer: (elements) -> | |
player = new webvisApp.parser.Player | |
player.id = elements[0] | |
player.playerName = elements[1] | |
player.time = elements[2] | |
player.scrapAmount = elements[3] | |
return player | |
parseMappable: (elements) -> | |
mappable = new webvisApp.parser.Mappable | |
mappable.id = elements[0] | |
mappable.x = elements[1] | |
mappable.y = elements[2] | |
return mappable | |
parseDroid: (elements) -> | |
droid = new webvisApp.parser.Droid | |
droid.id = elements[0] | |
droid.x = elements[1] | |
droid.y = elements[2] | |
droid.owner = elements[3] | |
droid.variant = elements[4] | |
droid.attacksLeft = elements[5] | |
droid.maxAttacks = elements[6] | |
droid.healthLeft = elements[7] | |
droid.maxHealth = elements[8] | |
droid.movementLeft = elements[9] | |
droid.maxMovement = elements[10] | |
droid.range = elements[11] | |
droid.attack = elements[12] | |
droid.armor = elements[13] | |
droid.maxArmor = elements[14] | |
droid.scrapWorth = elements[15] | |
droid.turnsToBeHacked = elements[16] | |
droid.hackedTurnsLeft = elements[17] | |
droid.hackets = elements[18] | |
droid.hacketsMax = elements[19] | |
return droid | |
parseTile: (elements) -> | |
tile = new webvisApp.parser.Tile | |
tile.id = elements[0] | |
tile.x = elements[1] | |
tile.y = elements[2] | |
tile.owner = elements[3] | |
tile.turnsUntilAssembled = elements[4] | |
tile.variantToAssembled = elements[5] | |
return tile | |
parseModelVariant: (elements) -> | |
modelVariant = new webvisApp.parser.ModelVariant | |
modelVariant.id = elements[0] | |
modelVariant.name = elements[1] | |
modelVariant.variant = elements[2] | |
modelVariant.cost = elements[3] | |
modelVariant.maxAttacks = elements[4] | |
modelVariant.maxHealth = elements[5] | |
modelVariant.maxMovement = elements[6] | |
modelVariant.range = elements[7] | |
modelVariant.attack = elements[8] | |
modelVariant.maxArmor = elements[9] | |
modelVariant.scrapWorth = elements[10] | |
modelVariant.turnsToBeHacked = elements[11] | |
modelVariant.hacketsMax = elements[12] | |
return modelVariant | |
# animations | |
parseAnimation: (elements) -> | |
anim = new webvisApp.parser.Animation | |
anim.type = elements[0] | |
anim.id = elements[1] | |
return anim | |
parseSpawn: (elements) -> | |
spawn = new webvisApp.parser.Spawn | |
spawn.type = elements[0] | |
spawn.sourceID = elements[1] | |
spawn.targetID = elements[2] | |
return spawn | |
parseRepair: (elements) -> | |
repair = new webvisApp.parser.Repair | |
repair.type = elements[0] | |
repair.actingID = elements[1] | |
repair.targetID = elements[2] | |
return repair | |
parseMove: (elements) -> | |
move = new webvisApp.parser.Move | |
move.type = elements[0] | |
move.actingID = elements[1] | |
move.fromX = elements[2] | |
move.fromY = elements[3] | |
move.toX = elements[4] | |
move.toY = elements[5] | |
return move | |
parseHack: (elements) -> | |
hack = new webvisApp.parser.Hack | |
hack.type = elements[0] | |
hack.actingID = elements[1] | |
hack.targetID = elements[2] | |
return hack | |
parseOrbitalDrop: (elements) -> | |
orbitalDrop = new webvisApp.parser.OrbitalDrop | |
orbitalDrop.type = elements[0] | |
orbitalDrop.sourceID = elements[1] | |
return orbitalDrop | |
parseAttack: (elements) -> | |
attack = new webvisApp.parser.Attack | |
attack.type = elements[0] | |
attack.actingID = elements[1] | |
attack.targetID = elements[2] | |
return attack | |
return new Droids |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment