REFACTOR: Split into modules (controller, models, and utils)

This commit is contained in:
2025-03-15 22:50:22 +01:00
parent 37e88f063e
commit 19934aa911
12 changed files with 34 additions and 38 deletions

0
controllers/__init__.py Normal file
View File

View File

@@ -1,4 +1,4 @@
from utils import mapped_value
from utils.utils import mapped_value
import math
class ImageCoordController:

View File

@@ -1,7 +1,7 @@
# Description: This file contains the CoordinateManager class which is responsible for converting coordinates to pixels and vice versa.
import math
from utils import mapped_value
from utils.utils import mapped_value
class MapCoordController:
def __init__(self, screen_width: int, screen_height: int, map_min_x: int, map_max_x, map_min_y, map_max_y):

25
main.py Normal file
View File

@@ -0,0 +1,25 @@
from models.game import Game
from models.match import Match
from models.player import Player
def main():
import demoparser2
demo_parser = demoparser2.DemoParser("demo.dem")
game_info = demo_parser.parse_ticks(["X", "Y", "Z", "pitch", "yaw", "is_alive", "team", "player_steamid", "team_rounds_total"])
header_info = demo_parser.parse_header()
map_name = header_info['map_name']
players = demo_parser.parse_player_info()
start_tick = int(input())
m = Match(map_name, game_info)
m.tick = start_tick
for index, row in players.iterrows():
m.add_player(Player(row["name"], row["steamid"]))
game = Game(m)
game.run()
if __name__ == "__main__":
main()

0
models/__init__.py Normal file
View File

View File

@@ -1,10 +1,10 @@
import pygame
from match import Match
from player import Player
from map_coord_controller import MapCoordController
from image_coord_controller import ImageCoordController
from json_object import JSONObject
from utils import mapped_value
from models.match import Match
from models.player import Player
from controllers.map_coord_controller import MapCoordController
from controllers.image_coord_controller import ImageCoordController
from utils.json_object import JSONObject
from utils.utils import mapped_value
WIDTH, HEIGHT = 700, 700
MAP_WIDTH, MAP_HEIGHT = 1024,1024

View File

@@ -1,4 +1,4 @@
from player import Player
from models.player import Player
class Match:
def __init__(self, map_name, game_info, tick_rate=64):

View File

@@ -1,29 +0,0 @@
import demoparser2
from match import Match
from player import Player
demo_parser = demoparser2.DemoParser("demo.dem")
demo_info = demo_parser.parse_ticks(["X", "Y", "Z"])
class Parser:
def __init__(self, demo_path):
self.demo_parser = demoparser2.DemoParser(demo_path)
self.demo_info = self.demo_parser.parse_ticks(["X", "Y", "Z", "pitch", "yaw", "is_alive", "team", "player_steamid"])
self.players = self.demo_parser.parse_player_info()
if __name__ == "__main__":
parser = Parser("demo.dem")
match = Match("de_dust2", parser.demo_info)
for index, row in parser.players.iterrows():
match.add_player(Player(row["name"], row["steamid"]))
while match.tick < match.max_tick:
match.next_tick()

0
utils/__init__.py Normal file
View File