Skip to content

Commit ea34df6

Browse files
committed
Load/Save state support.
1 parent 9ff5b4d commit ea34df6

File tree

12 files changed

+119
-2
lines changed

12 files changed

+119
-2
lines changed

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
".",
6+
"-p",
7+
"test_*.py"
8+
],
9+
"python.testing.pytestEnabled": false,
10+
"python.testing.unittestEnabled": true
11+
}

bink/native/arm64/libbink.dylib

53.4 KB
Binary file not shown.

bink/native/arm64/libbink.so

65.9 KB
Binary file not shown.

bink/native/x86_64/bink.dll

86.5 KB
Binary file not shown.

bink/native/x86_64/libbink.dylib

72 KB
Binary file not shown.

bink/native/x86_64/libbink.so

68.3 KB
Binary file not shown.

bink/story.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,40 @@ def choose_path_string(self, path: str):
136136
LIB.bink_cstring_free(err_msg)
137137
raise RuntimeError(err)
138138

139+
def save_state(self) -> str:
140+
"""Saves the current state of the story and returns it as a string.
141+
The returned state can be loaded later using load_state()."""
142+
err_msg = ctypes.c_char_p()
143+
save_string = ctypes.c_char_p()
144+
ret = LIB.bink_story_save_state(
145+
self._story,
146+
ctypes.byref(save_string),
147+
ctypes.byref(err_msg))
148+
149+
if ret != BINK_OK:
150+
err = err_msg.value.decode('utf-8')
151+
LIB.bink_cstring_free(err_msg)
152+
raise RuntimeError(err)
153+
154+
result = save_string.value.decode('utf-8')
155+
LIB.bink_cstring_free(save_string)
156+
157+
return result
158+
159+
def load_state(self, save_state: str):
160+
"""Loads a previously saved state into the story.
161+
This allows resuming the story from a saved point."""
162+
err_msg = ctypes.c_char_p()
163+
ret = LIB.bink_story_load_state(
164+
self._story,
165+
save_state.encode('utf-8'),
166+
ctypes.byref(err_msg))
167+
168+
if ret != BINK_OK:
169+
err = err_msg.value.decode('utf-8')
170+
LIB.bink_cstring_free(err_msg)
171+
raise RuntimeError(err)
172+
139173
def __del__(self):
140174
LIB.bink_story_free(self._story)
141175

inkfiles/runtime/load-save.ink

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-> back_in_london
2+
3+
=== back_in_london ===
4+
5+
We arrived into London at 9.45pm exactly.
6+
7+
* "There is not a moment to lose!"[] I declared.
8+
-> hurry_outside
9+
10+
* "Monsieur, let us savour this moment!"[] I declared.
11+
My master clouted me firmly around the head and dragged me out of the door.
12+
-> dragged_outside
13+
14+
* [We hurried home] -> hurry_outside
15+
16+
17+
=== hurry_outside ===
18+
We hurried home to Savile Row -> as_fast_as_we_could
19+
20+
21+
=== dragged_outside ===
22+
He insisted that we hurried home to Savile Row
23+
-> as_fast_as_we_could
24+
25+
26+
=== as_fast_as_we_could ===
27+
<> as fast as we could.
28+
-> END
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"inkVersion":21,"root":[[{"->":"back_in_london"},["done",{"#n":"g-0"}],null],"done",{"back_in_london":[["^We arrived into London at 9.45pm exactly.","\n",["ev",{"^->":"back_in_london.0.2.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^\"There is not a moment to lose!\"",{"->":"$r","var":true},null]}],["ev",{"^->":"back_in_london.0.3.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-1","flg":18},{"s":["^\"Monsieur, let us savour this moment!\"",{"->":"$r","var":true},null]}],"ev","str","^We hurried home","/str","/ev",{"*":".^.c-2","flg":20},{"c-0":["ev",{"^->":"back_in_london.0.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.2.s"},[{"#n":"$r2"}],"^ I declared.","\n",{"->":"hurry_outside"},{"#f":5}],"c-1":["ev",{"^->":"back_in_london.0.c-1.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.3.s"},[{"#n":"$r2"}],"^ I declared.","\n","^My master clouted me firmly around the head and dragged me out of the door.","\n",{"->":"dragged_outside"},{"#f":5}],"c-2":["^ ",{"->":"hurry_outside"},"\n",{"#f":5}]}],null],"hurry_outside":["^We hurried home to Savile Row ",{"->":"as_fast_as_we_could"},"\n",null],"dragged_outside":["^He insisted that we hurried home to Savile Row","\n",{"->":"as_fast_as_we_could"},null],"as_fast_as_we_could":["<>","^ as fast as we could.","\n","end",null]}],"listDefs":{}}

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = bink
3-
version = 0.4.0
3+
version = 0.5.0
44
author = Rafael Garcia
55
description = Runtime for Ink, a scripting language for writing interactive narrative
66
long_description = file: README.rst

0 commit comments

Comments
 (0)