git @ Cat's Eye Technologies The-Swallows / 2474efc
Even though it will be replaced, generalize/nicen LegacyPublisher. Cat's Eye Technologies 11 years ago
2 changed file(s) with 32 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
2626 ### main ###
2727
2828 publisher = LegacyPublisher(
29 alice=swallows.world.alice,
30 bob=swallows.world.bob,
31 house=swallows.world.house,
29 characters=(
30 swallows.world.alice,
31 swallows.world.bob,
32 ),
33 setting=swallows.world.house,
3234 title="Title TBD (Book Four of _The Swallows_ series)",
35 #debug=True,
3336 )
3437 publisher.publish()
151151
152152 """
153153 def __init__(self, **kwargs):
154 self.alice = kwargs.get('alice')
155 self.bob = kwargs.get('bob')
156 self.house = kwargs.get('house')
154 self.characters = kwargs.get('characters')
155 self.setting = kwargs.get('setting')
157156 self.friffery = kwargs.get('friffery', False)
158157 self.debug = kwargs.get('debug', False)
159158 self.title = kwargs.get('title', "Untitled")
165164 print "=" * len(self.title)
166165 print
167166
168 alice = self.alice
169 bob = self.bob
170 house = self.house
171
172167 for chapter in range(1, self.chapters+1):
173168 print "Chapter %d." % chapter
174169 print "-----------"
175170 print
176
177 alice_collector = EventCollector()
178 bob_collector = EventCollector()
179 # don't continue a conversation from the previous chapter, please
180 alice.topic = None
181 bob.topic = None
182 alice.location = None
183 bob.location = None
171
172 for character in self.characters:
173 # don't continue a conversation from the previous chapter, please
174 character.topic = None
175 character.location = None
184176
185177 for paragraph in range(1, self.paragraphs_per_chapter+1):
186 alice.collector = alice_collector
187 bob.collector = bob_collector
188
189 # we could do this randomly...
190 #pov_actor = pick([alice, bob])
191 # but, we could also alternate. They ARE Alice and Bob, after all.
192 pov_actor = (alice, bob)[(paragraph - 1) % 2]
193
194 for actor in (alice, bob):
178 for character in self.characters:
179 character.collector = EventCollector()
180
181 # we alternate pov like so:
182 pov_actor = (self.characters)[(paragraph - 1) % len(self.characters)]
183
184 for actor in self.characters:
195185 if actor.location is None:
196 actor.place_in(pick(house))
186 actor.place_in(pick(self.setting))
197187 else:
198188 # this is hacky & won't work for >2 characters:
199 if not (alice.location == bob.location):
189 if self.characters[0].location is not self.characters[1].location:
200190 actor.emit("<1> was in <2>", [actor, actor.location])
201
202 actor_order = (alice, bob)
203 # this leads to continuity problems:
204 #if random.randint(0, 1) == 0:
205 # actor_order = (bob, alice)
191
206192 while len(pov_actor.collector.events) < 20:
207 for actor in actor_order:
193 for actor in self.characters:
208194 actor.live()
209
195
210196 if self.friffery:
211197 if paragraph == 1:
212198 choice = random.randint(0, 3)
230216 sys.stdout.write("Feeling anxious, ")
231217
232218 if self.debug:
233 print "ALICE'S POV:"
234 for event in alice_collector.events:
235 print str(event)
236 print
237 alice.dump_memory()
238 print
239 print "BOB'S POV:"
240 for event in bob_collector.events:
241 print str(event)
242 print
243 bob.dump_memory()
244 print
219 for character in self.characters:
220 print "%s'S POV:" % character.name.upper()
221 for event in character.collector.events:
222 print str(event)
223 print
224 character.dump_memory()
225 print
245226 print "- - - - -"
246227 print
247228
254235 #sys.stdout.write("\n")
255236 print
256237 print
257
258 alice_collector.events = []
259 bob_collector.events = []