feat: verbose

This commit is contained in:
TrèsAbhi committed 2025-12-14 21:41:26 -06:00
1 parent 6830df01fa
commit 8921f84c38
1 file changed
+34 -28
@@ -11,82 +11,88 @@ function patch(change: StageParameters, base: StageParameters) {
throw new Error("Change stage number must be 1 greater than base"); throw new Error("Change stage number must be 1 greater than base");
} }
for (const attribute of change.attributes) { for (const changedAttribute of change.attributes) {
let newValue: number; let newValue: number;
switch (attribute.modifier) { switch (changedAttribute.modifier) {
case TankAttributeChange_Modifier.MODIFIER_OVERRIDE: case TankAttributeChange_Modifier.MODIFIER_OVERRIDE:
newValue = attribute.value; newValue = changedAttribute.value;
break; break;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: case TankAttributeChange_Modifier.MODIFIER_MULTIPLY:
case TankAttributeChange_Modifier.MODIFIER_ADD: case TankAttributeChange_Modifier.MODIFIER_ADD:
if (!(attribute.attribute_name in base)) { if (!(changedAttribute.attribute_name in base)) {
throw new Error( throw new Error(
`Missing attribute ${ `Missing attribute ${
TankAttributeChange_AttributeName[attribute.attribute_name] TankAttributeChange_AttributeName[changedAttribute.attribute_name]
} to modify` } to modify`
); );
} }
const oldValue = base.attributes[attribute.attribute_name]!.value; const oldValue =
base.attributes[changedAttribute.attribute_name]!.value;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: { case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
newValue = oldValue! * attribute.value; newValue = oldValue! * changedAttribute.value;
break; break;
} }
case TankAttributeChange_Modifier.MODIFIER_ADD: { case TankAttributeChange_Modifier.MODIFIER_ADD: {
newValue = oldValue! + attribute.value; newValue = oldValue! + changedAttribute.value;
break; break;
} }
default: default:
throw new Error( throw new Error(
`Unhandled modified ${ `Unhandled modified ${
TankAttributeChange_Modifier[attribute.modifier] TankAttributeChange_Modifier[changedAttribute.modifier]
}` }`
); );
} }
base.attributes[attribute.attribute_name] = { base.attributes[changedAttribute.attribute_name] = {
modifier: TankAttributeChange_Modifier.MODIFIER_OVERRIDE, modifier: TankAttributeChange_Modifier.MODIFIER_OVERRIDE,
attribute_name: attribute.attribute_name, attribute_name: changedAttribute.attribute_name,
value: newValue, value: newValue,
}; };
} }
for (const changedPenetrationGroupsUpgrade of change.penetration_groups_upgrades) { for (const changedPenetrationGroupUpgrades of change.penetration_groups_upgrades) {
if (changedPenetrationGroupsUpgrade.primary_armor.length > 0) { if (changedPenetrationGroupUpgrades.primary_armor.length > 0) {
throw new Error("Primary armor is not empty; implement this"); throw new Error("Primary armor is not empty; implement this");
} }
let basePenetrationGroupsUpgrade = base.penetration_groups_upgrades.find( let basePenetrationGroupUpgrades = base.penetration_groups_upgrades.find(
(group) => group.tank_part === changedPenetrationGroupsUpgrade.tank_part (group) => group.tank_part === changedPenetrationGroupUpgrades.tank_part
); );
if (!basePenetrationGroupsUpgrade) { if (!basePenetrationGroupUpgrades) {
basePenetrationGroupsUpgrade = PenetrationGroupUpgrade.create({ basePenetrationGroupUpgrades = PenetrationGroupUpgrade.create({
tank_part: changedPenetrationGroupsUpgrade.tank_part, tank_part: changedPenetrationGroupUpgrades.tank_part,
}); });
base.penetration_groups_upgrades.push(basePenetrationGroupsUpgrade); base.penetration_groups_upgrades.push(basePenetrationGroupUpgrades);
} }
for (const changedGroup of changedPenetrationGroupsUpgrade.penetration_groups) { for (const changedPenetrationGroup of changedPenetrationGroupUpgrades.penetration_groups) {
const baseGroup = basePenetrationGroupsUpgrade.penetration_groups.find( const basePenetrationGroup =
(baseGroup) => baseGroup.group_name === changedGroup.group_name basePenetrationGroupUpgrades.penetration_groups.find(
); (baseGroup) =>
baseGroup.group_name === changedPenetrationGroup.group_name
);
if (baseGroup) { if (basePenetrationGroup) {
if (baseGroup.common_data !== changedGroup.common_data) { if (
basePenetrationGroup.common_data !==
changedPenetrationGroup.common_data
) {
throw new Error("Common data is not the same"); throw new Error("Common data is not the same");
} }
baseGroup.armor = changedGroup.armor; basePenetrationGroup.armor = changedPenetrationGroup.armor;
} else { } else {
basePenetrationGroupsUpgrade.penetration_groups.push({ basePenetrationGroupUpgrades.penetration_groups.push({
...changedGroup, ...changedPenetrationGroup,
}); });
} }
} }