initial support for sections

This commit is contained in:
Jeremy Penner 2011-02-14 17:26:48 -08:00
parent 13e0166667
commit c45e3cf00d
3 changed files with 77 additions and 56 deletions

View file

@ -141,10 +141,19 @@ class Nevgen
# game state -- holds all the information needed to display the current state of the game in our browser # game state -- holds all the information needed to display the current state of the game in our browser
class Gst class Gst
constructor: (@story, @jDiv) -> constructor: (@story, @jDiv) ->
@wstInit = @story.WstInit(this) @rgwstInit = [@story.WstInit(this)]
@rgsection = [@story.SectionByName("start")]
@rgwst = null @rgwst = null
@igenID = 0 @igenID = 0
GoBackOneSection: () ->
isectionRemove = @rgsection.length - 1
@rgsection.splice(isectionRemove, 1)
@rgwstInit.splice(isectionRemove, 1)
SectionCurrent: () ->
@rgsection[@rgsection.length - 1]
Display: () -> Display: () ->
@mpstId_dgOnClick = [] @mpstId_dgOnClick = []
@ClearMenu(true) @ClearMenu(true)
@ -207,7 +216,7 @@ class Gst
stId stId
RgwstRun: () -> RgwstRun: () ->
wst = @wstInit.WstNext(@story.NevByName("start")) wst = @rgwstInit[@rgwstInit.length - 1].WstNext(@SectionCurrent().NevByName("start"))
eniWst = Nevgen.EniWst(this, wst) eniWst = Nevgen.EniWst(this, wst)
ArrayFromEni(eniWst) ArrayFromEni(eniWst)
@ -360,7 +369,7 @@ TemplateFromStNev = (st, wst) ->
else else
stDisplay = rgstDisplay[1].replace(/_/g, " ") stDisplay = rgstDisplay[1].replace(/_/g, " ")
word = wst.gst.story.WordByName(wst.gst, stWord) word = wst.gst.SectionCurrent().WordByName(wst.gst, stWord)
if word? and (rgverb = word.Rgverb(wst)).length > 0 if word? and (rgverb = word.Rgverb(wst)).length > 0
dgOnClick = (ev) -> wst.gst.ShowMenu(ev, this, rgverb) dgOnClick = (ev) -> wst.gst.ShowMenu(ev, this, rgverb)
@ -448,10 +457,23 @@ class Story
constructor: (@jStory) -> constructor: (@jStory) ->
@actorPlayer = new ActorPlayer(this) @actorPlayer = new ActorPlayer(this)
@rgactor = [@actorPlayer] @rgactor = [@actorPlayer]
SectionByName: (stName) ->
jSection = @jStory.find("section[name=#{stName}]")
if jSection.length == 1 then new Section(this, jSection)
Rgsection: () ->
new Section(this, $(jSection)) for jSection in @jStory.find("section").toArray()
RespoResponse: (nev, wst) ->
Respo.FromEnieniNev(new EniMap(new EniArray(@rgactor), (actor) -> actor.EninevResponse(nev, wst)))
WstInit: (gst) ->
NewWst({}, gst)
class Section
constructor: (@story, @jSection) ->
NevByName: (stName) -> NevByName: (stName) ->
if stName? if stName?
rgstName = stName.split('.') rgstName = stName.split('.')
for dNev in @jStory.find("[name=#{rgstName[rgstName.length - 1]}]") for dNev in @jSection.find("[name=#{rgstName[rgstName.length - 1]}]")
istName = rgstName.length - 2 istName = rgstName.length - 2
dParent = dNev dParent = dNev
while dParent? and istName >= 0 while dParent? and istName >= 0
@ -461,12 +483,8 @@ class Story
return new Nev(dNev) return new Nev(dNev)
null null
WordByName: (gst, stName) -> WordByName: (gst, stName) ->
jWord = @jStory.find("word[name=#{stName}]") jWord = @jSection.find("word[name=#{stName}]")
if jWord.length > 0 then new Word(gst, jWord) if jWord.length > 0 then new Word(gst, jWord)
RespoResponse: (nev, wst) ->
Respo.FromEnieniNev(new EniMap(new EniArray(@rgactor), (actor) -> actor.EninevResponse(nev, wst)))
WstInit: (gst) ->
NewWst({}, gst)
Rgget = (rgurl, dgAfter, iurl, rgresult) -> Rgget = (rgurl, dgAfter, iurl, rgresult) ->
if not iurl? then iurl = 0 if not iurl? then iurl = 0

View file

@ -13,8 +13,9 @@ that causes this nev to happen in the future. If the nev specified in future_ca
class ActorRetro class ActorRetro
constructor: (@story) -> constructor: (@story) ->
@mpnevID_rgnevResponse = {} @mpnevID_rgnevResponse = {}
for dResponse in @story.jStory.find("pastresponse") for section in @story.Rgsection()
@add(@story.NevByName($(dResponse).attr("after")), dResponse) for dResponse in section.jSection.find("pastresponse")
@add(section.NevByName($(dResponse).attr("after")), dResponse)
add: (nev, dResponse) -> add: (nev, dResponse) ->
if not @mpnevID_rgnevResponse[nev.ID()]? if not @mpnevID_rgnevResponse[nev.ID()]?
@mpnevID_rgnevResponse[nev.ID()] = [] @mpnevID_rgnevResponse[nev.ID()] = []
@ -23,7 +24,7 @@ class ActorRetro
rgnevTest = @mpnevID_rgnevResponse[nev.ID()] rgnevTest = @mpnevID_rgnevResponse[nev.ID()]
if rgnevTest? if rgnevTest?
FKeepNevTest = (nevTest, eniNev, nevgen, respo) -> FKeepNevTest = (nevTest, eniNev, nevgen, respo) ->
nevFuture = nevgen.wst.gst.story.NevByName($(nevTest.dNev).attr("future_cause")) nevFuture = nevgen.wst.gst.SectionCurrent().NevByName($(nevTest.dNev).attr("future_cause"))
return nevFuture? and nevgen.wst.gst.FWillNevRun(nevgen.wst, new EniFilter(eniNev, FKeepNevTest), nevgen, respo, nevTest, nevFuture) return nevFuture? and nevgen.wst.gst.FWillNevRun(nevgen.wst, new EniFilter(eniNev, FKeepNevTest), nevgen, respo, nevTest, nevFuture)
new EniFilter(new EniArray(rgnevTest), FKeepNevTest) new EniFilter(new EniArray(rgnevTest), FKeepNevTest)

View file

@ -1,46 +1,48 @@
<story title="Richard and Larry Build A Time Machine" author="Jeremy Penner"> <story title="Richard and Larry Build A Time Machine" author="Jeremy Penner">
<loadmodule url="retrochronal.js" /> <loadmodule url="retrochronal.js" />
<nev name="start"> <section name="start">
<p>"I still can't believe you actually used a [DeLorean]," says Larry.</p> <nev name="start">
<p>"Hey, if you're going to do a thing, you ought to do it right," says [Richard].</p> <p>"I still can't believe you actually used a [DeLorean]," says Larry.</p>
</nev> <p>"Hey, if you're going to do a thing, you ought to do it right," says [Richard].</p>
<word name="DeLorean"> </nev>
<verb name="Examine"> <word name="DeLorean">
Larry looks at the [DeLorean] with astonishment. [Richard] has done it up to look <i>exactly</i> like the car from <verb name="Examine">
<i>Back to the Future</i>. Larry looks at the [DeLorean] with astonishment. [Richard] has done it up to look <i>exactly</i> like the car from
</verb> <i>Back to the Future</i>.
<verb name="Drive"> </verb>
<p>Larry eyes the [DeLorean car]. "Give me the keys," he says. "I want to take this baby to 88."</p> <verb name="Drive">
<p>"Oh, it doesn't drive anymore," says [Richard]. "I had to use the engine to power the time machine."</p> <p>Larry eyes the [DeLorean car]. "Give me the keys," he says. "I want to take this baby to 88."</p>
</verb> <p>"Oh, it doesn't drive anymore," says [Richard]. "I had to use the engine to power the time machine."</p>
</word> </verb>
<word name="Richard"> </word>
<verb name="how" display="What have you done?"> <word name="Richard">
<p>"So, run it by me again," says Larry.</p> <verb name="how" display='Say, "What have you done?"'>
<p>"I modified this [DeLorean] to send information backwards through time," says [Richard].</p> <p>"So, run it by me again," says Larry.</p>
<p>"Just information. Not matter."</p> <p>"I modified this [DeLorean] to send information backwards through time," says [Richard].</p>
<p>"Right."</p> <p>"Just information. Not matter."</p>
<p>Larry ponders this for a moment. "How... how does that even work?"</p> <p>"Right."</p>
<p>[Richard] waves his hands around. "Spooky action at a distance," he says.</p> <p>Larry ponders this for a moment. "How... how does that even work?"</p>
<p>"No, I mean, augh. I mean, what can you practically change about the past with this machine?" says Larry.</p> <p>[Richard] waves his hands around. "Spooky action at a distance," he says.</p>
<p> <p>"No, I mean, augh. I mean, what can you practically change about the past with this machine?" says Larry.</p>
"Well, so far I've gotten my computer to crash five minutes before I push this [button]," says [Richard], <p>
gesturing at one of the controls inside the [DeLorean]. "Well, so far I've gotten my computer to crash five minutes before I push this [button]," says [Richard],
</p> gesturing at one of the controls inside the [DeLorean].
</verb> </p>
</word> </verb>
<word name="button"> </word>
<verb name="Push"> <word name="button">
<p>Larry reaches for the button and gives it a push.</p> <verb name="Push">
<p>"Nothing happened", says Larry, looking at the [computer].</p> <p>Larry reaches for the button and gives it a push.</p>
<p>"I <i>told</i> you you were going to push it," says [Richard].</p> <p>"Nothing happened", says Larry, looking at the [computer].</p>
<p>Larry opens his mouth to say something, then seems to think better of it.</p> <p>"I <i>told</i> you you were going to push it," says [Richard].</p>
</verb> <p>Larry opens his mouth to say something, then seems to think better of it.</p>
</word> </verb>
<pastresponse after="start" future_cause="button.Push" name="crash"> </word>
<p>There is a beep as [Richard Richard's] [computer] spontaneously and inexplicably reboots.</p> <pastresponse after="start" future_cause="button.Push" name="crash">
<p>"Aw, geez, you're going to push the button, aren't you?", whines [Richard].</p> <p>There is a beep as [Richard Richard's] [computer] spontaneously and inexplicably reboots.</p>
<p>"What? What button?" asks Larry, puzzled.</p> <p>"Aw, geez, you're going to push the button, aren't you?", whines [Richard].</p>
<p>"Never mind," says [Richard].</p> <p>"What? What button?" asks Larry, puzzled.</p>
</pastresponse> <p>"Never mind," says [Richard].</p>
</pastresponse>
</section>
</story> </story>