-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
111 lines (92 loc) · 2.57 KB
/
player.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
# 26.07.52 Simle console player
# Python = 3.9.7
import csv
from rich import print
import parser
d = parser.Parser().parse(parser.choose_file())
moods = {
"calm": "🙂",
"yawning": "🥱",
"happy": "😀",
"sad": "🙁",
"cool": "😎",
"smart": "🤓",
"bored": "😒",
"scared": "😱",
"ashamed": "😳",
}
characters = {} # Персонажи в формате alias: (name, color)
with open('characters.csv', mode='r', encoding="utf-8") as csv_file:
# Загружаем персонажей из characters.csv
csv_reader = csv.DictReader(csv_file)
line_count = 0
for row in csv_reader:
if line_count > 0:
if row:
characters[row["alias"]] = row["name"], row["color"]
line_count += 1
csv_file.close()
opt_colors = ["red", "green", "cyan", "yellow"]
options = []
mark = "start"
line = 0
def print_line(i):
if i["author"] != "narrator":
print(moods[i["state"]]
if i["state"] in moods
else i["state"],
" [bold "+
(characters[i["author"]][1]
if i["author"] in characters
else "gray")+"]"+
(characters[i["author"]][0]
if i["author"] in characters
else i["author"]))
tags = ""
tag_pool = ""
pc = ""
for c in i["text"]:
if c == "[" and pc != "\\":
tag_pool += c
elif c == "]":
if tag_pool:
tag_pool += c
tags += tag_pool
tag_pool = ""
else:
print(tags+c, end="")
elif c == "\\":
if pc == "\\":
print(tags+c, end="")
else:
if tag_pool:
tag_pool += c
else:
print(tags+c, end="")
pc = c
def print_menu(i):
opts = []
print(":diamond_with_a_dot:", "[bold blue u]"+i["label"])
for opt in i["opts"]:
print("["+opt_colors[len(options)]+"]"+str(len(opts))+"\t"+opt["text"])
opts.append(opt["mark"])
options.append(opt["mark"])
choice = input("Введи число> ")
if choice.isdecimal():
return opts[int(choice)]
else:
return opts[0]
while True:
if line < len(d["marks"][mark]):
l = d["marks"][mark][line]
line += 1
if l["type"] == "line":
print_line(l)
input()
elif l["type"] == "menu":
mark = print_menu(l)
line = 0
else:
break
else:
break