forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGUI_CommandRecorder.py
198 lines (152 loc) · 7.13 KB
/
GUI_CommandRecorder.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from CommandRecorder import CommandRecorder
from tkinter import *
from tkinter.ttk import *
from AcademyBot import AcademyBot
from TekkenGameState import TekkenGameState
from _TekkenBotLauncher import TekkenBotLauncher
from NotationParser import ParseMoveList
from BotData import BotBehaviors
import win32.user32 as user32
import movelist
import xml.etree.ElementTree as ET
class GUI_CommandRecorder(AcademyBot):
def __init__(self, bot_commands):
super().__init__(bot_commands)
self.GUI_Recorder = Toplevel()
self.GUI_Recorder.wm_title("Command Recorder")
self.GUI_Recorder.geometry(str(500) + 'x' + str(200))
self.recorder = None
self.recording = False
self.playback = False
#self.launcher = TekkenBotLauncher(AcademyBot, True)
self.gameState = None
#Command label
self.InputLabel = Label(self.GUI_Recorder, text="Command")
self.InputLabel.grid(row=0, column=0, padx=5, pady=5)
#Command Input Box
self.InputBox = Text(self.GUI_Recorder, height=3, width=50)
self.InputBox.grid(row=0, column=1, columnspan=2, padx=5, pady=5)
#Record Button
self.RecordButtonText = StringVar()
self.RecordButtonText.set("Record")
self.RecordBtn = Button(self.GUI_Recorder, textvariable=self.RecordButtonText, command=self.recordCallback)
self.RecordBtn.grid(row=1, column=0, columnspan=1, padx=5, pady=5)
#Test Button
self.TestBtn = Button(self.GUI_Recorder, text="Test Command", command=self.testCallback)
self.TestBtn.grid(row=1, column=1, padx=5, pady=5)
#Save Button
self.SaveBtn = Button(self.GUI_Recorder, text="Save Movelist", command=self.saveMovelist)
self.SaveBtn.grid(row=1, column=2, padx=5, pady=5)
#Move Name Label
self.MoveNameLabel = Label(self.GUI_Recorder, text="Move Names")
self.MoveNameLabel.grid(row=2, column=0, padx=5, pady=5)
self.MoveNameBox = Text(self.GUI_Recorder, height=3, width=50)
self.MoveNameBox.grid(row=2, column=1, columnspan=2, padx=5, pady=5)
self.testCommand = ""
self.movelistIndex = 0
self.OverlayPrefix = ""
def Update(self, gameState: TekkenGameState):
successfulUpdate = super().Update(gameState)
if(self.recording):
self.recorder.update_state()
self.checkKeyPresses()
self.movelistIds = self.Movelist.GetAllMoveIds()
self.workingMove = self.Movelist.getMoveById(self.movelistIds[self.movelistIndex])
self.overlay.WriteToOverlay(self.OverlayPrefix + ": " + self.Movelist.getMoveName(self.workingMove))
if(self.playback and self.botCommands.IsAvailable() and gameState.IsForegroundPID()):
# if self.distance > 1500:
# self.botCommands.AddCommand(self.botCommands.ForwarddashSmall())
# else:
self.botCommands.AddCommand(ParseMoveList(self.testCommand))
self.testCommand = ""
self.playback = False
def checkKeyPresses(self):
if self.DidKeyGetPressed(ord('M')):
self.testCallback()
if self.DidKeyGetPressed(user32.VK_OEM_COMMA):
self.previousWorkingMove()
if self.DidKeyGetPressed(user32.VK_OEM_PERIOD):
self.nextWorkingMove()
if self.DidKeyGetPressed(user32.VK_OEM_2):
self.recordCallback()
def updateWorkingMove(self):
self.workingMove = self.Movelist.getMoveById(self.movelistIds[self.movelistIndex])
self.InputBox.delete("1.0", END)
command = self.workingMove.find('.//command').text
if command != None:
self.InputBox.insert(END, self.workingMove.find('.//command').text)
else:
self.InputBox.insert(END, "")
def previousWorkingMove(self):
if self.movelistIndex <= 0:
self.movelistIndex = len(self.movelistIds) - 1
else:
self.movelistIndex -= 1
self.updateWorkingMove()
def nextWorkingMove(self):
if self.movelistIndex >= len(self.movelistIds) - 1:
self.movelistIndex = 0
else:
self.movelistIndex += 1
self.updateWorkingMove()
def recordCallback(self):
if not self.recording:
self.record()
else:
self.stopRecording()
def record(self):
self.recording = True
self.InputBox.delete("1.0", END)
self.MoveNameBox.delete("1.0", END)
self.RecordButtonText.set("Stop Recording")
self.recorder = CommandRecorder(self)
self.OverlayPrefix = "Recording"
def stopRecording(self):
self.recording = False
if(self.recorder != None):
playbackrecord=[]
for line in self.recorder.f.splitlines():
playbackrecord.append(line.rstrip().split(' '))
playbackrecord.append("#")
#playbackrecord = self.recorder.parser(playbackrecord)
#print(playbackrecord)
move = self.recorder.move_process(playbackrecord)
#move = playbackrecord
#print(playbackrecord)
#for i in playbackrecord:
# if i != None :
# for j in i :
# move += str(j[0]) + ', '
# move += '\n'
if(move != None):
self.InputBox.insert(END, move)
extra_info = self.recorder.extra_process()
first_line = True
for info in extra_info:
if first_line:
for type in info:
self.MoveNameBox.insert(END, type + "\t")
self.MoveNameBox.insert(END, "\n")
first_line = False
for type in info:
self.MoveNameBox.insert(END, str(info[type]) + "\t")
self.MoveNameBox.insert(END, "\n")
self.RecordButtonText.set("Record")
self.OverlayPrefix = "Stopped Recording"
def testCallback(self):
#print(ParseMoveList(self.InputBox.get("1.0", 'end-1c')))
self.playback = True
self.testCommand = self.InputBox.get("1.0", 'end-1c')
self.workingMove.find('.//command').text = self.testCommand
info_node = self.workingMove.find('.//info')
if info_node == None:
info_node = ET.SubElement(self.workingMove, "info")
info_frames = self.recorder.extra_process()
for info_frame in info_frames:
info_frame_node = ET.SubElement(info_node, "info_frame")
for info in info_frame:
n = ET.SubElement(info_frame_node, info)
n.text = str(info_frame[info])
self.OverlayPrefix = "Testing Recording"
def saveMovelist(self):
self.Movelist.Save()