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 pathplugins.py
141 lines (119 loc) · 4.16 KB
/
plugins.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
from colorama import init, Fore, Back, Style, Cursor
import os
import re
import time
init(autoreset=True)
curdir = os.getcwd()
class Plugins:
def __init__(self, mColors, file="example.plugin"):
self.colors = mColors
self.store = []
self.file = str(file)
def switch_file(self, file):
self.file = file
return
def run_plugin(self, linenum=0):
f = open(f"{curdir}/plugins/{self.file}", "r")
lines = f.read().split("\n")
for i in lines:
if len(self.store) > 0:
# print(*self.store)
for k in self.store:
self.execute(k, lines)
self.store = []
continue
self.execute(i, lines)
def execute(self, line, lines):
file = self.file
i = line
if i.__contains__("`"):
return "comment"
if i.__contains__("func"):
return "function"
if i.__contains__("\t") or i.__contains__(" "):
return "inside of function"
if re.match("text, (\w*): ", i):
# print(i)
color = self.get_colors(i.split(", ")[1].split(":")[0])
# print(i.split(", ")[1].replace(":", ""))
print(color + i.split(": ")[1])
return "text-color"
if i.__contains__("text: "):
print(i)
print(i.split("text: ")[1])
return "text"
if i.__contains__("run > "):
func_name = i.split("run > ")[1]
self.get_function(lines, func_name)
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(">")
# print(len(lines))
if choice.lower() in choices.lower().split(", "):
self.get_function(lines, choice.lower())
return
print("That is not a valid option...")
continue
print(after_text)
return "prompt"
if i.__contains__("wait"):
time.sleep(int(i.split("wait, ")[1].split(":")[0]))
print(i.split(": ")[1])
return "wait"
if i.__contains__("goto > "):
d_chapter = i.split("goto > ", "")[1].split(":")[0] + ".tac"
d = i.split(": ")[1] + ".tac"
read_story(d_chapter, d)
return "goto-chapter"
if i.__contains__("goto: "):
read_story(chapter, i.split("goto: ")[1] + ".tac")
return "goto"
if re.match("stop, (\w*): (\w*)", i):
color = self.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
def get_function(self, lines: list, func_name: str):
for k in range(len(lines)):
if lines[k] == f"func {func_name.lower()} " + "{":
pluginstr = ""
for j in lines:
pluginstr += j + "\n"
# print(lines[k])
function = pluginstr.split("func " + func_name + " {")[1].split("}")[0]
# print(function)
for j in function.replace(" ", "").split("\n"):
# print(f"J: {j}")
if j != "\n":
self.store.append(j)
return
def get_colors(self, color_string: str) -> str:
if color_string in self.colors:
return self.colors[color_string]
return self.colors["white"]
"""
p = Plugins(
{
"black": Fore.BLACK,
"red": Fore.RED,
"green": Fore.GREEN,
"yellow": Fore.YELLOW,
"blue": Fore.BLUE,
"magenta": Fore.MAGENTA,
"cyan": Fore.CYAN,
"white": Fore.WHITE,
},
"example.plugin",
)
p.run_plugin()
"""