forked from JBenda/inkcpp
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
executable file
·78 lines (66 loc) · 1.96 KB
/
Copy pathexample.py
File metadata and controls
executable file
·78 lines (66 loc) · 1.96 KB
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
#!/bin/python
importinkcpp_py
importsys
importos
story_ink='unreal_example.ink'
story_json='unreal_example.ink.json'
story_bin='unreal_example.bin'
# convert .ink / .json file to .bin file
ifnotos.path.exists(story_bin):
ifnotos.path.exists(story_json):
os.system('inklecate {}'.format(story_ink))
inkcpp_py.compile_json(story_json, story_bin)
# load story and maybe snapshot
story=inkcpp_py.Story.from_file(story_bin)
iflen(sys.argv) >1:
snap=inkcpp_py.Snapshot.from_file(sys.argv[1])
globals=story.new_globals_from_snapshot(snap)
runner=story.new_runner_from_snapshot(snap, globals)
else:
globals=story.new_globals()
runner=story.new_runner(globals)
# access global variables
print("Date: ", globals.date)
globals.date=inkcpp_py.Value("17.12.2023")
bg=globals.background.as_list();
print(bg)
bg.add('b')
print(bg)
bg.remove('a')
print(bg)
globals.background=inkcpp_py.Value(bg)
# observer examples
defob_delta(x, y):
print("from:",y,"to:",x)
globals.observe("brightness", ob_delta)
# external function with no input, but return value
defgreeting(a):
returninkcpp_py.Value("Tach")
runner.bind("GetGreeting", greeting)
# external function with no return value
defbrightness(args):
print("Set Brightness: ", args[0])
runner.bind_void("SetBrightness", brightness)
# simple story stepper
whileTrue:
whilerunner.can_continue():
print(runner.getline())
print("# tags: ", end="")
print(', '.join(runner.tags()))
ifrunner.has_choices():
print()
index=1
forcinrunner:
print(str(index) +": "+c.text())
print("\t"+', '.join(c.tags()))
index+=1
index=int(input('Select choice to continue: '))
ifindex==-1:
snap=runner.create_snapshot();
snap.write_to_file("story.snap");
break
else:
runner.choose(index-1)
else:
break
print("Finish")