mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-01 08:23:57 -04:00
Fixed naming.
Improved tome updating of programmable spell thangs.
This commit is contained in:
parent
065a1c4c27
commit
bac4fbcd7d
7 changed files with 34 additions and 48 deletions
app
lib
views
|
@ -163,7 +163,8 @@ module.exports = class SpriteBoss extends CocoClass
|
||||||
if sprite = @sprites[thang.id]
|
if sprite = @sprites[thang.id]
|
||||||
sprite.setThang thang # make sure Sprite has latest Thang
|
sprite.setThang thang # make sure Sprite has latest Thang
|
||||||
else
|
else
|
||||||
sprite = @addThangToSprites(thang) or updateOrder
|
sprite = @addThangToSprites(thang)
|
||||||
|
Backbone.Mediator.publish 'surface:new-thang-added', thang:thang, sprite:sprite
|
||||||
updateCache = updateCache or sprite.displayObject.parent is @spriteLayers["Obstacle"]
|
updateCache = updateCache or sprite.displayObject.parent is @spriteLayers["Obstacle"]
|
||||||
sprite.playSounds()
|
sprite.playSounds()
|
||||||
for thangID, sprite of @sprites
|
for thangID, sprite of @sprites
|
||||||
|
|
|
@ -124,16 +124,15 @@ module.exports.thangNames = thangNames =
|
||||||
"Skoggen"
|
"Skoggen"
|
||||||
"Treg"
|
"Treg"
|
||||||
"Goreball"
|
"Goreball"
|
||||||
"Shmeal"
|
|
||||||
"Gert"
|
"Gert"
|
||||||
"Thabt"
|
"Thabt"
|
||||||
"Iyert"
|
|
||||||
"Palt"
|
|
||||||
"Snortt"
|
"Snortt"
|
||||||
"Kog"
|
"Kog"
|
||||||
]
|
]
|
||||||
"Ogre Munchkin F": [
|
"Ogre Munchkin F": [
|
||||||
|
"Iyert"
|
||||||
|
"Palt"
|
||||||
|
"Shmeal"
|
||||||
]
|
]
|
||||||
"Ogre M": [
|
"Ogre M": [
|
||||||
"Krogg"
|
"Krogg"
|
||||||
|
@ -144,12 +143,11 @@ module.exports.thangNames = thangNames =
|
||||||
"Mak Fod"
|
"Mak Fod"
|
||||||
"Trung"
|
"Trung"
|
||||||
"Axe Ox"
|
"Axe Ox"
|
||||||
|
]
|
||||||
|
"Ogre F": [
|
||||||
"Nareng"
|
"Nareng"
|
||||||
"Morthrug"
|
"Morthrug"
|
||||||
"Glonc"
|
"Glonc"
|
||||||
]
|
|
||||||
"Ogre F": [
|
|
||||||
|
|
||||||
]
|
]
|
||||||
"Ogre Brawler": [
|
"Ogre Brawler": [
|
||||||
"Grul'thock"
|
"Grul'thock"
|
||||||
|
|
|
@ -32,8 +32,4 @@ class Rand
|
||||||
rand2: (min, max) =>
|
rand2: (min, max) =>
|
||||||
min + @rand max - min
|
min + @rand max - min
|
||||||
|
|
||||||
# return an array of numbers from 0 to n-1, shuffled
|
|
||||||
randArray: (n) =>
|
|
||||||
_.shuffle [0...n]
|
|
||||||
|
|
||||||
module.exports = Rand
|
module.exports = Rand
|
|
@ -4,44 +4,29 @@ ThangState = require './thang_state'
|
||||||
Rand = require './rand'
|
Rand = require './rand'
|
||||||
|
|
||||||
module.exports = class Thang
|
module.exports = class Thang
|
||||||
@className: "Thang"
|
@className: 'Thang'
|
||||||
@random = new Rand
|
@remainingThangNames: {}
|
||||||
|
|
||||||
# Random ordering for each sprite name
|
@nextID: (spriteName, world) ->
|
||||||
@ordering: (spriteName) ->
|
|
||||||
Thang.orders ?= {}
|
|
||||||
names = thangNames[spriteName]
|
|
||||||
if names
|
|
||||||
len = names.length
|
|
||||||
array = Thang.orders[spriteName]
|
|
||||||
unless array?
|
|
||||||
array = @random.randArray len
|
|
||||||
Thang.orders[spriteName] = array
|
|
||||||
else
|
|
||||||
array = []
|
|
||||||
array
|
|
||||||
|
|
||||||
@nextID: (spriteName) ->
|
|
||||||
Thang.lastIDNums ?= {}
|
Thang.lastIDNums ?= {}
|
||||||
names = thangNames[spriteName]
|
originals = thangNames[spriteName] or [spriteName]
|
||||||
order = @ordering spriteName
|
remaining = Thang.remainingThangNames[spriteName]
|
||||||
if names and names.length
|
remaining = Thang.remainingThangNames[spriteName] = originals.slice() unless remaining?.length
|
||||||
lastIDNum = Thang.lastIDNums[spriteName]
|
|
||||||
idNum = (if lastIDNum? then lastIDNum + 1 else 0)
|
|
||||||
Thang.lastIDNums[spriteName] = idNum
|
|
||||||
id = names[order[idNum % names.length]]
|
|
||||||
if idNum >= names.length
|
|
||||||
id += Math.floor(idNum / names.length) + 1
|
|
||||||
else
|
|
||||||
Thang.lastIDNums[spriteName] = if Thang.lastIDNums[spriteName]? then Thang.lastIDNums[spriteName] + 1 else 0
|
|
||||||
id = spriteName + (Thang.lastIDNums[spriteName] or '')
|
|
||||||
id
|
|
||||||
|
|
||||||
@resetThangIDs: -> Thang.lastIDNums = {}
|
baseName = remaining.splice(world.rand.rand(remaining.length), 1)[0]
|
||||||
|
i = 0
|
||||||
|
while true
|
||||||
|
name = if i then "#{baseName} #{i}" else baseName
|
||||||
|
extantThang = world.thangMap[name]
|
||||||
|
break unless extantThang
|
||||||
|
i++
|
||||||
|
name
|
||||||
|
|
||||||
|
@resetThangIDs: -> Thang.remainingThangNames = {}
|
||||||
|
|
||||||
constructor: (@world, @spriteName, @id) ->
|
constructor: (@world, @spriteName, @id) ->
|
||||||
@spriteName ?= @constructor.className
|
@spriteName ?= @constructor.className
|
||||||
@id ?= @constructor.nextID @spriteName
|
@id ?= @constructor.nextID @spriteName, @world
|
||||||
@addTrackedProperties ['exists', 'boolean'] # TODO: move into Systems/Components, too?
|
@addTrackedProperties ['exists', 'boolean'] # TODO: move into Systems/Components, too?
|
||||||
#console.log "Generated #{@toString()}."
|
#console.log "Generated #{@toString()}."
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,7 @@ module.exports = class ThangsTabView extends View
|
||||||
@editThang thangID: id if id
|
@editThang thangID: id if id
|
||||||
|
|
||||||
addThang: (thangType, pos) ->
|
addThang: (thangType, pos) ->
|
||||||
thangID = Thang.nextID(thangType.get('name')) until thangID and not @thangsTreema.get "id=#{thangID}"
|
thangID = Thang.nextID(thangType.get('name'), @world) until thangID and not @thangsTreema.get "id=#{thangID}"
|
||||||
if @cloneSourceThang
|
if @cloneSourceThang
|
||||||
components = _.cloneDeep @thangsTreema.get "id=#{@cloneSourceThang.id}/components"
|
components = _.cloneDeep @thangsTreema.get "id=#{@cloneSourceThang.id}/components"
|
||||||
@selectAddThang null
|
@selectAddThang null
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = class Spell
|
||||||
@tabView.render()
|
@tabView.render()
|
||||||
|
|
||||||
addThang: (thang) ->
|
addThang: (thang) ->
|
||||||
@thangs[thang.id] = {thang: thang, aether: @createAether(thang), castAether: null}
|
@thangs[thang.id] ?= {thang: thang, aether: @createAether(thang), castAether: null}
|
||||||
|
|
||||||
canRead: (team) ->
|
canRead: (team) ->
|
||||||
(team ? me.team) in @permissions.read or (team ? me.team) in @permissions.readwrite
|
(team ? me.team) in @permissions.read or (team ? me.team) in @permissions.readwrite
|
||||||
|
|
|
@ -47,6 +47,7 @@ module.exports = class TomeView extends View
|
||||||
'tome:cast-spell': "onCastSpell"
|
'tome:cast-spell': "onCastSpell"
|
||||||
'tome:toggle-spell-list': 'onToggleSpellList'
|
'tome:toggle-spell-list': 'onToggleSpellList'
|
||||||
'surface:sprite-selected': 'onSpriteSelected'
|
'surface:sprite-selected': 'onSpriteSelected'
|
||||||
|
'surface:new-thang-added': 'onNewThangAdded'
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #spell-view': 'onSpellViewClick'
|
'click #spell-view': 'onSpellViewClick'
|
||||||
|
@ -65,14 +66,19 @@ module.exports = class TomeView extends View
|
||||||
@cast()
|
@cast()
|
||||||
console.log "Warning: There are no Programmable Thangs in this level, which makes it unplayable."
|
console.log "Warning: There are no Programmable Thangs in this level, which makes it unplayable."
|
||||||
|
|
||||||
|
onNewThangAdded: (e) ->
|
||||||
|
return unless e.thang.isProgrammable
|
||||||
|
@createSpells [e.thang]
|
||||||
|
|
||||||
createSpells: (programmableThangs) ->
|
createSpells: (programmableThangs) ->
|
||||||
# If needed, we could make this able to update when programmableThangs changes.
|
# If needed, we could make this able to update when programmableThangs changes.
|
||||||
# We haven't done that yet, so call it just once on init.
|
# We haven't done that yet, so call it just once on init.
|
||||||
pathPrefixComponents = ['play', 'level', @options.levelID, @options.session.id, 'code']
|
pathPrefixComponents = ['play', 'level', @options.levelID, @options.session.id, 'code']
|
||||||
@spells = {}
|
@spells ?= {}
|
||||||
@thangSpells = {}
|
@thangSpells ?= {}
|
||||||
for thang in programmableThangs
|
for thang in programmableThangs
|
||||||
world = thang.world
|
world = thang.world
|
||||||
|
continue if @thangSpells[thang.id]?
|
||||||
@thangSpells[thang.id] = []
|
@thangSpells[thang.id] = []
|
||||||
for methodName, method of thang.programmableMethods
|
for methodName, method of thang.programmableMethods
|
||||||
pathComponents = [thang.id, methodName]
|
pathComponents = [thang.id, methodName]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue