git @ Cat's Eye Technologies The-Swallows / ee377e1
The return of friffery. Cat's Eye Technologies 8 years ago
4 changed file(s) with 77 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2626 # (you *can* pass other objects here, for example 'revolver=brandy', in which
2727 # case the character will act fairly nonsensibly, threatening other characters
2828 # with the bottle of brandy and so forth)
29 fred = MaleCharacter('Fred',
29 fred = MaleCharacter('Fred')
30 fred.configure_objects(
3031 revolver=revolver,
3132 brandy=brandy,
3233 dead_body=dead_body,
3536 # we extend the world by adding new locations and objects
3637 # note that locations exited-to and from must be imported from swallows.story.world (above)
3738 # "Location" is imported from swallows.engine.objects
38 freds_office = Location("Fred's office")
39 freds_office = ProperLocation("<*> office", owner=fred)
3940 freds_office.set_exits(upstairs_hall)
4041
4142 upstairs_hall.set_exits(freds_office) # adds to existing (unknown) exits
4243
4344 # we extend the world by adding some Objects
4445 # "ProperContainer" and "Item" are imported from swallows.engine.objects
45 desk = ProperContainer("Fred's desk", location=freds_office)
46 desk = ProperContainer("<*> desk", owner=fred, location=freds_office)
4647 pencils = Item('box of pencils', location=desk)
4748
4849
1919 publisher = Publisher(
2020 characters=(alice, bob),
2121 setting=house,
22 title="Dial 'S' for Swallows (Unfinished Draft)",
22 title="Dial S for Swallows (DRAFT)",
23 friffery=True,
2324 #debug=True,
2425 #chapters=1,
2526 )
33 # TODO
44
55 # Diction:
6 # - At the start of a paragraph, as well as telling us where a character
7 # is if it's not obvious, also include significant memories they
8 # acquired in the last paragraph -- such as finding a revolver in the bed
96 # - use indef art when they have no memory of an item that they see
107 # - dramatic irony would be really nice, but hard to pull off. Well, a certain
118 # amount happens naturally now, with character pov. but more could be done
172169 self.events = list(reversed(collector.events))
173170 self.main_characters = main_characters
174171 self.pov_index = 0
172 self.transformers = []
175173 # maps main characters to where they currently are (omnisciently)
176174 self.character_location = {}
177175 # maps main characters to where the reader last saw them
178176 self.last_seen_at = {}
179 self.transformers = []
180177 # maps characters to things that happened to them while not narrated
181178 self.exciting_developments = {}
182179
184181 self.transformers.append(transformer)
185182
186183 def publish(self):
184 paragraph_num = 1
187185 while len(self.events) > 0:
188186 pov_actor = self.main_characters[self.pov_index]
189187 paragraph_events = self.generate_paragraph_events(pov_actor)
190188 for transformer in self.transformers:
191189 if paragraph_events:
192 paragraph_events = transformer.transform(self, paragraph_events)
190 paragraph_events = transformer.transform(
191 self, paragraph_events, paragraph_num
192 )
193193 self.publish_paragraph(paragraph_events)
194194 self.pov_index += 1
195195 if self.pov_index >= len(self.main_characters):
196196 self.pov_index = 0
197 paragraph_num += 1
197198
198199 def generate_paragraph_events(self, pov_actor):
199200 quota = random.randint(10, 25)
247248 # you have two characters, Bob Jones and Bob Smith, and both are
248249 # named 'Bob', and they are actually two different events... but...
249250 # for now that is an edge case.
250 def transform(self, editor, incoming_events):
251 def transform(self, editor, incoming_events, paragraph_num):
251252 events = []
252253 for event in incoming_events:
253254 if events:
266267
267268 class UsePronounsTransformer(Transformer):
268269 # replace repeated proper nouns with pronouns
269 def transform(self, editor, incoming_events):
270 def transform(self, editor, incoming_events, paragraph_num):
270271 events = []
271272 for event in incoming_events:
272273 if events:
279280
280281
281282 class MadeTheirWayToTransformer(Transformer):
282 def transform(self, editor, incoming_events):
283 def transform(self, editor, incoming_events, paragraph_num):
283284 events = []
284285 for event in incoming_events:
285286 if (events and
307308 return events
308309
309310
311 # well well well
312 from swallows.engine.objects import Actor
313 weather = Actor('the weather')
314
315
316 class AddWeatherFrifferyTransformer(Transformer):
317 def transform(self, editor, incoming_events, paragraph_num):
318 events = []
319 if paragraph_num == 1:
320 choice = random.randint(0, 3)
321 if choice == 0:
322 events.append(Event("It was raining", [weather]))
323 if choice == 1:
324 events.append(Event("It was snowing", [weather]))
325 if choice == 2:
326 events.append(Event("The sun was shining", [weather]))
327 if choice == 3:
328 events.append(Event("The day was overcast and humid", [weather]))
329 return events + incoming_events
330
331
332 class AddParagraphStartFrifferyTransformer(Transformer):
333 def transform(self, editor, incoming_events, paragraph_num):
334 first_event = incoming_events[0]
335 if paragraph_num == 1:
336 return incoming_events
337 if str(first_event).startswith("'"):
338 return incoming_events
339 if " had found " in str(first_event):
340 return incoming_events
341 if " was in " in str(first_event):
342 return incoming_events
343 choice = random.randint(0, 8)
344 if choice == 0:
345 first_event = first_event.rephrase(
346 "Later on, " + first_event.phrase
347 )
348 if choice == 1:
349 first_event = first_event.rephrase(
350 "Suddenly, " + first_event.phrase
351 )
352 if choice == 2:
353 first_event = first_event.rephrase(
354 "After a moment's consideration, " + first_event.phrase
355 )
356 if choice == 3:
357 first_event = first_event.rephrase(
358 "Feeling anxious, " + first_event.phrase
359 )
360 return [first_event] + incoming_events[1:]
361
362
310363 class AggregateEventsTransformer(Transformer):
311364 # replace "Bob went to the kitchen. Bob saw the toaster"
312365 # with "Bob went to the kitchen, where he saw the toaster"
313 def transform(self, editor, incoming_events):
366 def transform(self, editor, incoming_events, paragraph_num):
314367 events = []
315368 for event in incoming_events:
316369 if events:
334387 class DetectWanderingTransformer(Transformer):
335388 # not used yet
336389 # if they 'made their way' to their current location...
337 def transform(self, editor, incoming_events):
390 def transform(self, editor, incoming_events, paragraph_num):
338391 events = []
339392 for event in incoming_events:
340393 if (event.phrase == '<1> made <his-1> way to <2>' and
395448 editor.add_transformer(AggregateEventsTransformer())
396449 editor.add_transformer(DetectWanderingTransformer())
397450 # this one should be last, so prior transformers don't
398 # have to worry themselved about looking for pronouns
451 # have to worry themselves about looking for pronouns
399452 editor.add_transformer(UsePronounsTransformer())
453 # this should be a matter of configuring what transformers
454 # to use, when you instantiate a Publisher
455 if self.friffery:
456 editor.add_transformer(AddWeatherFrifferyTransformer())
457 editor.add_transformer(AddParagraphStartFrifferyTransformer())
400458 editor.publish()
401459
402460 def publish(self):
99
1010 # TODO
1111
12 # they check containers while someone else is in the room? how'd that get that way?
12 # They can hide something, then see the other carrying it, then check that
13 # it's still hidden, and be surprised that it's no longer ther.
1314 # 'Hello, Alice', said Bob. 'Hello, Bob', replied Alice. NEVER GETS OLD
1415 # they should always scream at seeing the dead body. the scream should
1516 # be heard throughout the house and yard.