-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdamageStickersRandomizer.py
51 lines (34 loc) · 1.31 KB
/
damageStickersRandomizer.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
46
47
48
49
50
51
from configLoader import Config
import xml.etree.ElementTree as ET
import xmlMethods as xml
import random
class DamageStickersRandomizer:
conf: Config
effects = []
def __init__(self, seed: int, config: Config):
random.seed(seed)
self.conf = config
self.tree = ET.parse(self.conf.dmgStickersPath)
root = self.tree.getroot()
self.effects = root.findall("*")
def randomize(self):
num = 0
num_max = len(self.effects)
for definition in self.effects:
num += 1
percent = round(num / num_max * 100, 1)
print(f"({percent}%) Randomizing damage decal: {definition.tag}")
for variant in definition.findall("*"):
if not variant.tag.startswith("variant"):
continue
scale1 = random.uniform(0.1, 4)
scale2 = scale1 + random.uniform(-0.1, 0.1)
if scale2 <= 0.02:
scale2 = 0.02
variation = random.uniform(0.1, 0.5)
element = variant.find("modelSizes")
element.text = f"{scale1} {scale2}"
element = variant.find("variation")
element.text = f"{variation}"
def save(self):
self.tree.write(self.conf.dmgStickersPathOut)