-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvehicleEffectsRandomizer.py
45 lines (33 loc) · 1.33 KB
/
vehicleEffectsRandomizer.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
from configLoader import Config
import xml.etree.ElementTree as ET
import xmlMethods as xml
import random
class VehicleEffectRandomizer:
conf: Config
explEffects = []
explNames = []
@staticmethod
def isValidExplosion(tag):
return "trackdestruction" not in tag and "empty" not in tag and ("explosion" in tag or "destruction" in tag or "crewdeath" in tag or "submersiondeath" in tag or "instantexplosion" in tag or "burnoff" in tag)
def __init__(self, seed: int, config: Config):
random.seed(seed)
self.conf = config
self.tree = ET.parse(self.conf.vehEffectsPath)
root = self.tree.getroot()
effects = root.findall("*")
for item in effects:
if self.isValidExplosion(item.tag.lower()):
self.explEffects.append(item)
self.explNames.append(item.tag)
def randomize(self):
num = 0
num_max = len(self.explEffects)
for e in self.explEffects:
num += 1
percent = round(num / num_max * 100, 1)
print(f"({percent}%) Randomizing vehicle explosion effect: {e.tag}")
idx = xml.getRandomListIndex(self.explNames, random)
e.tag = self.explNames[idx]
self.explNames.pop(idx)
def save(self):
self.tree.write(self.conf.vehEffectsPathOut)