This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
149 lines (120 loc) · 4.19 KB
/
main.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
from colorama import init, Fore, Back, Style, Cursor
import os
import re
import time
import custom_commands
import execute_command
import plugins
init(autoreset=True)
curdir = os.getcwd()
colors = {
"black": Fore.BLACK,
"red": Fore.RED,
"green": Fore.GREEN,
"yellow": Fore.YELLOW,
"blue": Fore.BLUE,
"magenta": Fore.MAGENTA,
"cyan": Fore.CYAN,
"white": Fore.WHITE,
}
print("Welcome to text adventure!")
print(
Fore.BLUE
+ "Check out the repo:\nhttps://github.com/RAMENtheNOODLES/text-adventure-creator"
)
print(Fore.GREEN + "┌──┬──┬─┐\n└┐┌┤┌┐│┌┘\n │││├┤│└┐\n └┘└┘└┴─┘")
print("T🖈C\nv0.0.2")
p = plugins.Plugins(colors)
cc = custom_commands.Custom_Commands()
ec = execute_command.Execute_Command()
chapters = []
c = open("story_chapters.txt", "r")
for i in c:
print(i)
chapters.append(i)
def read_story(chapter, option="story.tac"):
f = open(f"{curdir}/{chapter}/{option}", "r")
lines = f.read().split("\n")
for i in lines:
result = ec.FAE(i)
if result == "stop":
return
# Need to check for stop, plugin, run_plugin, read_story,
if not isinstance(result, str):
for k in result.keys():
if k == "plugin":
p.switch_file(result[k])
if k == "run_plugin":
p.run_plugin(result[k] if result[k] != "" else 0)
if k == "read_story":
goto_chapter = chapter
if result[k][0] == "cur":
goto_chapter = chapter
read_story(
goto_chapter,
result[k][1],
)
continue
# print(i)
if i.__contains__("`"):
continue
if i == "\n":
continue
if re.match("text, (\w*): ", i):
color = get_colors(i.split(", ")[1].split(":")[0])
# print(i.split(", ")[1].replace(":", ""))
print(color + i.split(": ")[1])
continue
if i.__contains__("text"):
print(i.split("text: ")[1])
if i.__contains__("prompt"):
choices = i.split("prompt, (")[1].split(")")[0]
destinations = i.split("> (")[1].split(")")[0].split(", ")
after_text = i.split(": ")[1]
# print(choices)
# print(destinations)
print(f"Please select from one of these choices: ({choices})")
while True:
choice = input(">")
if choice in choices.split(", "):
read_story(
chapter,
destinations[choices.split(", ").index(choice)] + ".tac",
)
return
print("That is not a valid option...")
continue
print(after_text)
if i.__contains__("wait"):
time.sleep(int(i.split("wait, ")[1].split(":")[0]))
print(i.split(": ")[1])
if i.__contains__("goto > "):
d_chapter = i.split("goto > ", "")[1].split(":")[0] + ".tac"
d = i.split(": ")[1] + ".tac"
read_story(d_chapter, d)
return
if i.__contains__("goto: "):
read_story(chapter, i.split("goto: ")[1] + ".tac")
return
if i.__contains__("plugin > "):
p.switch_file(i.split("plugin > ")[1] + ".plugin")
p.run_plugin()
if re.match("stop, (\w*): (\w*)", i):
color = get_colors(i.split(", ")[1].split(":")[0])
print(color + i.split(": ")[1])
return
if re.match("stop: (\w*)", i):
print(i.split(": ")[1])
return
if i.__contains__("stop"):
return
if i.__contains__("import"):
cc.import_command(i.split("> ")[1])
for k in cc.imported.keys():
if i.__contains__(k):
cc.execute_command(i.split(" >")[0], i.split("> ")[1])
def get_colors(color_string: str) -> str:
if color_string in colors:
return colors[color_string]
return colors["white"]
read_story("beginning")