Fixed up headless client, I hope.

This commit is contained in:
Nick Winter 2015-02-12 16:06:27 -08:00
parent c4f46faf25
commit 1aa738b256
8 changed files with 53 additions and 41 deletions

View file

@ -144,7 +144,7 @@ module.exports.getUTCDay = (offset=0) ->
# Fast, basic way to replace text in an element when you don't need much.
# http://stackoverflow.com/a/4962398/540620
if document?
if document?.createElement
dummy = document.createElement 'div'
dummy.innerHTML = 'text'
TEXT = if dummy.textContent is 'text' then 'textContent' else 'innerText'
@ -155,7 +155,7 @@ if document?
# Add a stylesheet rule
# http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript/26230472#26230472
# Don't use wantonly, or we'll have to implement a simple mechanism for clearing out old rules.
if document?
if document?.createElement
module.exports.injectCSS = ((doc) ->
# wrapper for all injected styles and temp el to create them
wrap = doc.createElement("div")

View file

@ -94,7 +94,7 @@ module.exports = class LevelLoader extends CocoClass
if session is @session
codeLanguage = session.get('codeLanguage') or me.get('aceConfig')?.language or 'python'
modulePath = "vendor/aether-#{codeLanguage}"
loading = application.moduleLoader.load(modulePath)
loading = application.moduleLoader?.load(modulePath)
if loading
@languageModuleResource = @supermodel.addSomethingResource 'language_module'
@listenTo application.moduleLoader, 'loaded', (e) ->

View file

@ -206,7 +206,7 @@ module.exports = class Spell
@problemContext = { stringReferences: [], thisMethods: [], thisProperties: [] }
# TODO: These should be read from the database
@problemContext.commonThisMethods = ['moveRight', 'moveLeft', 'moveUp', 'moveDown', 'attack', 'findNearestEnemy', 'buildXY', 'moveXY', 'say', 'move', 'distance', 'findEnemies', 'getFriends', 'addFlag', 'getFlag', 'removeFlag', 'getFlags', 'attackRange', 'cast', 'buildTypes', 'jump', 'jumpTo', 'attackXY']
@problemContext.commonThisMethods = ['moveRight', 'moveLeft', 'moveUp', 'moveDown', 'attack', 'findNearestEnemy', 'buildXY', 'moveXY', 'say', 'move', 'distance', 'findEnemies', 'findFriends', 'addFlag', 'findFlag', 'removeFlag', 'findFlags', 'attackRange', 'cast', 'buildTypes', 'jump', 'jumpTo', 'attackXY']
return @problemContext unless thang?
# Populate stringReferences

View file

@ -22,7 +22,8 @@ options =
simulateOnlyOneGame: simulateOneGame
options.heapdump = require('heapdump') if options.heapdump
server = if options.testing then 'http://127.0.0.1:3000' else 'https://codecombat.com'
server = if options.testing then 'http://127.0.0.1:3000' else 'http://direct.codecombat.com'
# Use direct instead of live site because jQlone's requests proxy doesn't do caching properly and CloudFlare gets too aggressive.
# Disabled modules
disable = [
@ -62,12 +63,16 @@ hookedLoader = (request, parent, isMain) ->
if request in disable or ~request.indexOf('templates')
console.log 'Ignored ' + request if options.debug
return class fake
else if /node_modules[\\\/]aether[\\\/]/.test parent.id
null # Let it through
else if '/' in request and not (request[0] is '.') or request is 'application'
#console.log 'making path', path + '/app/' + request, 'from', path, request, 'with parent', parent
request = path + '/app/' + request
else if request is 'underscore'
request = 'lodash'
console.log 'loading ' + request if options.debug
originalLoader request, parent, isMain
unhook = () ->
m._load = originalLoader
hook = () ->

View file

@ -9,7 +9,7 @@ module.exports = $ = (input) ->
# Non-standard jQuery stuff. Don't use outside of server.
$._debug = false
$._server = 'https://codecombat.com'
$._server = 'http://direct.codecombat.com'
$._cookies = request.jar()
$.when = Deferred.when

File diff suppressed because one or more lines are too long

View file

@ -100,12 +100,12 @@ work = () ->
self.postMessage type: 'start-load-frames'
self.world.loadFrames self.onWorldLoaded, self.onWorldError, self.onWorldLoadProgress, true
self.world.loadFrames self.onWorldLoaded, self.onWorldError, self.onWorldLoadProgress, null, true
self.onWorldLoaded = onWorldLoaded = ->
self.goalManager.worldGenerationEnded()
goalStates = self.goalManager.getGoalStates()
self.postMessage type: 'end-load-frames', goalStates: goalStates
self.postMessage type: 'end-load-frames', goalStates: goalStates, overallStatus: goalManager.checkOverallStatus()
t1 = new Date()
diff = t1 - self.t0
@ -176,9 +176,19 @@ work = () ->
self.postMessage type: 'worker-initialized'
worldCode = fs.readFileSync './public/javascripts/world.js', 'utf8'
lodashCode = fs.readFileSync './public/javascripts/lodash.js', 'utf8'
aetherCode = fs.readFileSync './public/javascripts/aether.js', 'utf8'
codeFileContents = []
for codeFile in [
'world.js'
'lodash.js'
'aether.js'
'app/vendor/aether-clojure.js'
'app/vendor/aether-coffeescript.js'
'app/vendor/aether-io.js'
'app/vendor/aether-javascript.js'
'app/vendor/aether-lua.js'
'app/vendor/aether-python.js'
]
codeFileContents.push fs.readFileSync("./public/javascripts/#{codeFile}", 'utf8')
#window.BOX2D_ENABLED = true;
@ -195,9 +205,7 @@ ret = """
try {
// the world javascript file
#{worldCode};
#{lodashCode};
#{aetherCode};
#{codeFileContents.join(';\n ')};
// Don't let user generated code access stuff from our file system!
self.importScripts = importScripts = null;

View file

@ -63,7 +63,7 @@
"aws-sdk": "~2.0.0",
"bayesian-battle": "0.0.x",
"redis": "",
"webworker-threads": "~0.4.11",
"webworker-threads": "~0.5.5",
"node-gyp": "~0.13.0",
"aether": "~0.3.0",
"JASON": "~0.1.3",