mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-03 17:33:31 -04:00
Initial attempts, dunno if it works or is missing things
This commit is contained in:
parent
6b8a56ae4f
commit
68fc710384
2 changed files with 21 additions and 16 deletions
app/views/play/level/tome
|
@ -13,7 +13,7 @@ module.exports = class Problem
|
||||||
@annotation = @buildAnnotationFromAetherProblem(@aetherProblem)
|
@annotation = @buildAnnotationFromAetherProblem(@aetherProblem)
|
||||||
{ @lineMarkerRange, @textMarkerRange } = @buildMarkerRangesFromAetherProblem(@aetherProblem) if isCast
|
{ @lineMarkerRange, @textMarkerRange } = @buildMarkerRangesFromAetherProblem(@aetherProblem) if isCast
|
||||||
|
|
||||||
{ @level, @range, @message, @hint, @userInfo } = @aetherProblem
|
{ @level, @range, @message, @hint, @userInfo, @type } = @aetherProblem
|
||||||
{ @row, @column: col } = @aetherProblem.range?[0]
|
{ @row, @column: col } = @aetherProblem.range?[0]
|
||||||
@createdBy = 'aether'
|
@createdBy = 'aether'
|
||||||
else
|
else
|
||||||
|
|
|
@ -853,34 +853,37 @@ module.exports = class SpellView extends CocoView
|
||||||
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: isCast
|
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: isCast
|
||||||
@ace.resize()
|
@ace.resize()
|
||||||
|
|
||||||
saveUserCodeProblem: (aether, aetherProblem) ->
|
saveUserCodeProblem: (aether, problem) ->
|
||||||
|
aether ?= @spellThang?.aether
|
||||||
# Skip duplicate problems
|
# Skip duplicate problems
|
||||||
hashValue = aether.raw + aetherProblem.message
|
hashValue = aether.raw + problem.message
|
||||||
return if hashValue of @savedProblems
|
return if hashValue of @savedProblems
|
||||||
@savedProblems[hashValue] = true
|
@savedProblems[hashValue] = true
|
||||||
return unless Math.random() < 0.01 # Let's only save a tiny fraction of these during HoC to reduce writes.
|
return unless Math.random() < 0.01 # Let's only save a tiny fraction of these to reduce writes.
|
||||||
|
|
||||||
# Save new problem
|
# Save new problem
|
||||||
@userCodeProblem = new UserCodeProblem()
|
@userCodeProblem = new UserCodeProblem()
|
||||||
@userCodeProblem.set 'code', aether.raw
|
@userCodeProblem.set 'code', aether.raw
|
||||||
if aetherProblem.range
|
if problem.range or problem.row
|
||||||
rawLines = aether.raw.split '\n'
|
rawLines = aether.raw.split '\n'
|
||||||
errorLines = rawLines.slice aetherProblem.range[0].row, aetherProblem.range[1].row + 1
|
startLine = problem.range?[0].row or problem.row
|
||||||
|
endLine = (problem.range?[1].row or problem.row)
|
||||||
|
errorLines = rawLines.slice startLine, endLine + 1
|
||||||
@userCodeProblem.set 'codeSnippet', errorLines.join '\n'
|
@userCodeProblem.set 'codeSnippet', errorLines.join '\n'
|
||||||
@userCodeProblem.set 'errHint', aetherProblem.hint if aetherProblem.hint
|
@userCodeProblem.set 'errHint', problem.hint if problem.hint
|
||||||
@userCodeProblem.set 'errId', aetherProblem.id if aetherProblem.id
|
@userCodeProblem.set 'errId', problem.id if problem.id
|
||||||
@userCodeProblem.set 'errLevel', aetherProblem.level if aetherProblem.level
|
@userCodeProblem.set 'errLevel', problem.level if problem.level
|
||||||
if aetherProblem.message
|
if problem.message
|
||||||
@userCodeProblem.set 'errMessage', aetherProblem.message
|
@userCodeProblem.set 'errMessage', problem.message
|
||||||
# Save error message without 'Line N: ' prefix
|
# Save error message without 'Line N: ' prefix
|
||||||
messageNoLineInfo = aetherProblem.message
|
messageNoLineInfo = problem.message
|
||||||
if lineInfoMatch = messageNoLineInfo.match /^Line [0-9]+\: /
|
if lineInfoMatch = messageNoLineInfo.match /^Line [0-9]+\: /
|
||||||
messageNoLineInfo = messageNoLineInfo.slice(lineInfoMatch[0].length)
|
messageNoLineInfo = messageNoLineInfo.slice(lineInfoMatch[0].length)
|
||||||
@userCodeProblem.set 'errMessageNoLineInfo', messageNoLineInfo
|
@userCodeProblem.set 'errMessageNoLineInfo', messageNoLineInfo
|
||||||
@userCodeProblem.set 'errRange', aetherProblem.range if aetherProblem.range
|
@userCodeProblem.set 'errRange', problem.range if problem.range
|
||||||
@userCodeProblem.set 'errType', aetherProblem.type if aetherProblem.type
|
@userCodeProblem.set 'errType', problem.type if problem.type
|
||||||
@userCodeProblem.set 'language', aether.language.id if aether.language?.id
|
@userCodeProblem.set 'language', aether.language.id if aether.language?.id
|
||||||
@userCodeProblem.set 'levelID', @options.levelID if @options.levelID
|
@userCodeProblem.set 'levelID', problem.levelID if problem.levelID
|
||||||
@userCodeProblem.save()
|
@userCodeProblem.save()
|
||||||
null
|
null
|
||||||
|
|
||||||
|
@ -1010,7 +1013,9 @@ module.exports = class SpellView extends CocoView
|
||||||
lineOffsetPx -= @ace.session.getScrollTop()
|
lineOffsetPx -= @ace.session.getScrollTop()
|
||||||
Backbone.Mediator.publish 'tome:show-problem-alert', problem: problem, lineOffsetPx: Math.max lineOffsetPx, 0
|
Backbone.Mediator.publish 'tome:show-problem-alert', problem: problem, lineOffsetPx: Math.max lineOffsetPx, 0
|
||||||
|
|
||||||
# @saveUserCodeProblem(aether, aetherProblem) # TODO: Enable saving of web-dev user code problems
|
if aether = @spellThang?.aether
|
||||||
|
@saveUserCodeProblem(aether, problem) # TODO: Enable saving of web-dev user code problems
|
||||||
|
|
||||||
annotations.push problem.annotation if problem.annotation
|
annotations.push problem.annotation if problem.annotation
|
||||||
@reallySetAnnotations annotations
|
@reallySetAnnotations annotations
|
||||||
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: true
|
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue