summaryrefslogtreecommitdiff
blob: 4ffaca43a54e8420c933a36f12cfd8fd142f3d35 (plain)
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
import argparse

import tonkadur

parser = argparse.ArgumentParser(
    description = (
        "Tonkadur Python Interpreter"
    )
)

parser.add_argument(
    '-f',
    '--file',
    dest='world_file',
    type = str,
    help = 'Wyrd JSON file to load.',
)

args = parser.parse_args()
state = tonkadur.Tonkadur(args.world_file)

#try:
while True:
    result = state.run()
    result_category = result['category']

    if (result_category == "end"):
        print("Program ended")
        break
    elif (result_category == "display"):
        print(result['content'])
    elif (result_category == "assert"):
        print("Assert failed at line " + str(result['line']) + ":" + str(result['message']))
    elif (result_category == "resolve_choices"):
        current_choice = 0;

        for choice in result['choices']:
            print(str(current_choice) + ". " + ''.join(choice[0]['content']))
            current_choice += 1

        user_choice = input("Your choice? ")
        state.resolve_choice_to(result['choices'][int(user_choice)][1])
    elif (result_category == "event"):
        print("Unhandled event:" + str(result))

#except Error:
#    print("failed.\n")
print(str(state.memory))