Files
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

59 lines
3.7 KiB
C

class ERR_ItemPreferenceTest : ERR_ItemPreferences
{
void ERR_ItemPreferenceTest(string path) { }
void ForgetLoaded() { m_Loaded.Clear(); }
bool Validate(array<string> records) { return Valid(records); }
}
modded class ArmaReforgerScripted
{
protected bool m_ERRItemEditDone;
protected int m_ERRItemEditFailures;
protected void ItemAssert(bool condition, string name)
{
if (!condition) m_ERRItemEditFailures++;
PrintFormat("ERR ITEM EDIT TEST: pass=%1 %2", condition, name);
}
override void OnUpdate(BaseWorld world, float timeslice)
{
super.OnUpdate(world, timeslice);
ERR_GameMode mode = ERR_GameMode.Get();
if (!Replication.IsServer() || !mode || !mode.Active() || m_ERRItemEditDone) return;
ERR_ServerItemCatalog catalog = ERR_ServerItems();
array<string> values = {}; catalog.Snapshot(mode, values, "58d0fb3206b6f859", 0);
if (!values.Contains("itemsScan=Catalog complete")) return;
m_ERRItemEditDone = true;
ERR_ServerAddonItems addon = catalog.Find("58d0fb3206b6f859");
if (!addon || addon.Items.IsEmpty()) { ItemAssert(false, "native catalog ready"); return; }
ResourceName prefab = addon.Items[0].Prefab;
string id = ERR_TerrainCatalog.Key(prefab), base = addon.Id;
ERR_ItemPreferences prefs = ERR_ItemSelections();
int initial = ERR_AutomaticEquipmentCatalog.Count(mode);
ItemAssert(initial > 0 && prefs.Allows(prefab), "default eligible pool and item allowed");
ItemAssert(prefs.Set(base, "*", false) && !prefs.Allows(prefab), "bulk disable");
int blocked = ERR_AutomaticEquipmentCatalog.Count(mode);
ItemAssert(blocked < initial, "cached pool invalidated by selection");
ItemAssert(prefs.Set(base, id, true) && prefs.Allows(prefab), "explicit enable overrides same-mod default");
ItemAssert(prefs.Preset("save", "custom_1"), "save named preset");
ItemAssert(prefs.Set(base, "*", true) && prefs.Enabled(base, id), "enable all clears item exceptions");
ItemAssert(ERR_AutomaticEquipmentCatalog.Count(mode) == initial, "enabled pool restored without reroll bias");
ItemAssert(prefs.Preset("load", "custom_1") && !prefs.Enabled(base, "0000000000000001") && prefs.Enabled(base, id), "load preset restores baseline and override");
ERR_ItemPreferences reread = new ERR_ItemPreferences();
ItemAssert(!reread.Enabled(base, "0000000000000001") && reread.Enabled(base, id), "disk reload preserves working selection");
ERR_ItemPreferenceTest missing = new ERR_ItemPreferenceTest();
missing.ForgetLoaded();
ItemAssert(missing.Allows(prefab), "missing mod rules do not apply even to shared resources");
ItemAssert(prefs.Set("0000000000000001", "*", false) && prefs.Allows(prefab), "unloaded unrelated mod rule dormant");
ItemAssert(!prefs.Preset("load", "absent") && !prefs.Preset("save", "../escape") && !prefs.Preset("save", "active"), "invalid or absent preset rejected");
ItemAssert(prefs.Preset("save", "custom_1") && prefs.Preset("delete", "custom_1") && !prefs.Preset("load", "custom_1"), "replace and delete preset");
ERR_ItemPreferences failure = new ERR_ItemPreferences("$profile:nonexistent-folder/settings.json");
int revision = failure.Revision();
ItemAssert(!failure.Set(base, "*", false) && failure.Enabled(base, id) && failure.Revision() == revision, "failed save preserves state and revision");
array<string> bad = {"active", "active|58d0fb3206b6f859|*|2"};
ItemAssert(!missing.Validate(bad), "invalid stored value rejected");
array<string> duplicate = {"active", "active|58d0fb3206b6f859|*|0", "active|58d0fb3206b6f859|*|1"};
ItemAssert(!missing.Validate(duplicate), "duplicate stored rules rejected");
ItemAssert(prefs.Set(base, "*", true), "restore test selection");
PrintFormat("ERR ITEM EDIT COMPLETE failures=%1 initial=%2 blocked=%3", m_ERRItemEditFailures, initial, blocked);
}
}