1
0
mirror of https://gitlab.com/Deukhoofd/BattleSim.git synced 2025-10-29 10:40:04 +00:00

Lots of stuff

This commit is contained in:
Deukhoofd
2016-02-01 23:19:30 +01:00
commit d7316d5799
6681 changed files with 527969 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
MAX_LOG_LENGTH = 50
class @PrivateMessage extends Backbone.Model
initialize: =>
@loadLog()
@set('notifications', 0)
add: (username, message, opts = {}) =>
@set('notifications', @get('notifications') + 1) if username == @id
@trigger("receive", this, @id, username, message, opts)
log = @get('log')
log.push({username, message, opts})
# Trim the log size. Use 2x log length to reduce how often this happens
if log.length > (2 * MAX_LOG_LENGTH)
log.splice(0, log.length - MAX_LOG_LENGTH)
@saveLog()
openChallenge: (args...) =>
@trigger("openChallenge", args...)
cancelChallenge: (args...) =>
@trigger("cancelChallenge", args...)
closeChallenge: (args...) =>
@trigger("closeChallenge", args...)
getLog: =>
log = @get('log')
if log.length > 50
log.splice(0, log.length - 50)
return log
loadLog: =>
try
log = JSON.parse(window.localStorage.getItem(@logKey())) || []
@set('log', log)
catch
@set('log', [])
saveLog: =>
try
window.localStorage.setItem(@logKey(), JSON.stringify(@getLog()))
logKey: =>
key = [ @id, PokeBattle.username ]
key.sort()
key.join(':')

View File

@@ -0,0 +1,20 @@
class @Room extends Backbone.AssociatedModel
relations: [
type: Backbone.Many
key: 'users'
relatedModel: 'User'
collectionType: 'UserList'
]
EVENTS: "userMessage rawMessage announce clear setTopic".split(/\s+/)
for eventName in this::EVENTS
do (eventName) =>
this::[eventName] = (args...) ->
@trigger(eventName, args...)
sendChat: (message) ->
return false unless message?.replace(/\s+$/).length > 0
if !PokeBattle.commands.execute(this, message)
PokeBattle.primus.send('sendChat', @id, message)
return true

View File

@@ -0,0 +1,16 @@
AuthorityMap =
"1": ""
"2": "+"
"3": "%"
"4": "@"
"5": "~"
class @User extends Backbone.Model
initialize: (attributes) =>
getDisplayName: =>
authorityString = AuthorityMap[@get('authority')] ? ""
"#{authorityString}#{@get('id')}"
isAlt: =>
@get('isAlt')