-
Notifications
You must be signed in to change notification settings - Fork 2
/
frame_library.py
1648 lines (1513 loc) · 67 KB
/
frame_library.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
# coding: UTF-8
'''A module for a class containing functions to manipulate the trial data.'''
import functools
import inspect
import re
from catalysis_globals import (
Invalid, list_to_n_gen, key_or_value, is_object, validate_int,
int_at_least, find_subobject)
from library_aux import (
action, delay_sub, expression_pack, param, no_manual, merge_lock,
scene_only, special)
class Library(object):
'''Class that does the trial data manipulation.'''
def __init__(self, JSON, suffix_dicts, object_dict, config_dict):
self.trial = JSON
self.suffix_dicts = suffix_dicts
self.object_dict = object_dict
self.base_start = config_dict["startup"]
self.cross = self.trial["cross_examinations"][-1]
self.scene = self.trial["scenes"][-1]
self.statement_index = -1
self.pressable_indices = []
self.frame = {"merged_to_next": False}
self.location = ""
self.action_mult = {}
# talk and talk scene are separate! Each talk anchor needs a related
# anchor for the scene, even if no global scene anchor has been made.
self.anc_dict = {x: {"destination": set(), "value": {}} for x in {
"frame", "scene", "talk", "talk scene", "evidence", "profile"}}
for item, val in object_dict.items():
if val.attribute in {"profiles", "evidence"}:
attr = "profile" if val.attribute == "profiles" else (
val.attribute)
self.anc_dict[attr]["value"][item] = val.data["id"]
self.scene_dia = {}
self.check_locks = set()
self.from_object_dict = functools.partial(
is_object, object_dict=self.object_dict)
self.from_object_dict.no_manual = True
self.speaker_override = False
self.camera_override = False
self.erase_override = False
self.hide_if_no_place = False
@no_manual
def check_ev(self, item):
'''Utility function to check if the item is a profile or
evidence.'''
return self.from_object_dict(
item, {"profiles", "evidence"}, self.action_mult["bad_ev_msg"])
def autohide(self):
'''Toggles whether calling a new character automatically hides
previous characters.'''
self.hide_if_no_place = not self.hide_if_no_place
def null(self):
'''Dummy function to create a blank frame.'''
pass
def make_frame(self):
'''Add a frame.'''
# Yes, action_parameters is an array when blank, not a dict.
self.trial["frames"].append({
"id": len(self.trial["frames"]), "speaker_name": "",
"speaker_use_name": False, "speaker_id": -3, "speaker_voice": -4,
"sound": 0, "music": 0, "place": 0, "place_position": 0,
"place_transition": 0, "characters": [],
"characters_erase_previous": False, "popups": [],
"action_name": "", "action_parameters": [],
"text_colour": "white", "text_content": "", "text_speed": 1,
"hidden": False, "wait_time": 0, "merged_to_next": False,
"fade": False
})
self.frame = self.trial["frames"][-1]
self.speaker_override = False
self.camera_override = False
self.erase_override = False
@delay_sub
def dialogue(self, *argv):
r'''Add dialogue. \ is escaped, and a terminal \ signifies a
newline.'''
original_line = ", ".join(argv)
match = re.search(r"\\*$", original_line)
if match and len(match.group(0)) % 2:
original_line = original_line[:-1]
newline = "\n"
else:
newline = ""
line = original_line.replace(r"\\", "\\")
self.frame["text_content"] += (line + newline)
def popup(self, name):
'''Set a pop-up. The argument is the name of the pop-up.'''
obj = self.from_object_dict(name, {"popups"}, "Popup to display")
self.frame["popups"].append({
"popup_id": obj.data["id"], "position": 0, "mirror_effect": False})
def music(self, name=-1):
'''Play a music track. Argument is the name in playerCommands.'''
if name == -1:
self.frame["music"] = -1
else:
obj = self.from_object_dict(name, {"music"}, "Music to play")
self.frame["music"] = obj.data["id"]
def sound(self, name):
'''Play a sound. Argument is the name in playerCommands'''
obj = self.from_object_dict(name, {"sounds"}, "Sound to play")
self.frame["sound"] = obj.data["id"]
def place(self, name="black", position=False):
'''Set the place.'''
# If a position is given, disable characters implicitly changing it.
if position:
self.camera_override = True
# Otherwise, mark the new position as center.
else:
position = "center"
self.frame["place"] = self.place_exp(["val", name], kill_exp=True)[1]
if self.frame["characters"]:
raise Invalid("place post char")
pos_dict = {
"c": -1, "l": -2, "r": -3, "l2": -4, "r2": -5, "ll": -6, "rl": -7,
"lr": -8, "rr": -9, "lc": -10, "rc": -11, "center": -1,
"left": -2, "right": -3, "AAI left": -4, "AAI right": -5,
"left of left": -6, "right of left": -7, "left of right": -8,
"right of right": -9, "left of center": -10, "right of center": -11
}
self.frame["place_position"] = key_or_value(
position, pos_dict, "position")
if not self.erase_override:
self.frame["characters_erase_previous"] = True
def wait(self, time):
'''Set a wait in milliseconds. Argument is wait in miliseconds.'''
self.frame["wait_time"] = int_at_least(time, 0, "Wait time")
def hide(self):
'''Hide a frame.'''
self.frame["hidden"] = not self.frame["hidden"]
def merge(self):
'''Merge a frame with the one below.'''
self.frame["merged_to_next"] = not self.frame["merged_to_next"]
def erase(self):
'''Erases previous characters.'''
self.frame["characters_erase_previous"] = not self.frame[
"characters_erase_previous"]
self.erase_override = True
def scroll(self, scroll_type):
'''Established smooth scrolling.'''
scroll_dict = {
"none": 0, "linear": 1, "bezier": 2, "ease_in": 3, "ease_out": 4
}
self.frame["place_transition"] = key_or_value(
scroll_type, scroll_dict, "scroll type")
def speed(self, type_speed):
'''Set the type-speed from the default of one.'''
try:
type_speed = float(type_speed)
except ValueError:
raise Invalid("num", "Typing speed")
if type_speed < 0:
raise Invalid("min", "Typing speed", 0)
else:
self.frame["text_speed"] = str(type_speed)
def blip(self, keyword):
'''Set the text blips. Takes the kind of blip as argument.'''
blip_dict = {
"n": 0, "m": -1, "f": -2, "t": -3, "a": -4, "none": 0, "male": -1,
"female": -2, "type": -3, "auto": -4
}
self.frame["speaker_voice"] = key_or_value(keyword, blip_dict, "blip")
def mirror(self):
'''Activate the mirror effect.'''
try:
self.frame["characters"][-1]["mirror_effect"] = (
not self.frame["characters"][-1]["mirror_effect"])
except IndexError:
raise Invalid("pre char", "mirror")
def appear(self, keyword):
'''Set the appearance effect.'''
appear_dict = {
"n": 0, "none": 0, "l": 2, "left": 2, "r": 3, "right": 3, "f": 4, "fade": 4
}
try:
self.frame["characters"][-1]["visual_effect_appears"] = (
key_or_value(keyword, appear_dict, "appearance mode"))
except IndexError:
raise Invalid("pre char", "appear")
def disappear(self, keyword):
'''Set the disappearance effect.'''
disappear_dict = {
"n": 0, "none": 0, "a": 1, "auto": 1, "l": 2, "left": 2, "r": 3, "right": 3, "f": 4, "fade": 4
}
try:
self.frame["characters"][-1]["visual_effect_disappears"] = (
key_or_value(keyword, disappear_dict, "disappearance mode"))
except IndexError:
raise Invalid("pre char", "disappear")
def color(self, color_code):
'''Set the color. Takes as argument the hex code or string.'''
try:
int(color_code, 16)
except ValueError:
pass
else:
color_code = "#" + color_code
self.frame["text_colour"] = color_code
def sync(self, keyword):
'''Set the sync behavior. Sync, do not talk, keep talking, or auto.
Works for last character. Assumes character already set.'''
sync_dict = {"s": 0, "n": 1, "k": 2, "a": 3, "sync": 0,
"do not talk": 1, "keep talking": 2, "auto": 3}
sync_number = key_or_value(keyword, sync_dict, "sync")
try:
self.frame["characters"][-1]["sync_mode"] = sync_number
except IndexError:
raise Invalid("pre char", "sync")
def startup(self, keyword):
'''Set the start-up behavior. Is the animation skipped, during,
or before text?'''
start_dict = {
"s": 0, "d": 1, "b": 2, "skip": 0, "during": 1, "before": 2}
start_number = key_or_value(keyword, start_dict, "startup")
try:
self.frame["characters"][-1]["startup_mode"] = start_number
except IndexError:
raise Invalid("pre char", "startup")
def c_pos(self, keyword):
'''Set the character position.'''
pos_dict = {
"c": -1, "l": -2, "r": -3, "l2": -4, "r2": -5, "ll": -6, "rl": -7,
"lr": -8, "rr": -9, "lc": -10, "rc": -11, "center": -1,
"left": -2, "right": -3, "AAI left": -4, "AAI right": -5,
"left of left": -6, "right of left": -7, "left of right": -8,
"right of right": -9, "left of center": -10,
"right of center": -11
}
if not self.frame["place"]:
raise Invalid("pre place", "cPos")
pos_number = key_or_value(keyword, pos_dict, "character position")
try:
self.frame["characters"][-1]["position"] = pos_number
except IndexError:
raise Invalid("pre char", "character position")
if not self.camera_override:
self.frame["place_position"] = pos_number
def p_pos(self, keyword):
'''Set the place position. Automatic, no move, or align on
centered. Only use if place not set.'''
if self.frame["place"]:
raise Invalid("pre place", "pPos")
pos_dict = {
"a": 0, "n": -101, "ac": -100, "auto": 0, "no move": -101,
"align center": -100
}
self.frame["place_position"] = key_or_value(
keyword, pos_dict, "place position")
def speaker_name(self, name=""):
'''Set a custom name for the present speaker. Takes speaker name as
argument. With no argument, name will be the empty string.'''
self.frame["speaker_name"] = name
self.frame["speaker_use_name"] = True
def speaker_id(self, speaker=""):
'''Change the speaker ID to the ID, or null. With no argument,
goes to null. With ???, turn to ???. Could theoretically be passed
an int - no need to figure out which object it refers to.'''
if not speaker:
speaker = -3
elif speaker == "?":
speaker = -1
elif not isinstance(speaker, int):
active_object = self.from_object_dict(
speaker, {"profiles"}, "Speaker")
speaker = active_object.data["id"]
self.frame["speaker_id"] = speaker
# editor_frames_rows 996 forces this
if not self.frame["speaker_use_name"]:
if speaker == -1:
self.frame["speaker_name"] = "???"
elif speaker == -3:
self.frame["speaker_name"] = ""
else:
self.frame["speaker_name"] = (
self.trial["profiles"][speaker]["short_name"])
self.speaker_override = True
def set_sprite(self, prefix, suffix=False):
'''Sets the sprite with the given prefix and suffix.
If not suffix is given, no sprite is set.
set_character is more accurate, but the old name is kept.'''
try:
data = self.suffix_dicts[prefix]
except KeyError:
raise Invalid("unk pre", prefix)
if not suffix:
sprite_id = 0
elif suffix in data["suffix dict"]:
sprite_id = data["suffix dict"][suffix]
else:
raise Invalid("unk suff", suffix, prefix)
if not self.speaker_override or not self.frame["place"]:
self.frame["speaker_id"] = data["id"]
for char in self.frame["characters"]:
if char["profile_id"] == data["id"]:
char["sprite_id"] = sprite_id
break
else:
position = -1 if self.frame["place"] else 0
char = {
"profile_id": data["id"], "sprite_id": sprite_id,
"sync_mode": 3, "startup_mode": self.base_start,
"position": position, "mirror_effect": False,
"visual_effect_appears": 0,
"visual_effect_disappears": 1,
}
self.frame["characters"].append(char)
if not self.camera_override:
self.frame["place_position"] = char["position"]
if self.hide_if_no_place and not self.frame["place"] and (
not self.erase_override) and sprite_id:
self.frame["characters_erase_previous"] = True
def fade(self, fadetype, color, time, place):
fadetype_dict = {"in": 0, "out": 1}
fadetype = key_or_value(
fadetype, fadetype_dict, "fade type")
fadeplace_dict = {"bg": 0, "bgchar": 1, "nottext": 2, "all": 3}
place = key_or_value(
place, fadeplace_dict, "fade place")
time = int_at_least(time, 0, "Fade duration")
try:
int(color, 16)
except ValueError:
pass
else:
color = "#" + color
fade = {"fade_type": fadetype, "fade_colour": color, "fade_duration": time, "fade_placement": place}
self.frame["fade"] = fade
@special
def ce_start(self):
'''Start a cross-examination. Structure is
Testimony->Assistant->Press->Failure.'''
self.location = "ceStart"
self.frame["wait_time"] = 1
self.frame["action_name"] = "CEStart"
self.frame["action_parameters"] = {}
ce_id = self.cross["id"] if self.cross else 0
self.trial["cross_examinations"].append({
"id": ce_id + 1, "start": self.frame["id"], "end": 0,
"cocouncil_start": 0, "cocouncil_end": 0, "statements": [],
"failure_conv_start": 0, "failure_conv_end": 0})
self.cross = self.trial["cross_examinations"][-1]
self.make_frame()
@special
def ce_statement(self, skip=False):
'''Create a cross-examination statement.'''
self.location = "ceStatement"
self.statement_index += 1
if not skip:
self.pressable_indices.append(self.statement_index)
self.frame["action_name"] = "CEStatement"
self.frame["action_parameters"] = {
"context": {"statement_desc": {
"ce_id": "val="+str(self.cross["id"]), "statement_id":
"val="+str(self.frame["id"])}}}
self.cross["statements"].append({
"id": self.frame["id"], "contradictions": [],
"pressing_conv_start": 0, "pressing_conv_end": 0,
"optional_conv_start": 0, "optional_conv_end": 0})
@special
def assist(self):
'''Start an assistant conversation.'''
self.statement_index = -1
self.location = "assist"
self.frame["wait_time"] = 1
self.cross["cocouncil_start"] = self.frame["id"]
self.frame["action_name"] = "CEPause"
self.frame["action_parameters"] = {}
self.make_frame()
@no_manual
def assist_end(self):
'''End the assistant conversation.'''
self.frame["wait_time"] = 1
self.cross["cocouncil_end"] = self.frame["id"]
self.frame["action_name"] = "CERestart"
self.frame["action_parameters"] = {
"context": {"ce_desc": "val="+str(self.cross["id"])}}
self.make_frame()
@special
def press(self):
'''Start a press conversation.'''
try:
# Run the end function for the last block.
{"assist": self.assist_end, "press": self.press_end}[
self.location]()
except KeyError:
raise Invalid("valid fail", "press", self.location)
self.location = "press"
self.frame["wait_time"] = 1
try:
index = self.pressable_indices[0]
except IndexError:
raise Invalid("excess press")
self.cross["statements"][index]["pressing_conv_start"] = (
self.frame["id"])
self.frame["action_name"] = "CEPause"
self.frame["action_parameters"] = {}
self.make_frame()
@no_manual
def press_end(self):
'''End a press conversation. Must be used before a new press
conversation begins.'''
index = self.pressable_indices.pop(0)
self.frame["wait_time"] = 1
self.cross["statements"][index]["pressing_conv_end"] = (
self.frame["id"])
self.cross["end"] = self.frame["id"]
self.frame["action_name"] = "CEReturnAfter"
self.frame["action_parameters"] = {
"context": {"statement_desc": {
"ce_id": "val="+str(self.cross["id"]), "statement_id":
"val=" + str(self.cross["statements"][index]["id"])}}}
self.make_frame()
@special
def fail(self):
'''Start the cross-examination fail conversation.'''
try:
{"assist": self.assist_end, "press": self.press_end}[
self.location]()
except KeyError:
raise Invalid("valid fail", "fail", self.location)
self.location = "fail"
if self.pressable_indices:
raise Invalid(
"inadequate press", "start fail conversation",
len(self.pressable_indices))
self.frame["wait_time"] = 1
self.cross["failure_conv_start"] = self.frame["id"]
self.frame["action_name"] = "CEPause"
self.frame["action_parameters"] = {}
self.make_frame()
@no_manual
def fail_end(self):
'''End a fail conversation, and the cross-examination.'''
self.frame["wait_time"] = 1
self.cross["end"] = self.frame["id"]
self.cross["failure_conv_end"] = self.frame["id"]
self.frame["action_name"] = "CERestart"
self.frame["action_parameters"] = {
"context": {"ce_desc": "val="+str(self.cross["id"])}}
self.make_frame()
@special
def ce_end(self):
'''End the cross-examination'''
self.cross["end"] = self.frame["id"]
try:
{"assist": self.assist_end, "press": self.press_end,
"fail": self.fail_end}[self.location]()
except KeyError:
raise Invalid("valid fail", "ceEnd", self.location)
if self.pressable_indices:
raise Invalid(
"inadequate press", "end cross examination",
len(self.pressable_indices))
self.location = ""
@special
def contra(self, item, dest_anc):
'''Create a contradiction. Arguments are object to present and
destination anchor.'''
contra_ev = self.from_object_dict(
item, {"profiles", "evidence"}, "Contradictory item")
contras = self.cross["statements"][-1]["contradictions"]
type_dict = {"type": contra_ev.attribute, "id": contra_ev.data["id"]}
for contra in contras:
if contra["contrad_elt"] == type_dict:
raise Invalid("mult contra", item)
self.anc_dict["frame"]["destination"].add((
"cross_examinations", self.cross["id"], "statements",
self.statement_index, "contradictions", len(contras),
"destination"))
contras.append({"contrad_elt": type_dict, "destination": dest_anc})
def anc(self, point):
'''Set an anchor. Point is the 'anchor phrase.' Anchor can be used in
any frame with dialogue.'''
if point in self.anc_dict["frame"]["value"]:
raise Invalid("anc dupl", point)
self.anc_dict["frame"]["value"][point] = self.frame["id"]
@special
def sce_intro(self, name="", hidden=False):
'''Start the scene. Arguments are scene name and if hidden.
This command writes multiple frames.'''
self.location = "sceIntro"
self.frame["wait_time"] = 1
self.frame["action_name"] = "SceneStart"
hidden = bool(hidden)
sce_id = self.scene["id"] if self.scene else 0
self.trial["scenes"].append({
"id": sce_id + 1, "name": name, "hidden": hidden,
"dialogues": [{
"id": 1, "start": 0, "main": 0, "talk": 0, "present": 0, "end":
0, "intro_start": 0, "intro_end": 0, "talk_topics": [],
"present_conversations": [], "locks":None}],
"current_dialogue": 1, "examinations": [],
"current_examination": 1, "start": self.frame["id"],
"move": 0, "end": 0, "move_list": []})
self.scene = self.trial["scenes"][-1]
self.frame["action_parameters"] = {"context": {"scene": {
"scene_type": "val=scenes",
"scene_id": "val="+str(self.scene["id"])}}}
self.make_frame()
self.frame["action_name"] = "GoTo"
# Missing action_parameters is accounted for in sceMain.
self.frame["wait_time"] = 1
self.frame["hidden"] = 1
self.scene = self.trial["scenes"][-1]
self.scene_dia = self.scene["dialogues"][0]
self.scene_dia["start"] = self.frame["id"]
self.scene_dia["intro_start"] = self.frame["id"]
self.make_frame()
self.frame["action_name"] = "RevealFrame"
self.frame["action_parameters"] = {"multiple": {"frame": [{
"target": "val="+str(self.frame["id"]-1)}]}}
self.frame["wait_time"] = 1
self.make_frame()
@special
def sce_main(self, anc=""):
'''Ends the introduction conversation and creates the scene
interface.'''
self.location = "sceMain"
self.frame["action_name"] = "GoTo"
# Missing action_parameters is accounted for after make_frame.
self.frame["wait_time"] = 1
self.scene_dia["intro_end"] = self.frame["id"]
self.make_frame()
self.scene_dia["main"] = self.frame["id"]
self.trial["frames"][self.scene_dia["start"]][
"action_parameters"] = (
{"global": {"target": "val="+str(self.frame["id"])}})
self.trial["frames"][self.scene_dia["intro_end"]][
"action_parameters"] = (
{"global": {"target": "val="+str(self.frame["id"])}})
self.frame["action_name"] = "DialogueMenu"
self.frame["action_parameters"] = {"context": {"dialogue": {
"scene_type": "val=scenes",
"scene_id": "val="+str(self.scene["id"]),
"section_type": "val=dialogues", "section_id": "val=1"}}}
if anc:
if anc in self.anc_dict["scene"]["value"]:
raise Invalid("anc dupl", anc)
self.anc_dict["scene"]["value"][anc] = self.scene["id"]
@special
def sce_talk(self):
'''Create the talk interface.'''
self.location = "sceTalk"
self.frame["action_name"] = "DialogueTalk"
self.frame["action_parameters"] = {"context": {"dialogue": {
"scene_type": "val=scenes",
"scene_id": "val="+str(self.scene["id"]),
"section_type": "val=dialogues", "section_id": "val=1"}}}
self.scene_dia["talk"] = self.frame["id"]
self.make_frame()
@special
def sce_talk_convo(self, title="", hidden=False, anc=""):
'''Start a talk option. Arguments are title for option, and if hidden,
and if anchor.'''
if self.location == "sceTalkConvo":
self.sce_talk_end()
self.location = "sceTalkConvo"
hidden = bool(hidden)
talk_id = len(self.scene_dia["talk_topics"]) + 1
self.scene_dia["talk_topics"].append({
"start": self.frame["id"], "end": 0,
"id": talk_id, "title": title,
"hidden": hidden, "icon": 0})
self.frame["wait_time"] = 1
if anc:
if anc in self.anc_dict["talk"]["value"]:
raise Invalid("anc dupl", anc)
self.anc_dict["talk"]["value"][anc] = talk_id
self.anc_dict["talk scene"]["value"][anc] = self.scene["id"]
self.make_frame()
@no_manual
def sce_talk_end(self):
'''End a talk option.'''
self.frame["action_name"] = "GoTo"
self.frame["action_parameters"] = {"global": {
"target": "val="+str(self.scene_dia["talk"])}}
self.scene_dia["talk_topics"][-1]["end"] = self.frame["id"]
self.frame["wait_time"] = 1
self.make_frame()
@special
def sce_pres(self):
'''Start a present sequence.'''
if self.location == "sceTalkConvo":
self.sce_talk_end()
self.location = "scePres"
self.frame["action_name"] = "DialoguePresent"
self.frame["action_parameters"] = {
"context": {"dialogue": {
"scene_type": "val=scenes",
"scene_id": "val="+str(self.scene["id"]),
"section_type": "val=dialogues", "section_id": "val=1"}}}
self.scene_dia["present"] = self.frame["id"]
self.make_frame()
self.sce_pres_convo()
@special
def sce_pres_convo(self, evidence=""):
'''Start an individual present. Takes name of evidence/profile as
argument.'''
self.location = "scePresConvo"
if self.scene_dia["present_conversations"]:
self.sce_pres_end()
pres_ev = self.from_object_dict(
evidence, {"profiles", "evidence"}, "Item to present")
snippet = {"type": pres_ev.attribute, "id": pres_ev.data["id"]}
for present in self.scene_dia["present_conversations"]:
if present["elt"] == snippet:
raise Invalid("mult pres", evidence)
else:
snippet = None
self.frame["wait_time"] = 1
self.scene_dia["present_conversations"].append({
"elt": snippet, "start": self.frame["id"], "end": 0})
self.make_frame()
@no_manual
def sce_pres_end(self):
'''End an individual present.'''
self.frame["action_name"] = "GoTo"
self.frame["action_parameters"] = {
"global": {"target": "val="+str(self.scene_dia["present"])}}
self.scene_dia["present_conversations"][-1]["end"] = (
self.frame["id"])
self.frame["wait_time"] = 1
self.make_frame()
@special
def sce_locks(self, *argv):
'''Start psyche-locks. Arguments are sequence of x and y, then
(optional) hidden status.'''
self.sce_pres_end()
try:
int(argv[0] if argv else "0")
hidden = False
except ValueError:
argv = argv[1:]
hidden = True
self.location = "sceLocks"
self.scene_dia["locks"] = {
"start": self.frame["id"], "end": 0, "hidden": hidden,
"locks_to_display": []}
argv = list_to_n_gen(
argv, 2, " plus one for hidden" if hidden else "")
err_msg = "Arguments to sceLocks after the optional hidden"
for index, (x_coord, y_coord) in enumerate(argv):
x_coord = validate_int(x_coord, err_msg)
y_coord = validate_int(y_coord, err_msg)
self.scene_dia["locks"]["locks_to_display"].append({
"id": index+1, "type": "jfa_lock", "x": x_coord,
"y": y_coord})
self.frame["wait_time"] = 1
self.make_frame()
@special
def sce_exam(self, place=0):
'''Initialize examinations. Takes the place to examine as argument.
Also ends psyche_locks.'''
if self.location == "scePresConvo":
self.sce_pres_end()
elif self.location == "sceLocks":
self.scene_dia["locks"]["end"] = self.frame["id"]
self.frame["wait_time"] = 1
self.frame["action_name"] = "LocksEnd"
self.frame["action_parameters"] = {"context": {
"parent_dialogue": {
"scene_type": "val=scenes", "scene_id":
"val="+str(self.scene["id"]),
"section_type": "val=dialogues", "section_id": "val=1"}}}
self.make_frame()
else:
raise Invalid("valid fail", "sceExam", self.location)
self.scene_dia["end"] = self.frame["id"]
self.make_frame()
place = self.place_exp(
["val", place], kill_exp=True)[1] if place else 0
self.frame["action_name"] = "ExaminationExamine"
self.frame["action_parameters"] = {"context": {"examination": {
"scene_type": "val=scenes",
"scene_id": "val="+str(self.scene["id"]),
"section_type": "val=examinations", "section_id": "val=1"}}}
self.scene["examinations"].append({
"id": 1, "start": self.frame["id"], "examine": self.frame["id"],
"end": 0, "place": place, "examine_conversations": [],
"deduce_conversations": [], "enable_deduction": False})
self.make_frame()
self.sce_exam_convo("dummy")
@special
def sce_exam_convo(self, exam_type, *argv):
'''Create the examination. Takes arguments for the area. You can only
avoid arguments for the default.'''
if self.location == "sceExamConvo":
self.sce_exam_end()
if exam_type == "region":
exam = self.exam_exp("val", list(argv))[1]
elif exam_type == "object":
if len(argv) != 1:
raise Invalid("bad arg num", "sceExamConvo")
place_id = self.scene["examinations"][-1]["place"]
place, bg_fg_obj = self.bg_fg_obj_exp(
["val", argv[0]], ["val", int(place_id)])
exam = {
"place_id": place[1],
"layer": bg_fg_obj[1], "id": bg_fg_obj[2]
}
else:
raise Invalid("bad exam type", exam_type, "region, object")
exam_dict = {
"start": self.frame["id"], "end": 0,
"area": exam}
else:
exam_dict = {"area": None, "start": self.frame["id"], "end": 0}
self.location = "sceExamConvo"
self.frame["wait_time"] = 1
self.scene["examinations"][0]["examine_conversations"].append(
exam_dict)
self.make_frame()
@no_manual
def sce_exam_end(self):
'''End the examination.'''
self.scene["examinations"][0][
"examine_conversations"][-1]["end"] = self.frame["id"]
self.frame["action_name"] = "GoTo"
self.frame["action_parameters"] = {
"global": {"target": "val="+str(self.scene["examinations"][0][
"start"])}}
self.frame["wait_time"] = 1
self.make_frame()
@special
def sce_move(self, *argv):
'''Handle deduction frames, end the investigation block, and go into
sceMove.'''
self.sce_exam_end()
self.location = ""
self.frame["wait_time"] = 1
dedu_dict = {"area": None, "elt": None, "start": self.frame["id"],
"end": 0}
self.scene["examinations"][0]["deduce_conversations"].append(dedu_dict)
self.make_frame()
self.scene["examinations"][0]["deduce_conversations"][-1]["end"] = (
self.frame["id"])
self.frame["action_name"] = "GoTo"
self.frame["action_parameters"] = {
"global": {"target": "val="+str(
self.scene["examinations"][0]["start"])}}
self.frame["wait_time"] = 1
self.make_frame()
self.frame["wait_time"] = 1
self.scene["examinations"][0]["end"] = self.frame["id"]
self.make_frame()
self.frame["action_name"] = "SceneMove"
self.frame["action_parameters"] = {
"context": {"scene": {"scene_type": "val=scenes", "scene_id":
"val="+str(self.scene["id"])}}}
self.scene["move"] = self.frame["id"]
self.scene["end"] = self.frame["id"]
object_gen = list_to_n_gen(argv, 2)
for i, j in object_gen:
self.anc_dict["scene"]["destination"].add((
"scenes", self.scene["id"], "move_list",
len(self.scene["move_list"]), "scene_id"))
self.scene["move_list"].append({
"scene_type": "scenes", "scene_id": i, "name_override": j})
self.make_frame()
@action({"type": "ev_pos", "bad_ev_msg": "Item to display"})
def disp_ev(self):
'''Display evidence. Arguments are evidence name and position as
coded.'''
self.frame["action_name"] = "DisplayElements"
self.frame["action_parameters"] = {"multiple": {"element": []}}
@action({"type": "ev", "bad_ev_msg": "Item to hide"})
def hide_ev(self):
'''Hide evidence. Argument is evidence name.'''
self.frame["action_name"] = "HideElements"
self.frame["action_parameters"] = {"multiple": {"element": []}}
@action({"type": "ev", "bad_ev_msg": "Item to reveal"})
def rev_ev(self):
'''Reveal evidence. Argument is evidence name.'''
self.frame["action_name"] = "RevealElements"
self.frame["action_parameters"] = {"multiple": {"element": []}}
@no_manual
def over_proceed_helper(self, *argv):
'''Helper function for game overs and proceed to frame. Handles the
action parameters.'''
frame, = expression_pack(argv, (1,))
self.frame["action_parameters"] = {
"context": {"not_merged": "val=true"},
"global": {"target": param(frame, 1)}}
self.frame_exp(("global", "target"))
@merge_lock
@action()
def set_over(self, *argv):
'''Make a game over redirect. Argument is an anchor.'''
self.frame["action_name"] = "SetGameOver"
self.over_proceed_helper(*argv)
@merge_lock
@action()
def proceed(self, *argv):
'''Make a proceed command. Argument is an anchor.'''
self.frame["action_name"] = "GoTo"
self.over_proceed_helper(*argv)
@action({"type": "frame"})
def hide_frame(self):
'''Hide a frame. Arguments are anchors.'''
self.frame["action_name"] = "HideFrame"
self.frame["action_parameters"] = {"multiple": {"frame": []}}
@action({"type": "frame"})
def rev_frame(self):
'''Reveal a frame. Arguments are anchors.'''
self.frame["action_name"] = "RevealFrame"
self.frame["action_parameters"] = {"multiple": {"frame": []}}
@merge_lock
@action()
def game_over(self, *argv):
'''End the game. First command tells which end state to go. If 'next'
or 'another' end state, supply data-transfer type. If 'another,' also
supply target part and frame IDs.'''
self.frame["action_name"] = "GameOver"
self.frame["action_parameters"] = {
"context": {"not_merged": "val=true"}, "global": {"action": ""}}
data_dict = {"none": "0", "var": "1", "full": "2"}
parsed_exp = expression_pack(argv, (1, 1, 1, 1), pad=True)
insert = self.frame["action_parameters"]["global"]
# If we don't need all four variables...
if all([x[0] == "val" for x in parsed_exp]) and (
parsed_exp[0][1] != "another"):
# End the game now is simple!
if parsed_exp[0][1] == "end":
insert["action"] = "val=0"
# But if we go to the next part, which data transfers over?
elif parsed_exp[0][1] == "next":
data = parsed_exp[1]
if not data[1]:
raise Invalid("arg missing", "Data to transfer")
data[1] = key_or_value(
data[1], data_dict, "game over transfer data", True)
insert["action"] = "val=1"
insert["data_transfer"] = param(data, 1)
# Any other case is a problem in the script.
else:
raise Invalid("bad key", parsed_exp[0][1], "target part")
# If we do need all four variables...
else:
# Let's rule out any bad types for the first argument...
if parsed_exp[0][0] == "val" and parsed_exp[0][1] not in {
"end", "next", "another"}:
raise Invalid("bad key", parsed_exp[0][1], "target part")
# ...and handle the good types now, unless we're in advanced mode.
elif parsed_exp[0][0] == "val":
proceed_dict = {"end": "0", "next": "1", "another": "2"}
parsed_exp[0] = (parsed_exp[0][0], key_or_value(
parsed_exp[0][1], proceed_dict, "proceed", True))
# We expect all data, so let's make sure we have it.
if not parsed_exp[1][1]:
raise Invalid("arg missing", "Data to transfer")
if not parsed_exp[2][1]:
raise Invalid("arg missing", "Target part")
if not parsed_exp[3][1]:
raise Invalid("arg missing", "Target frame")
# Convert the data-to-transfer to a number...
if parsed_exp[1][0] == "val":
parsed_exp[1][1] = key_or_value(
parsed_exp[1][1], data_dict, "game over transfer data",
True)
# And now we fill the insertion dict!
insert["action"] = param(parsed_exp[0], 1)
insert["data_transfer"] = param(parsed_exp[1], 1)
insert["target_part"] = param(parsed_exp[2], 1)
insert["target_frame"] = param(parsed_exp[3], 1)
@action({"type": "bg_obj"})
def hide_obj(self):
'''Hide an object. Arguments are place name and object name.'''
self.frame["action_name"] = "HideObject"
self.frame["action_parameters"] = {"multiple": {"object": []}}
@action({"type": "bg_obj"})
def rev_obj(self):
'''Reveal an object. Arguments are place name and object name.'''
self.frame["action_name"] = "RevealObject"
self.frame["action_parameters"] = {"multiple": {"object": []}}
@no_manual
def hide_rev_sce_helper(self, *argv):
'''Helper function for revealing and hiding scenes. Handles the
action parameters.'''
scene, = expression_pack(argv, (2,))
scene = self.scene_exp(scene, ("global", "scene", "scene_id"))
self.frame["action_parameters"] = {
"global": {
"scene": {
"scene_type": param(scene, 1),
"scene_id": param(scene, 2)
}
}
}
@action()
def hide_sce(self, *argv):
'''Hide scene. Argument is scene anchor.'''
self.frame["action_name"] = "HideScene"
self.hide_rev_sce_helper(*argv)
@action()
def rev_sce(self, *argv):
'''Reveal scene. Argument is scene anchor.'''
self.frame["action_name"] = "RevealScene"
self.hide_rev_sce_helper(*argv)
@no_manual
def intro_helper(self, *argv):
'''Helper function for setting introduction conversations. Handles
action parameters.'''
# It's perfectly safe to use expression_pack here, since this is
# only ever called for global arguments, not multiple.
dialogue, = expression_pack(argv, (4,))
dialogue = self.dialogue_exp(
dialogue, ("global", "scene", "scene_id"),
("global", "dialogue", "scene_id"))
self.frame["action_parameters"] = {"global": {
"scene": {"scene_type": param(dialogue, 1),
"scene_id": param(dialogue, 2)},
"dialogue": {"scene_type": param(dialogue, 1),
"scene_id": param(dialogue, 2),
"section_type": param(dialogue, 3),
"section_id": param(dialogue, 4)}
}}
@action()
def hide_intro(self, *argv):
'''Hide intro conversation. Takes scene anchor as argument.'''
self.frame["action_name"] = "HideDialogueIntro"
self.intro_helper(*argv)
@action()
def rev_intro(self, *argv):