forked from roguelike2d/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharacterData.py
50 lines (40 loc) · 1.7 KB
/
CharacterData.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
import json
import os
from NotationParser import ParseMoveList
from enum import Enum
class ResponseTypes(Enum):
st_punishes = 1
ws_punishes = 2
class Gameplan:
def __init__(self, json_data:dict):
self.move_index = {}
self.json_data = json_data
#print(json_data["punishes"])
self.AddDictIfExists(ResponseTypes.st_punishes)
self.AddDictIfExists(ResponseTypes.ws_punishes)
def AddDictIfExists(self, tag_name:ResponseTypes):
if tag_name.name in self.json_data:
moves = {}
for key in self.json_data[tag_name.name]:
moves[int(key)] = ParseMoveList(self.json_data[tag_name.name][key])
self.move_index[tag_name.name] = moves
def GetMoveByFrame(self, tag_name:ResponseTypes, frames:int):
if tag_name.name in self.move_index:
moves = self.move_index[tag_name.name]
for i in range(frames):
punishKey = frames - i
if punishKey in moves :
return moves[punishKey]
return None
def GetGameplan(char_id):
directory = "TekkenData/CharacterData/"
for filename in os.listdir(directory):
if filename.endswith(".txt"):
#print(os.path.join(directory, filename))
with open(os.path.join(directory, filename)) as data_file:
data = json.load(data_file)
if int(data['char_id']) == int(char_id):
print('Gameplan located: ' + str(data['name']))
return Gameplan(data)
print("Gameplan not found for char_id: " + str(char_id) + " Using default gameplan.")
return GetGameplan(-9999)