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,5 +1,6 @@
<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" />
<section name="start">
<nev name="start"> <nev name="start">
<p>"I still can't believe you actually used a [DeLorean]," says Larry.</p> <p>"I still can't believe you actually used a [DeLorean]," says Larry.</p>
<p>"Hey, if you're going to do a thing, you ought to do it right," says [Richard].</p> <p>"Hey, if you're going to do a thing, you ought to do it right," says [Richard].</p>
@ -15,7 +16,7 @@
</verb> </verb>
</word> </word>
<word name="Richard"> <word name="Richard">
<verb name="how" display="What have you done?"> <verb name="how" display='Say, "What have you done?"'>
<p>"So, run it by me again," says Larry.</p> <p>"So, run it by me again," says Larry.</p>
<p>"I modified this [DeLorean] to send information backwards through time," says [Richard].</p> <p>"I modified this [DeLorean] to send information backwards through time," says [Richard].</p>
<p>"Just information. Not matter."</p> <p>"Just information. Not matter."</p>
@ -43,4 +44,5 @@
<p>"What? What button?" asks Larry, puzzled.</p> <p>"What? What button?" asks Larry, puzzled.</p>
<p>"Never mind," says [Richard].</p> <p>"Never mind," says [Richard].</p>
</pastresponse> </pastresponse>
</section>
</story> </story>