From c45e3cf00d8a59bd56da0867f6443d9f57a3c4c9 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Mon, 14 Feb 2011 17:26:48 -0800 Subject: [PATCH] initial support for sections --- iffy.coffee | 38 ++++++++++++++------ retrochronal.coffee | 7 ++-- timemachine.xml | 88 +++++++++++++++++++++++---------------------- 3 files changed, 77 insertions(+), 56 deletions(-) diff --git a/iffy.coffee b/iffy.coffee index 0f388be..0c506fa 100644 --- a/iffy.coffee +++ b/iffy.coffee @@ -141,10 +141,19 @@ class Nevgen # game state -- holds all the information needed to display the current state of the game in our browser class Gst constructor: (@story, @jDiv) -> - @wstInit = @story.WstInit(this) + @rgwstInit = [@story.WstInit(this)] + @rgsection = [@story.SectionByName("start")] @rgwst = null @igenID = 0 + GoBackOneSection: () -> + isectionRemove = @rgsection.length - 1 + @rgsection.splice(isectionRemove, 1) + @rgwstInit.splice(isectionRemove, 1) + + SectionCurrent: () -> + @rgsection[@rgsection.length - 1] + Display: () -> @mpstId_dgOnClick = [] @ClearMenu(true) @@ -207,7 +216,7 @@ class Gst stId RgwstRun: () -> - wst = @wstInit.WstNext(@story.NevByName("start")) + wst = @rgwstInit[@rgwstInit.length - 1].WstNext(@SectionCurrent().NevByName("start")) eniWst = Nevgen.EniWst(this, wst) ArrayFromEni(eniWst) @@ -360,7 +369,7 @@ TemplateFromStNev = (st, wst) -> else 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 dgOnClick = (ev) -> wst.gst.ShowMenu(ev, this, rgverb) @@ -448,10 +457,23 @@ class Story constructor: (@jStory) -> @actorPlayer = new ActorPlayer(this) @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) -> if stName? 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 dParent = dNev while dParent? and istName >= 0 @@ -461,13 +483,9 @@ class Story return new Nev(dNev) null WordByName: (gst, stName) -> - jWord = @jStory.find("word[name=#{stName}]") + jWord = @jSection.find("word[name=#{stName}]") 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) -> if not iurl? then iurl = 0 if not rgresult then rgresult = [] diff --git a/retrochronal.coffee b/retrochronal.coffee index 8eba831..43752f4 100644 --- a/retrochronal.coffee +++ b/retrochronal.coffee @@ -13,8 +13,9 @@ that causes this nev to happen in the future. If the nev specified in future_ca class ActorRetro constructor: (@story) -> @mpnevID_rgnevResponse = {} - for dResponse in @story.jStory.find("pastresponse") - @add(@story.NevByName($(dResponse).attr("after")), dResponse) + for section in @story.Rgsection() + for dResponse in section.jSection.find("pastresponse") + @add(section.NevByName($(dResponse).attr("after")), dResponse) add: (nev, dResponse) -> if not @mpnevID_rgnevResponse[nev.ID()]? @mpnevID_rgnevResponse[nev.ID()] = [] @@ -23,7 +24,7 @@ class ActorRetro rgnevTest = @mpnevID_rgnevResponse[nev.ID()] if rgnevTest? 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) new EniFilter(new EniArray(rgnevTest), FKeepNevTest) diff --git a/timemachine.xml b/timemachine.xml index badff1e..6e3970e 100644 --- a/timemachine.xml +++ b/timemachine.xml @@ -1,46 +1,48 @@ - -

"I still can't believe you actually used a [DeLorean]," says Larry.

-

"Hey, if you're going to do a thing, you ought to do it right," says [Richard].

-
- - - Larry looks at the [DeLorean] with astonishment. [Richard] has done it up to look exactly like the car from - Back to the Future. - - -

Larry eyes the [DeLorean car]. "Give me the keys," he says. "I want to take this baby to 88."

-

"Oh, it doesn't drive anymore," says [Richard]. "I had to use the engine to power the time machine."

-
-
- - -

"So, run it by me again," says Larry.

-

"I modified this [DeLorean] to send information backwards through time," says [Richard].

-

"Just information. Not matter."

-

"Right."

-

Larry ponders this for a moment. "How... how does that even work?"

-

[Richard] waves his hands around. "Spooky action at a distance," he says.

-

"No, I mean, augh. I mean, what can you practically change about the past with this machine?" says Larry.

-

- "Well, so far I've gotten my computer to crash five minutes before I push this [button]," says [Richard], - gesturing at one of the controls inside the [DeLorean]. -

-
-
- - -

Larry reaches for the button and gives it a push.

-

"Nothing happened", says Larry, looking at the [computer].

-

"I told you you were going to push it," says [Richard].

-

Larry opens his mouth to say something, then seems to think better of it.

-
-
- -

There is a beep as [Richard Richard's] [computer] spontaneously and inexplicably reboots.

-

"Aw, geez, you're going to push the button, aren't you?", whines [Richard].

-

"What? What button?" asks Larry, puzzled.

-

"Never mind," says [Richard].

-
+
+ +

"I still can't believe you actually used a [DeLorean]," says Larry.

+

"Hey, if you're going to do a thing, you ought to do it right," says [Richard].

+
+ + + Larry looks at the [DeLorean] with astonishment. [Richard] has done it up to look exactly like the car from + Back to the Future. + + +

Larry eyes the [DeLorean car]. "Give me the keys," he says. "I want to take this baby to 88."

+

"Oh, it doesn't drive anymore," says [Richard]. "I had to use the engine to power the time machine."

+
+
+ + +

"So, run it by me again," says Larry.

+

"I modified this [DeLorean] to send information backwards through time," says [Richard].

+

"Just information. Not matter."

+

"Right."

+

Larry ponders this for a moment. "How... how does that even work?"

+

[Richard] waves his hands around. "Spooky action at a distance," he says.

+

"No, I mean, augh. I mean, what can you practically change about the past with this machine?" says Larry.

+

+ "Well, so far I've gotten my computer to crash five minutes before I push this [button]," says [Richard], + gesturing at one of the controls inside the [DeLorean]. +

+
+
+ + +

Larry reaches for the button and gives it a push.

+

"Nothing happened", says Larry, looking at the [computer].

+

"I told you you were going to push it," says [Richard].

+

Larry opens his mouth to say something, then seems to think better of it.

+
+
+ +

There is a beep as [Richard Richard's] [computer] spontaneously and inexplicably reboots.

+

"Aw, geez, you're going to push the button, aren't you?", whines [Richard].

+

"What? What button?" asks Larry, puzzled.

+

"Never mind," says [Richard].

+
+