Skip to content

Instantly share code, notes, and snippets.

@jareiko
jareiko / robot.js
Created December 1, 2012 20:08
Robby
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
createAttributeMonitor = ->
monitored = Object.create null
(parentModel, name) ->
bubbleEvent = (event, args...) ->
return unless event.startsWith 'change:'
parentModel.trigger "change:#{name}.#{event[7..]}", args...
value = parentModel.get name
oldValue = monitored[name]
createAttributeMonitor = ->
monitored = Object.create null
(parentModel, name) ->
bubbleEvent = (event, args...) ->
return unless event.startsWith 'change:'
parentModel.trigger "change:#{name}.#{event[7..]}", args...
value = parentModel.get name
oldValue = monitored[name]
class Model extends Backbone.Model
initialize: ->
super
monitor = createAttributeMonitor()
# Bind to initial attributes.
monitor @, name for name of @attributes
# Watch for changes to attributes and rebind as necessary.
@on 'change', =>
app.track.config.on 'change', -> updateView()
app.track.on 'change:config', ->
app.track.config.on 'change', -> updateView()
app.track.on 'change:config', ->
app.track.config.on 'change', -> updateView()
# This code...
app.track.config.on 'change', -> updateView()
# ...becomes this:
app.on 'change:track.config', -> updateView()
Process: Grandroids [11089]
Path: /Users/USER/Downloads/*/GrandroidsMac.app/Contents/MacOS/Grandroids
Identifier: unity.Steve Grand.Grandroids
Version: Unity Player version 4.3.4f1 (4.3.4f1)
Code Type: X86-64 (Native)
Parent Process: launchd [253]
Responsible: Grandroids [11089]
User ID: 501
Date/Time: 2014-04-25 14:17:17.574 +0200
var ReactiveValue = function(value) {
var dep = new Deps.Dependency();
var state = value;
this.get = function() {
dep.depend();
return state;
}
this.set = function(newValue) {
if (state === newValue) return;
state = newValue;