mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
debriefing polling & parsing WIP
This commit is contained in:
parent
dc303997a6
commit
51c32747b4
@ -1,4 +1,4 @@
|
||||
from userdata.debriefing_parser import *
|
||||
from userdata.debriefing import *
|
||||
from theater.conflicttheater import *
|
||||
from theater.base import *
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ class EventResultsMenu(Menu):
|
||||
self.event = event
|
||||
self.finished = False
|
||||
|
||||
wait_for_debriefing(lambda: self.process_debriefing)
|
||||
wait_for_debriefing(callback=self.process_debriefing)
|
||||
|
||||
def display(self):
|
||||
self.window.clear_right_pane()
|
||||
@ -55,12 +55,12 @@ class EventResultsMenu(Menu):
|
||||
Button(self.frame, text="Okay", command=self.dismiss).grid(columnspan=1, row=row); row += 1
|
||||
|
||||
def process_debriefing(self, debriefing: Debriefing):
|
||||
self.game.finish_event(debriefing)
|
||||
self.game.finish_event(event=self.event, debriefing=debriefing)
|
||||
self.game.pass_turn()
|
||||
|
||||
self.finished = True
|
||||
self.player_losses = debriefing.destroyed_units[self.game.player]
|
||||
self.enemy_losses = debriefing.destroyed_units[self.game.enemy]
|
||||
self.player_losses = debriefing.destroyed_units.get(self.game.player, {})
|
||||
self.enemy_losses = debriefing.destroyed_units.get(self.game.enemy, {})
|
||||
self.display()
|
||||
|
||||
def simulate_result(self, player_factor: float, enemy_factor: float, result: bool):
|
||||
|
||||
52
userdata/debriefing.py
Normal file
52
userdata/debriefing.py
Normal file
@ -0,0 +1,52 @@
|
||||
import typing
|
||||
|
||||
import json
|
||||
import threading
|
||||
import time
|
||||
import os
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
DEBRIEFING_LOG_EXTENSION = "log"
|
||||
|
||||
|
||||
class Debriefing:
|
||||
def __init__(self):
|
||||
self.destroyed_units = {} # type: typing.Dict[str, typing.Dict[str, int]]
|
||||
|
||||
@classmethod
|
||||
def parse(cls, path: str):
|
||||
with open(path, "r") as f:
|
||||
events = json.load(f)
|
||||
|
||||
return Debriefing()
|
||||
|
||||
|
||||
def debriefing_directory_location() -> str:
|
||||
return "build/debriefing"
|
||||
|
||||
|
||||
def _logfiles_snapshot() -> typing.Dict[str, float]:
|
||||
result = {}
|
||||
for file in os.listdir(debriefing_directory_location()):
|
||||
fullpath = os.path.join(debriefing_directory_location(), file)
|
||||
result[file] = os.path.getmtime(fullpath)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def _poll_new_debriefing_log(snapshot: typing.Dict[str, float], callback: typing.Callable):
|
||||
should_run = True
|
||||
while should_run:
|
||||
for file, timestamp in _logfiles_snapshot().items():
|
||||
if file not in snapshot or timestamp != snapshot[file]:
|
||||
callback(Debriefing.parse(os.path.join(debriefing_directory_location(), file)))
|
||||
should_run = False
|
||||
break
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def wait_for_debriefing(callback: typing.Callable):
|
||||
threading.Thread(target=_poll_new_debriefing_log, args=(_logfiles_snapshot(), callback)).start()
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import typing
|
||||
import json
|
||||
|
||||
|
||||
class Debriefing:
|
||||
def __init__(self):
|
||||
self.destroyed_units = {} # type: typing.Dict[str, typing.Dict[str, int]]
|
||||
|
||||
def parse(self, path: str):
|
||||
with open(path, "r") as f:
|
||||
events = json.load(f)
|
||||
|
||||
|
||||
def debriefing_directory_location() -> str:
|
||||
return "build/debrfiefing"
|
||||
|
||||
|
||||
def wait_for_debriefing(callback: typing.Callable):
|
||||
pass
|
||||
Loading…
x
Reference in New Issue
Block a user