Files
wicked-quest/src/stat_tracker.py
2025-03-21 20:54:13 -04:00

45 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
class StatTracker:
def __init__(self):
# Base dictionary for tracking stats
self.total = {
'Bone dust': 0,
'Enemies killed': 0,
'Coffins broken': 0,
'Items collected': 0,
'Total time': 0
}
# Create level stats from total (shallow copy is fine here)
self.level = self.total.copy()
self.total['levelsCompleted'] = 0
def reset_level(self):
"""Reset level stats based on variable type"""
for key in self.level:
if isinstance(self.level[key], (int, float)):
self.level[key] = 0
elif isinstance(self.level[key], str):
self.level[key] = ""
elif isinstance(self.level[key], list):
self.level[key] = []
elif self.level[key] is None:
self.level[key] = None
def update_stat(self, statName, value=1, levelOnly=False):
"""Update a stat in both level and total (unless levelOnly is True)"""
if statName in self.level:
self.level[statName] += value
if not levelOnly and statName in self.total:
self.total[statName] += value
def get_level_stat(self, statName):
"""Get a level stat"""
return self.level.get(statName, 0)
def get_total_stat(self, statName):
"""Get a total stat"""
return self.total.get(statName, 0)