Skip to content

Commit

Permalink
Add log message for number of lines parsed in load
Browse files Browse the repository at this point in the history
function and add delay in mainGameLoop
  • Loading branch information
Niceygy committed Nov 9, 2023
1 parent 17f1450 commit d9c57ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
7 changes: 5 additions & 2 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ def load(logDir):
latest_file = max(log_files, key=os.path.getmtime)
log("Opening log file " + str(latest_file), "load")
res = []
i = 0
with open(latest_file) as f:
for line in f:
line = line.strip() # Remove leading/trailing whitespace
if line: # Skip empty lines
try:
data = json.loads(line)
res.append(data)
i = i +1
except json.JSONDecodeError:
log(f"Skipping line: {line}", "load")
log("Log file parsed, " + str(i) + " lines found", "load")
res.reverse() # so that it will stop when at the latest event it recognizes
return res, len(res)
return res


def getCMDR(logs):
Expand Down Expand Up @@ -121,7 +124,7 @@ def getStation(logs):



def eventHandler(event, logLineNum):
def eventHandler(event, logLineNum=0):
"""
Event handler for journal events.
Run once per line.
Expand Down
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def updatePrecense(presence, state, start_time, cmdr):
client_id = "1170388114498392095"

def mainGameLoop():
time.sleep(1)
currently = "Loading EDDP..."
log("Starting game loop", "mainGameLoop")
currently = " "
Expand All @@ -93,7 +94,7 @@ def mainGameLoop():
j = 0
while j < len(logs):
logLineNow = logs[j]
now, logLineCount = eventHandler(logLineNow["event"], j)
now = eventHandler(logLineNow["event"], j)
log("Event: " + str(now) + " No: " + str(j), "mainGameLoop")
j += 1
if now != 1:
Expand All @@ -114,4 +115,5 @@ def mainGameLoop():

# Start the thread
icon_thread.start()
#mainGameLoop()
awaitGame()

0 comments on commit d9c57ce

Please sign in to comment.