diff --git a/iffy.coffee b/iffy.coffee index ae9ee8a..70c2b15 100644 --- a/iffy.coffee +++ b/iffy.coffee @@ -291,6 +291,7 @@ bind = (fn, me) -> ((args...) -> fn.apply(me, args))# argh new coffeescript won' # narrative event happens, the preconditions to make sure the event should be allowed to occur, and # the resultant effect on the state of the model of the world class Nev + @RgstelemReserved = ["cond", "set", "donext"] constructor: (@dNev) -> ID: () -> if not @id? @@ -305,9 +306,23 @@ class Nev return true wst = wst.WstPrev() return false - FCanRun: (gst, wst) -> not @FHasRun(wst) + FConds: (wst) -> + for dCond in $("cond", @dNev) + try + if (!(new Function("wst", "with(wst) {return #{dCond.textContent};}")(wst))) + return false + catch error + return false + true + FCanRun: (gst, wst) -> not @FHasRun(wst) and @FConds(wst) FEndsSection: () -> $(@dNev).attr("nextsection")? RunAction: (gst, wst) -> + for dSet in $("set", @dNev) + try + new Function("wst", "wst.#{$(dSet).attr('var')} = #{dSet.textContent};")(wst) + catch e + alert("error setting #{$(dSet).attr('var')} to #{dSet.textContent}") + StHtmlNextSection: (gst, wst) -> stSectionNext = $(@dNev).attr("nextsection") if stSectionNext? @@ -317,7 +332,13 @@ class Nev StHtmlDisplay: (gst, wst) -> jdivTmp = $("
") for dHTML in $(@dNev).contents() - jdivTmp.append(document.importNode(dHTML, true)) + fReserved = false + for stElemReserved in Nev.RgstelemReserved + if ($.nodeName(dHTML, stElemReserved)) + fReserved = true + break + if not fReserved + jdivTmp.append(document.importNode(dHTML, true)) stHtml = jdivTmp[0].innerHTML "