Lua: Standardize record stores

This commit is contained in:
Zackhasacat 2024-03-25 13:46:23 +00:00 committed by psi29a
parent 38eb741bfd
commit 6d529835ae
12 changed files with 329 additions and 182 deletions

View file

@ -2,6 +2,7 @@ local testing = require('testing_util')
local core = require('openmw.core')
local async = require('openmw.async')
local util = require('openmw.util')
local types = require('openmw.types')
local world = require('openmw.world')
local function testTimers()
@ -87,6 +88,45 @@ local function testMWScript()
testing.expectEqual(variableStoreCount, indexCheck)
end
local function testRecordStore(store,storeName,skipPairs)
testing.expect(store.records)
local firstRecord = store.records[1]
if not firstRecord then return end
testing.expectEqual(firstRecord.id,store.records[firstRecord.id].id)
local status, _ = pcall(function()
for index, value in ipairs(store.records) do
if value.id == firstRecord.id then
testing.expectEqual(index,1,storeName)
break
end
end
end)
testing.expectEqual(status,true,storeName)
end
local function testRecordStores()
for key, type in pairs(types) do
if type.records then
testRecordStore(type,key)
end
end
testRecordStore(core.magic.enchantments,"enchantments")
testRecordStore(core.magic.effects,"effects",true)
testRecordStore(core.magic.spells,"spells")
testRecordStore(core.stats.Attribute,"Attribute")
testRecordStore(core.stats.Skill,"Skill")
testRecordStore(core.sound,"sound")
testRecordStore(core.factions,"factions")
testRecordStore(types.NPC.classes,"classes")
testRecordStore(types.NPC.races,"races")
testRecordStore(types.Player.birthSigns,"birthSigns")
end
local function initPlayer()
player:teleport('', util.vector3(4096, 4096, 867.237), util.transform.identity)
coroutine.yield()
@ -124,6 +164,7 @@ tests = {
end},
{'teleport', testTeleport},
{'getGMST', testGetGMST},
{'recordStores', testRecordStores},
{'mwscript', testMWScript},
}