-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRLConsole.py
More file actions
174 lines (151 loc) · 7.42 KB
/
RLConsole.py
File metadata and controls
174 lines (151 loc) · 7.42 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from PySide6.QtWidgets import QMainWindow
import RLConditions
import RLDataFiles
import RLGame
import RLDebug
import global_var
from ui.ui_form_console import Ui_FormConsole
global rlConsole
class RLConsole(QMainWindow):
def __init__(self):
# 加载控制台UI
super(RLConsole, self).__init__()
self.ui = Ui_FormConsole()
self.ui.setupUi(self)
# 绑定命令选择框事件
self.ui.listCommand.itemClicked.connect(self.command_change)
# 绑定按钮事件
self.ui.buttonRun.clicked.connect(self.run_command)
self.ui.buttonDebug.clicked.connect(self.show_debug)
# 绑定输入框事件
self.ui.lineEditCoef1.textEdited.connect(self.coefficient1_edit)
self.ui.lineEditCoef2.textEdited.connect(self.coefficient2_edit)
self.ui.lineEditCoef3.textEdited.connect(self.coefficient3_edit)
# 设定参数
self.set_coefficient((None, None, None))
self.current_command_index = -1
self.coefficient_1 = ""
self.coefficient_2 = ""
self.coefficient_3 = ""
# 命令列表
self.commands_list = ['获取物品',
'玩家信息',
'设置修正',
'保存玩家信息',
'格式化数据文件',
'判断基本语句',
'判断复合语句',
'测试复合语句拆分',
'游戏页面成功率测试',
'投掷骰子测试',
'随机抽取事件',
'随机抽取藏品',
]
self.coefficients_list = [('物品序号', None, None),
(None, None, None),
("修正名称", "修正值", None),
(None, None, None),
('文件名', None, None),
('语句', None, None),
('语句', None, None),
('语句', None, None),
('当前', '需要', None),
('骰子1', '骰子2', '额外骰子'),
(None, None, None),
(None, None, None),
]
for command in self.commands_list:
self.ui.listCommand.addItem(command)
RLDebug.debug("控制台初始化完成", type='success', who=self.__class__.__name__)
def command_change(self):
self.ui.lineEditCoef1.clear()
self.ui.lineEditCoef2.clear()
self.ui.lineEditCoef3.clear()
self.current_command_index = self.ui.listCommand.currentRow()
self.set_coefficient(self.coefficients_list[self.current_command_index])
def set_coefficient(self, coefficients):
(coefficient_1, coefficient_2, coefficient_3) = coefficients
if coefficient_1 is None:
self.ui.lineEditCoef1.setVisible(False)
self.ui.labelCoef1.setVisible(False)
else:
self.ui.lineEditCoef1.setVisible(True)
self.ui.labelCoef1.setVisible(True)
self.ui.labelCoef1.setText(coefficient_1)
if coefficient_2 is None:
self.ui.lineEditCoef2.setVisible(False)
self.ui.labelCoef2.setVisible(False)
else:
self.ui.lineEditCoef2.setVisible(True)
self.ui.labelCoef2.setVisible(True)
self.ui.labelCoef2.setText(coefficient_2)
if coefficient_3 is None:
self.ui.lineEditCoef3.setVisible(False)
self.ui.labelCoef3.setVisible(False)
else:
self.ui.lineEditCoef3.setVisible(True)
self.ui.labelCoef3.setVisible(True)
self.ui.labelCoef3.setText(coefficient_3)
def run_command(self):
if self.current_command_index == -1:
RLDebug.debug("请先选择要执行的命令", type='error', who=self.__class__.__name__)
return
RLDebug.debug("开始运行序号为{}的命令{}".format(
self.current_command_index, self.commands_list[self.current_command_index]),
who=self.__class__.__name__)
if self.current_command_index == 0:
global_var.player_info.attain_item(int(self.coefficient_1))
elif self.current_command_index == 1:
global_var.player_info.print_player_info()
elif self.current_command_index == 2:
global_var.player_info.add_adjustment(self.coefficient_1, int(self.coefficient_2))
elif self.current_command_index == 3:
RLDataFiles.save_player_info()
elif self.current_command_index == 4:
RLDataFiles.reformat_data_file(self.coefficient_1)
elif self.current_command_index == 5:
RLConditions.check_logic(self.coefficient_1)
elif self.current_command_index == 6:
if RLConditions.check(RLConditions.parse_conditions(self.coefficient_1)[0]) is True:
RLDebug.debug("判断完毕,最终结果为真", type='success', who=self.__class__.__name__)
else:
RLDebug.debug("判断完毕,最终结果为假", type='success', who=self.__class__.__name__)
elif self.current_command_index == 7:
RLConditions.test_parse(RLConditions.parse_conditions(self.coefficient_1)[0], 0)
elif self.current_command_index == 8:
RLGame.rlGame.set_check_rate(int(self.coefficient_1), int(self.coefficient_2))
elif self.current_command_index == 9:
RLGame.rlGame.roll_dice(manipulate=[int(self.coefficient_1),
int(self.coefficient_2),
int(self.coefficient_3)])
elif self.current_command_index == 10:
rand_index = global_var.random_events.get_random_index()
RLDebug.debug("随机到了序号为{}的事件{}【抽取概率{}】"
.format(rand_index,
global_var.events_list[rand_index].name,
global_var.events_list[rand_index].rare), who=self.__class__.__name__)
elif self.current_command_index == 11:
rand_index = global_var.random_items.get_random_index()
RLDebug.debug("随机到了序号为{}的藏品{}【抽取概率{}】"
.format(rand_index,
global_var.items_list[rand_index].name,
global_var.items_list[rand_index].rare), who=self.__class__.__name__)
def coefficient1_edit(self):
self.coefficient_1 = self.ui.lineEditCoef1.text()
def coefficient2_edit(self):
self.coefficient_2 = self.ui.lineEditCoef2.text()
def coefficient3_edit(self):
self.coefficient_3 = self.ui.lineEditCoef3.text()
@staticmethod
def show_debug():
# 显示调试输出
RLDebug.display()
def init():
global rlConsole
rlConsole = RLConsole()
def display() -> None:
if global_var.configs.get_config('allow_command') is True:
RLDebug.debug("已打开控制台", type='success', who='RLConsole')
rlConsole.show()
else:
RLDebug.debug("没有打开控制台的权限", type='error', who='RLConsole')