More fixed limits (NOBJECTS, LOCSIZ) stop being fixed.
[open-adventure.git] / objsound.py
1 #!/usr/bin/env python3
2 #
3 # Enhance adventure.yaml entries with explicit object-sound properties
4 # based on Section 13 of adventure.text.
5 #
6 # When in doubt, make the code dumber and the data smarter.
7 #
8 import sys, yaml
9
10 # This is the original sound-attribute data from section 13 of adventure.text
11 section13 = (
12     (8,         3,      -1),
13     (11,        2,      -1),
14     (13,        -1,     1),
15     (14,        1,      -1),
16     (15,        2,      -1),
17     (16,        -1,     1),
18     (24,        6,      -1),
19     (31,        4,      -1),
20     (33,        3,      -1),
21     (36,        -1,     1),
22     (38,        -1,     1),
23     (41,        1,      -1),
24     (47,        -1,     1),
25     (48,        -1,     1),
26     (49,        -1,     1),
27 )
28
29
30 def genline(ml):
31     attrs = {}
32     appendme = ""
33     return out
34
35 if __name__ == "__main__":
36     with open("adventure.yaml", "r") as fp:
37         db = yaml.load(fp)
38         fp.seek(0)
39         objnames = [el[0] for el in db["object_descriptions"]]
40         objnum = 0
41         counter = -99
42         soundtrap = texttrap = None
43         while True:
44             line = fp.readline()
45             if not line:
46                 break
47             if line.startswith("- OBJ"):
48                 counter = -99;
49                 soundtrap = texttrap = None
50                 for (obj, sound, text) in section13:
51                     if obj == objnum:
52                         counter = -2    # Skip inventory and longs markup line
53                         soundtrap = None if (sound == -1) else sound 
54                         texttrap = None if (text == -1) else text 
55                         break
56                 objnum += 1
57             sys.stdout.write(line)
58             if soundtrap is not None and counter == soundtrap:
59                 sys.stdout.write("    sounds:\n")
60             if texttrap is not None and counter == texttrap:
61                 sys.stdout.write("    texts:\n")
62             counter += 1
63
64 # end