-
Notifications
You must be signed in to change notification settings - Fork 667
/
character.py
1766 lines (1282 loc) · 55.7 KB
/
character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2004-2024 Tom Rothamel <pytom@bishoujo.us>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# The Character object (and friends).
from __future__ import division, absolute_import, with_statement, print_function, unicode_literals
from renpy.compat import PY2, basestring, bchr, bord, chr, open, pystr, range, round, str, tobytes, unicode # *
from typing import Any, Literal
import renpy
import re
import os
import collections
# This matches the dialogue-relevant text tags.
TAG_RE = re.compile(r'(\{\{)|(\{(p|w|nw|fast|done)(?:\=([^}]*))?\})', re.S)
less_pauses = ("RENPY_LESS_PAUSES" in os.environ)
class DialogueTextTags(object):
"""
This object parses the text tags that only make sense in dialogue,
like {fast}, {p}, {w}, and {nw}.
"""
def __init__(self, s):
# The text that we've accumulated, not including any tags.
self.text = ""
# The index in the produced string where each pause starts.
self.pause_start = [ 0 ]
# The index in the produced string where each pause ends.
self.pause_end = [ ]
# The time to delay for each pause. None to delay forever.
self.pause_delay = [ ]
# True if we've encountered the no-wait tag.
self.no_wait = False
# Does this statement have a done tag?
self.has_done = False
# Does this statement have a fast tag?
self.fast = False
i = iter(TAG_RE.split(s))
while True:
try:
self.text += next(i)
quoted = next(i)
full_tag = next(i)
tag = next(i)
value = next(i)
if value is not None:
value = float(value)
if quoted is not None:
self.text += quoted
continue
if tag == "p" or tag == "w":
if not less_pauses:
self.pause_start.append(len(self.text))
self.pause_end.append(len(self.text))
self.pause_delay.append(value)
elif tag == "nw":
self.no_wait = True
if value is not None and not less_pauses:
self.pause_start.append(len(self.text))
self.pause_end.append(len(self.text))
self.pause_delay.append(value)
elif tag == "fast":
self.pause_start = [ len(self.text) ]
self.pause_end = [ ]
self.pause_delay = [ ]
self.no_wait = False
self.fast = True
elif tag == "done":
self.has_done = True
self.text += full_tag
break
self.text += full_tag
except StopIteration:
break
self.pause_end.append(len(self.text))
while True:
try:
self.text += next(i)
quoted = next(i)
full_tag = next(i)
tag = next(i)
value = next(i)
if quoted is not None:
self.text += quoted
continue
self.text += full_tag
except StopIteration:
break
if self.no_wait:
self.pause_delay.append(0)
else:
self.pause_delay.append(None)
def predict_show_display_say(who, what, who_args, what_args, window_args, image=False, two_window=False, side_image=None, screen=None, properties=None, **kwargs):
"""
This is the default function used by Character to predict images that
will be used by show_display_say. It's called with more-or-less the
same parameters as show_display_say, and it's expected to return a
list of images used by show_display_say.
"""
if side_image:
renpy.easy.predict(side_image)
if renpy.store._side_image_attributes:
renpy.easy.predict(renpy.display.image.ImageReference(("side",) + renpy.store._side_image_attributes))
if image:
if image != "<Dynamic>":
renpy.easy.predict(who)
kwargs["image"] = image
if screen:
props = compute_widget_properties(who_args, what_args, window_args, properties)
renpy.display.predict.screen(
screen,
_widget_properties=props,
who=who,
what=what,
two_window=two_window,
side_image=side_image,
**kwargs)
return
def compute_widget_properties(who_args, what_args, window_args, properties, variant=None, multiple=None):
"""
Computes and returns the widget properties.
"""
def style_args(d, name):
style = d.get("style", None)
if style is None:
if multiple is None:
return d
else:
style = name
in_rollback = renpy.exports.in_rollback()
if (not in_rollback) and (not variant) and (not multiple):
return d
d = d.copy()
if isinstance(style, basestring):
if multiple is not None:
style = "block{}_multiple{}_{}".format(multiple[0], multiple[1], style)
style = getattr(renpy.store.style, style)
if variant is not None:
style = style[variant]
if in_rollback:
style = style["rollback"]
d["style"] = style
return d
who_args = style_args(who_args, "who")
what_args = style_args(what_args, "what")
window_args = style_args(window_args, "window")
rv = dict(properties)
for prefix in renpy.config.character_id_prefixes:
rv[prefix] = style_args(properties.get(prefix, {}), prefix)
rv["window"] = window_args
rv["what"] = what_args
rv["who"] = who_args
return rv
def show_display_say(who, what, who_args={}, what_args={}, window_args={},
image=False, side_image=None, two_window=False,
two_window_vbox_properties={},
who_window_properties={},
say_vbox_properties={},
transform=None,
variant=None,
screen=None,
layer=None,
properties={},
multiple=None,
retain=None,
**kwargs):
"""
This is called (by default) by renpy.display_say to add the
widgets corresponding to a screen of dialogue to the user. It is
not expected to be called by the user, but instead to be called by
display_say, or by a function passed as the show_function argument
to Character or display_say.
@param who: The name of the character that is speaking, or None to
not show this name to the user.
@param what: What that character is saying. Please not that this
may not be a string, as it can also be a list containing both text
and displayables, suitable for use as the first argument of ui.text().
@param who_args: Additional keyword arguments intended to be
supplied to the ui.text that creates the who widget of this dialogue.
@param what_args: Additional keyword arguments intended to be
supplied to the ui.text that creates the what widget of this dialogue.
@param window_args: Additional keyword arguments intended to be
supplied to the ui.window that creates the who widget of this
dialogue.
@param image: If True, then who should be interpreted as an image
or displayable rather than a text string.
@param kwargs: Additional keyword arguments should be ignored.
`retain`
If not None, the screen should be retained (not transient),
and the screen should be given the value of this argument as
its tag.
This function is required to return the ui.text() widget
displaying the what text.
"""
props = compute_widget_properties(who_args, what_args, window_args, properties, variant=variant, multiple=multiple)
def handle_who():
if who:
if image:
renpy.ui.add(renpy.display.im.image(who, loose=True, **props["who"])) #type: ignore
else:
renpy.ui.text(who, **who_args)
def merge_style(style, properties):
if isinstance(style, basestring):
style = getattr(renpy.store.style, style)
if variant is not None:
style = style[variant]
if renpy.exports.in_rollback():
style = style["rollback"]
rv = dict(style=style)
rv.update(properties)
return rv
if screen and renpy.display.screen.has_screen(screen):
if layer is None:
layer = renpy.config.say_layer
tag = screen
if retain:
tag = retain
elif multiple:
if renpy.display.screen.has_screen("multiple_" + screen):
screen = "multiple_" + screen
kwargs["multiple"] = multiple
tag = "block{}_multiple{}_{}".format(multiple[0], multiple[1], tag)
if image:
kwargs["image"] = image
if (side_image is not None) or renpy.config.old_say_args:
kwargs["side_image"] = side_image
if two_window or renpy.config.old_say_args:
kwargs["two_window"] = two_window
renpy.display.screen.show_screen(
screen,
_widget_properties=props,
_transient=not retain,
_tag=tag,
who=who,
what=what,
_layer=layer,
**kwargs)
renpy.exports.shown_window()
return (tag, "what", layer)
# Apply the transform.
if transform:
renpy.ui.at(transform)
if two_window:
# Opens say_two_window_vbox.
renpy.ui.vbox(**merge_style('say_two_window_vbox', two_window_vbox_properties))
renpy.ui.window(**merge_style('say_who_window', who_window_properties))
handle_who()
renpy.ui.window(**props["window"]) #type: ignore
# Opens the say_vbox.
renpy.ui.vbox(**merge_style('say_vbox', say_vbox_properties))
if not two_window:
handle_who()
rv = renpy.ui.text(what, **props["what"]) #type: ignore
# Closes the say_vbox.
renpy.ui.close()
if two_window:
# Closes the say_two_window_vbox.
renpy.ui.close()
if side_image:
renpy.ui.image(side_image)
renpy.exports.shown_window()
return rv
class SlowDone(object):
delay = None
ctc_kwargs = { }
last_pause = True
no_wait=False
def __init__(self, ctc, ctc_position, callback, interact, type, cb_args, delay, ctc_kwargs, last_pause, no_wait):
self.ctc = ctc
self.ctc_position = ctc_position
self.callback = callback
self.interact = interact
self.type = type
self.cb_args = cb_args
self.delay = delay
self.ctc_kwargs = ctc_kwargs
self.last_pause = last_pause
self.no_wait = no_wait
def __call__(self):
if self.interact and self.delay != 0:
if renpy.display.screen.has_screen("ctc"):
if self.ctc:
args = [ self.ctc ]
else:
args = [ ]
renpy.display.screen.show_screen("ctc", *args, _transient=True, _ignore_extra_kwargs=True, **self.ctc_kwargs)
renpy.exports.restart_interaction()
elif self.ctc and self.ctc_position == "fixed":
renpy.display.screen.show_screen("_ctc", _transient=True, ctc=self.ctc)
renpy.exports.restart_interaction()
if self.delay is not None:
renpy.ui.pausebehavior(self.delay, True, voice=self.last_pause and not self.no_wait, self_voicing=self.last_pause)
renpy.exports.restart_interaction()
for c in self.callback:
c("slow_done", interact=self.interact, type=self.type, **self.cb_args)
# This is a queue for text that's going to be passed to the say behavior to
# set the AFM info.
afm_text_queue = [ ]
def display_say(
who,
what,
show_function,
interact,
slow,
afm,
ctc,
ctc_pause,
ctc_position,
all_at_once,
cb_args,
with_none,
callback,
type, # @ReservedAssignment
what_suffix,
checkpoint=True,
ctc_timedpause=None,
ctc_force=False,
advance=True,
multiple=None,
dtt=None,
retain=False):
global afm_text_queue
# Final is true if this statement should perform an interaction.
if multiple is None:
final = interact
afm_text_queue = [ ]
else:
step, total = multiple
if step == 1:
afm_text_queue = [ ]
if step == total:
final = interact
else:
final = False
interact = False
if not final:
advance = False
if final and (not renpy.game.preferences.skip_unseen) and (not renpy.game.context().seen_current(True)) and renpy.config.skipping == "fast": # type: ignore
renpy.config.skipping = None
# If we're in fast skipping mode, don't bother with say
# statements at all.
if advance and renpy.config.skipping == "fast":
for i in renpy.config.fast_skipping_callbacks:
i()
# Clears out transients.
renpy.exports.with_statement(None)
renpy.exports.checkpoint(True, hard=checkpoint)
return
# If we're not interacting, call the noniteractive_callbacks.
if interact is False:
for i in renpy.config.nointeract_callbacks:
i()
# Figure out the callback(s) we want to use.
if callback is None:
if renpy.config.character_callback:
callback = [ renpy.config.character_callback ]
else:
callback = [ ]
if not isinstance(callback, list):
callback = [ callback ]
callback = renpy.config.all_character_callbacks + callback
# Call the begin callback.
for c in callback:
c("begin", interact=interact, type=type, **cb_args)
roll_forward = renpy.exports.roll_forward_info()
if roll_forward is True:
roll_forward = False
# If we're just after a rollback or roll_forward, disable slow.
after_rollback = renpy.game.after_rollback
if after_rollback:
slow = False
all_at_once = True
# If we're committed to skipping this statement, disable slow.
elif (renpy.config.skipping and
advance and
(renpy.game.preferences.skip_unseen or # type: ignore
renpy.game.context().seen_current(True))):
slow = False
all_at_once = True
# Figure out which pause we're on. (Or set the pause to None in
# order to put us in all-at-once mode.)
if not interact or renpy.game.preferences.self_voicing: # type: ignore
all_at_once = True
extend_text = ""
# Predict extend statements, and add them to the text so that re-layout
# is not required.
if renpy.config.scry_extend:
scry = renpy.exports.scry()
if scry is not None:
scry = scry.next()
scry_count = 0
while scry and scry_count < 64:
if scry.extend_text is renpy.ast.DoesNotExtend:
break
elif scry.extend_text is not None:
extend_text += scry.extend_text
scry = scry.next()
scry_count += 1
if extend_text:
extend_text = "{done}" + extend_text
# If dialog will be extended, should parse the dialog without suffix.
if extend_text:
dtt = DialogueTextTags(what)
elif dtt is None:
dtt = DialogueTextTags(what + what_suffix)
if all_at_once:
pause_start = [ dtt.pause_start[0] ]
pause_end = [ dtt.pause_end[-1] ]
pause_delay = [ dtt.pause_delay[-1] ]
else:
pause_start = dtt.pause_start
pause_end = dtt.pause_end
pause_delay = dtt.pause_delay
exception = None
retain_tag = "_retain_0"
retain_count = -1
if retain:
while True:
retain_count += 1
retain_tag = "_retain_{}".format(retain_count)
if not renpy.exports.get_screen(retain_tag):
break
if dtt.fast:
for i in renpy.config.say_sustain_callbacks:
i()
try:
for i, (start, end, delay) in enumerate(zip(pause_start, pause_end, pause_delay)):
# True if the is the last pause in a line of dialogue.
last_pause = (i == len(pause_start) - 1)
# If we're going to do an interaction, then saybehavior needs
# to be here.
if advance:
behavior = renpy.ui.saybehavior(allow_dismiss=renpy.config.say_allow_dismiss, dialogue_pause=delay)
else:
behavior = None
# The string to show.
what_string = dtt.text
# Figure out the CTC to use, if any.
if last_pause:
what_ctc = ctc
ctc_kind = "last"
else:
if delay is not None:
what_ctc = ctc_timedpause or ctc_pause
ctc_kind = "timedpause"
else:
what_ctc = ctc_pause
ctc_kind = "pause"
ctc_kwargs = {
"ctc_kind" : ctc_kind,
"ctc_last" : ctc,
"ctc_pause" : ctc_pause,
"ctc_timedpause" : ctc_timedpause,
}
if not (interact or ctc_force):
what_ctc = None
what_ctc = renpy.easy.displayable_or_none(what_ctc)
if (what_ctc is not None) and what_ctc._duplicatable:
what_ctc = what_ctc._duplicate(None)
what_ctc._unique()
if ctc is not what_ctc:
if (ctc is not None) and ctc._duplicatable:
ctc = ctc._duplicate(None)
ctc._unique()
if delay == 0:
what_ctc = None
ctc = None
# Run the show callback.
for c in callback:
c("show", interact=interact, type=type, **cb_args)
# Create the callback that is called when the slow text is done.
slow_done = SlowDone(what_ctc, ctc_position, callback, interact, type, cb_args, delay, ctc_kwargs, last_pause, dtt.no_wait)
# Show the text.
show_args = { }
if multiple:
show_args["multiple"] = multiple
if retain:
show_args["retain"] = retain_tag
what_text = show_function(who, what_string, **show_args)
# What text is (screen, id, layer) tuple if we're using a screen.
if isinstance(what_text, tuple):
# If this is not the first pause, set the transform event to "replace".
if i != 0 and renpy.config.say_replace_event:
screen_displayable = renpy.display.screen.get_screen(what_text[0], what_text[2])
if screen_displayable is not None:
screen_displayable.set_transform_event("replace")
if not retain and not last_pause:
sls = renpy.game.context().scene_lists
sls.set_transient_prefix(what_text[2], what_text[0], "replaced")
what_text = renpy.display.screen.get_widget(what_text[0], what_text[1], what_text[2])
if not multiple:
afm_text_queue = [ what_text ]
else:
afm_text_queue.append(what_text)
if interact or what_string or (what_ctc is not None) or (behavior and afm):
if not isinstance(what_text, renpy.text.text.Text): # @UndefinedVariable
raise Exception("The say screen (or show_function) must return a Text object.")
if what_ctc:
if ctc_position == "nestled":
what_text.set_ctc(what_ctc)
elif ctc_position == "nestled-close":
what_text.set_ctc([ u"\ufeff", what_ctc, ])
if (not last_pause) and ctc:
if ctc_position == "nestled":
what_text.set_last_ctc(ctc)
elif ctc_position == "nestled-close":
what_text.set_last_ctc([ u"\ufeff", ctc, ])
if what_text.text[0] == what_string:
if extend_text:
what_text.text[0] += extend_text
# Update the properties of the what_text widget.
what_text.start = start
what_text.end = end
what_text.slow = slow
what_text.slow_done = slow_done
what_text.update()
elif renpy.config.developer:
raise Exception("The displayable with id 'what' was not given the exact contents of the what variable given to the say screen.")
if behavior and afm:
behavior.set_text(*afm_text_queue)
else:
slow = False
for c in callback:
c("show_done", interact=interact, type=type, **cb_args)
if not slow:
slow_done()
if final:
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
# This is only the case if the user has rolled forward, {nw} happens, or
# maybe in some other obscure cases.
if rv is False:
break
if isinstance(rv, (renpy.game.JumpException, renpy.game.CallException)):
raise rv
if not last_pause:
for i in renpy.config.say_sustain_callbacks:
i()
except (renpy.game.JumpException, renpy.game.CallException) as e:
exception = e
# Do the checkpoint and with None.
if final:
if not dtt.no_wait:
if exception is None:
renpy.exports.checkpoint(True, hard=checkpoint)
else:
renpy.exports.checkpoint(exception)
else:
renpy.game.after_rollback = after_rollback
if with_none is None:
with_none = renpy.config.implicit_with_none
renpy.plog(1, "before with none")
if with_none:
renpy.game.interface.do_with(None, None)
renpy.plog(1, "after with none")
for c in callback:
c("end", interact=interact, type=type, **cb_args)
if exception is not None:
raise exception
class HistoryEntry(renpy.object.Object):
"""
Instances of this object are used to represent history entries in
_history_list.
"""
# See ADVCharacter.add_history for the fields.
multiple = None
who = None
what = None
def __eq__(self, other):
if isinstance(other, type(self)):
return self.__dict__ == other.__dict__
else:
return False
def __hash__(self):
return hash(tuple(sorted(self.__dict__.items())))
def __repr__(self):
return "<History {!r} {!r}>".format(self.who, self.what)
# This is used to flag values that haven't been set by the user.
NotSet = renpy.object.Sentinel("NotSet")
# The number of multiple characters we've seen during the current
# interaction.
multiple_count = 0
class ADVCharacter(object):
"""
The character object contains information about a character. When
passed as the first argument to a say statement, it can control
the name that is displayed to the user, and the style of the label
showing the name, the text of the dialogue, and the window
containing both the label and the dialogue.
"""
# Properties beginning with what or window that are treated
# specially.
special_properties = [
'what_prefix',
'what_suffix',
'who_prefix',
'who_suffix',
'show_function',
]
voice_tag = None
properties = { }
_statement_name = None
# When adding a new argument here, remember to add it to copy below.
def __init__(
self,
name=NotSet,
kind=None,
**properties): # type: (str|None|renpy.object.Sentinel, Literal[False]|None|ADVCharacter, Any) -> None
if kind is None:
kind = renpy.store.adv
if name is not NotSet:
properties["name"] = name
# This grabs a value out of properties, and then grabs it out of
# kind if it's not set.
def v(n):
if n in properties:
return properties.pop(n)
else:
return getattr(kind, n)
# Similar, but it grabs the value out of kind.display_args instead.
def d(n): # type (str) -> Any
if n in properties:
return properties.pop(n)
else:
return kind.display_args[n] # type: ignore
self.name = v('name')
self.who_prefix = v('who_prefix')
self.who_suffix = v('who_suffix')
self.what_prefix = v('what_prefix')
self.what_suffix = v('what_suffix')
self.show_function = v('show_function')
self.predict_function = v('predict_function')
self.condition = v('condition')
self.dynamic = v('dynamic')
self.screen = v('screen')
self.mode = v('mode')
self.voice_tag = v('voice_tag')
if renpy.config.new_character_image_argument:
if "image" in properties:
self.image_tag = properties.pop("image")
else:
self.image_tag = kind.image_tag # type: ignore
else:
self.image_tag = None
self.display_args = dict(
interact=d('interact'),
slow=d('slow'),
afm=d('afm'),
ctc=renpy.easy.displayable_or_none(d('ctc')),
ctc_pause=renpy.easy.displayable_or_none(d('ctc_pause')),
ctc_timedpause=renpy.easy.displayable_or_none(d('ctc_timedpause')),
ctc_position=d('ctc_position'),
all_at_once=d('all_at_once'),
with_none=d('with_none'),
callback=d('callback'),
type=d('type'),
advance=d('advance'),
retain=d('retain'),
)
self._statement_name = properties.pop("statement_name", None)
self.properties = collections.defaultdict(dict)
if kind:
self.who_args = kind.who_args.copy()
self.what_args = kind.what_args.copy()
self.window_args = kind.window_args.copy()
self.show_args = kind.show_args.copy()
self.cb_args = kind.cb_args.copy()
for k, val in kind.properties.items():
self.properties[k] = dict(val)
else:
self.who_args = { "substitute" : False }
self.what_args = { "substitute" : False }
self.window_args = { }
self.show_args = { }
self.cb_args = { }
if not renpy.config.new_character_image_argument:
if "image" in properties:
self.show_args["image"] = properties.pop("image")
if "slow_abortable" in properties:
self.what_args["slow_abortable"] = properties.pop("slow_abortable")
prefixes = [ "show", "cb", "what", "window", "who"] + renpy.config.character_id_prefixes
split_args = [ i + "_" for i in prefixes ] + [ "" ]
split = renpy.easy.split_properties(properties, *split_args)
for prefix, dictionary in zip(prefixes, split):
self.properties[prefix].update(dictionary)
self.properties["who"].update(split[-1])
self.show_args.update(self.properties.pop("show"))
self.cb_args.update(self.properties.pop("cb"))
self.what_args.update(self.properties.pop("what"))
self.window_args.update(self.properties.pop("window"))
self.who_args.update(self.properties.pop("who"))
def copy(self, name=NotSet, **properties):
return type(self)(name, kind=self, **properties)
# This is called before the interaction.
def do_add(self, who, what, multiple=None):
return
# This is what shows the screen for a given interaction.
def get_show_properties(self, extra_properties):
"""
This merges a potentially empty dict of extra properties in with
show_function.
"""
screen = self.screen
show_args = self.show_args
who_args = self.who_args
what_args = self.what_args
window_args = self.window_args
properties = self.properties
if extra_properties:
screen = extra_properties.pop("screen", screen)
show_args = show_args.copy()
who_args = who_args.copy()
what_args = what_args.copy()
window_args = window_args.copy()
properties = collections.defaultdict(dict)
for k, v in self.properties.items():
properties[k] = v.copy()
prefixes = [ "show", "cb", "what", "window", "who"] + renpy.config.character_id_prefixes
split_args = [ i + "_" for i in prefixes ] + [ "" ]
split = renpy.easy.split_properties(extra_properties, *split_args)