diff --git a/app/styles/play/level/tome/tome.sass b/app/styles/play/level/tome/tome.sass index 0fd9f5ac7..c8eaee5f3 100644 --- a/app/styles/play/level/tome/tome.sass +++ b/app/styles/play/level/tome/tome.sass @@ -33,3 +33,6 @@ &.right .arrow left: -3% + pre + display: inline-block + padding: 5px diff --git a/app/templates/play/level/tome/spell_palette_entry_popover.jade b/app/templates/play/level/tome/spell_palette_entry_popover.jade index 37b097869..1002593e1 100644 --- a/app/templates/play/level/tome/spell_palette_entry_popover.jade +++ b/app/templates/play/level/tome/spell_palette_entry_popover.jade @@ -20,7 +20,8 @@ else if doc.type == 'function' if doc.type != 'function' && doc.type != 'snippet' p.value strong Current Value: - code.current-value(data-prop=doc.name)= value + pre + code.current-value(data-prop=doc.name)= value if doc.args && doc.args.length p.args diff --git a/app/views/play/level/tome/spell_palette_entry_view.coffee b/app/views/play/level/tome/spell_palette_entry_view.coffee index 4f26afc17..0ef882854 100644 --- a/app/views/play/level/tome/spell_palette_entry_view.coffee +++ b/app/views/play/level/tome/spell_palette_entry_view.coffee @@ -8,6 +8,39 @@ filters = require 'lib/image_filter' # If we use marked somewhere else, we'll have to make sure to preserve options marked.setOptions {gfm: true, sanitize: false, smartLists: true, breaks: true} +safeJSONStringify = (input, maxDepth) -> + recursion = (input, path, depth) -> + output = {} + pPath = undefined + refIdx = undefined + path = path or "" + depth = depth or 0 + depth++ + return "{depth over " + maxDepth + "}" if maxDepth and depth > maxDepth + for p of input + pPath = ((if path then (path + ".") else "")) + p + if typeof input[p] is "function" + output[p] = "{function}" + else if typeof input[p] is "object" + refIdx = refs.indexOf(input[p]) + if -1 isnt refIdx + output[p] = "{reference to " + refsPaths[refIdx] + "}" + else + refs.push input[p] + refsPaths.push pPath + output[p] = recursion(input[p], pPath, depth) + else + output[p] = input[p] + output + refs = [] + refsPaths = [] + maxDepth = maxDepth or 5 + if typeof input is "object" + output = recursion(input) + else + output = input + JSON.stringify output, null, 1 + module.exports = class SpellPaletteEntryView extends View tagName: 'div' # Could also try <code> instead of <div>, but would need to adjust colors className: 'spell-palette-entry-view' @@ -61,6 +94,7 @@ module.exports = class SpellPaletteEntryView extends View formatPopover: -> content = popoverTemplate doc: @doc, value: @formatValue(), marked: marked, argumentExamples: (arg.example or arg.default or arg.name for arg in @doc.args ? []) owner = if @doc.owner is 'this' then @thang else window[@doc.owner] + content = content.replace /#{spriteName}/g, @thang.spriteName # No quotes like we'd get with @formatValue content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.')) formatValue: (v) -> @@ -70,7 +104,7 @@ module.exports = class SpellPaletteEntryView extends View v = @thang[@doc.name] else v = window[@doc.owner][@doc.name] - if @type is 'number' and not isNaN v + if @doc.type is 'number' and not isNaN v if v == Math.round v return v return v.toFixed 2 @@ -82,6 +116,8 @@ module.exports = class SpellPaletteEntryView extends View return v.name if _.isArray v return '[' + (@formatValue v2 for v2 in v).join(', ') + ']' + if _.isPlainObject v + return safeJSONStringify v, 2 v onMouseOver: (e) -> @@ -95,7 +131,6 @@ module.exports = class SpellPaletteEntryView extends View onFrameChanged: (e) -> return unless e.selectedThang?.id is @thang.id @options.thang = @thang = e.selectedThang # Update our thang to the current version - @$el.find("code.current-value").text(@formatValue()) destroy: -> @$el.off()