add conditionals, variable setting to nev primitives

This commit is contained in:
Jeremy Penner 2011-03-03 07:41:55 -08:00
parent dffc93d5e6
commit 2c8380a776

View file

@ -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 = $("<div/>")
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
"<div class='iffy-nev-ui'>#{gst.StHtmlUi(wst)}</div><div class='iffy-nev-text'>#{gst.FilterStHtml(stHtml, wst)}</div>"
@ -443,7 +464,7 @@ class Word
rgverb = []
for dVerb in @jWord.find("verb")
nev = new Nev(dVerb)
if not @gst.FWasRun(nev) and not @gst.story.actorPlayer.FWillAttempt(wst, nev)
if not @gst.FWasRun(nev) and not @gst.story.actorPlayer.FWillAttempt(wst, nev) and nev.FConds(wst)
stDisplay = $(dVerb).attr("display") or $(dVerb).attr("name")
dgActivate = ((dVerbT) => () => @gst.story.actorPlayer.RespondTo(wst.nev, new Nev(dVerbT)))(dVerb)
rgverb.push(new Verb(stDisplay, dgActivate))