Module:GameData/doc: Difference between revisions
More actions
Created page with "{{Documentation}} == Module:GameData == '''Module:GameData''' is the central JSON loader for SpiritVale’s game data. It reads four JSON pages: * Data:skills.json * Data:passives.json * Data:summons.json * Data:effects.json and turns each one into a Lua dataset that other modules (like Module:GameSkills, Module:GamePassives, Module:GameSummons, and Module:GameEffects) can use. This module is **not** meant to be called directly from..." |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Module:GameData == | == Module:GameData == | ||
| Line 14: | Line 12: | ||
and turns each one into a Lua dataset that other modules (like [[Module:GameSkills]], [[Module:GamePassives]], [[Module:GameSummons]], and [[Module:GameEffects]]) can use. | and turns each one into a Lua dataset that other modules (like [[Module:GameSkills]], [[Module:GamePassives]], [[Module:GameSummons]], and [[Module:GameEffects]]) can use. | ||
This module is | This module is '''not''' meant to be called directly from templates with <code>#invoke</code>. | ||
Instead, other Lua modules should <code>require</code> it and use the <code>load*</code> helper functions described below. | Instead, other Lua modules should <code>require</code> it and use the <code>load*</code> helper functions described below. | ||
| Line 23: | Line 21: | ||
Each JSON page is expected to have the following top-level structure: | Each JSON page is expected to have the following top-level structure: | ||
{ | |||
{ | "version": "SpiritVale-0.8.2", | ||
"schema_version": 1, | |||
"generated_at": "2025-12-12T17:24:05.807675+00:00", | |||
"records": [ | |||
{ | |||
"Name": "Some Skill", | |||
"Internal Name": "SomeSkillInternalId", | |||
"...": "other fields specific to this type" | |||
}, | |||
{ | |||
"Name": "Another Skill", | |||
"Internal Name": "AnotherSkill", | |||
"...": "more data" | |||
} | |||
] | |||
} | |||
} | |||
Key points: | Key points: | ||
* <code>version</code> – game / patch version string. | * <code>version</code> – game / patch version string. | ||
* <code>schema_version</code> – version number | * <code>schema_version</code> – JSON schema version number. | ||
* <code>generated_at</code> – timestamp when the file was generated by the external tool. | * <code>generated_at</code> – timestamp when the file was generated by the external tool. | ||
* <code>records</code> – array of objects (skills, passives, summons, effects, etc.). | * <code>records</code> – array of objects (skills, passives, summons, effects, etc.). | ||
* Each record must have an <code>"Internal Name"</code> field, used as the stable ID. | * Each record must have an <code>"Internal Name"</code> field, used as the stable ID. | ||
The exact fields inside each record depend on the data type and are handled by the type-specific modules (GameSkills, GamePassives, GameSummons, GameEffects). | The exact fields inside each record depend on the data type and are handled by the type-specific modules ([[Module:GameSkills]], [[Module:GamePassives]], [[Module:GameSummons]], [[Module:GameEffects]]). | ||
---- | ---- | ||
| Line 59: | Line 55: | ||
Every <code>load*</code> function returns the same dataset structure: | Every <code>load*</code> function returns the same dataset structure: | ||
local dataset = { | |||
local dataset = { | meta = { | ||
version = "SpiritVale-0.8.2", | |||
schema_version = 1, | |||
generated_at = "2025-12-12T17:24:05.807675+00:00", | |||
}, | |||
records = { ... }, -- array of all records from the JSON | |||
byId = { -- lookup table by "Internal Name" | |||
["SomeSkillInternalId"] = { ...record... }, | |||
["AnotherSkill"] = { ...record... }, | |||
-- etc. | |||
}, | |||
} | |||
} | |||
This makes it easy to either: | This makes it easy to either: | ||
| Line 88: | Line 82: | ||
Reads [[Data:skills.json]] and returns a dataset for all active skills. | Reads [[Data:skills.json]] and returns a dataset for all active skills. | ||
local GameData = require("Module:GameData") | |||
local GameData = require("Module:GameData") | local skills = GameData.loadSkills() | ||
local skills = GameData.loadSkills() | |||
-- Access metadata | |||
-- Access metadata | local meta = skills.meta | ||
local meta = skills.meta | |||
-- Iterate all skills | |||
-- Iterate all skills | for _, skill in ipairs(skills.records) do | ||
for _, skill in ipairs(skills.records) do | -- do something | ||
end | |||
end | |||
-- Lookup by Internal Name | |||
-- Lookup by Internal Name | local bash = skills.byId["Bash"] | ||
local bash = skills.byId["Bash"] | |||
=== <code>loadPassives()</code> === | === <code>loadPassives()</code> === | ||
| Line 108: | Line 100: | ||
Reads [[Data:passives.json]] and returns a dataset for all passive skills. | Reads [[Data:passives.json]] and returns a dataset for all passive skills. | ||
local GameData = require("Module:GameData") | |||
local GameData = require("Module:GameData") | local passives = GameData.loadPassives() | ||
local passives = GameData.loadPassives() | |||
=== <code>loadSummons()</code> === | === <code>loadSummons()</code> === | ||
| Line 117: | Line 107: | ||
Reads [[Data:summons.json]] and returns a dataset for all summons. | Reads [[Data:summons.json]] and returns a dataset for all summons. | ||
local GameData = require("Module:GameData") | |||
local GameData = require("Module:GameData") | local summons = GameData.loadSummons() | ||
local summons = GameData.loadSummons() | |||
=== <code>loadEffects()</code> === | === <code>loadEffects()</code> === | ||
| Line 126: | Line 114: | ||
Reads [[Data:effects.json]] and returns a dataset for all status effects / effects. | Reads [[Data:effects.json]] and returns a dataset for all status effects / effects. | ||
local GameData = require("Module:GameData") | |||
local GameData = require("Module:GameData") | local effects = GameData.loadEffects() | ||
local effects = GameData.loadEffects() | |||
---- | ---- | ||
| Line 144: | Line 130: | ||
Example (skills): | Example (skills): | ||
local GameData = require("Module:GameData") | |||
local GameData = require("Module:GameData") | local p = {} | ||
local p = {} | function p.infobox(frame) | ||
local id = frame.args.id | |||
function p.infobox(frame) | local skills = GameData.loadSkills() | ||
local rec = skills.byId[id] | |||
-- build and return HTML using 'rec' | |||
end | |||
return p | |||
end | |||
return p | |||
This keeps all JSON loading and parsing logic in one place, and makes it easy to update the data files each patch without changing the Lua code. | This keeps all JSON loading and parsing logic in one place, and makes it easy to update the data files each patch without changing the Lua code. | ||
Latest revision as of 19:50, 12 December 2025
Module:GameData
edit sourceModule:GameData is the central JSON loader for SpiritVale’s game data.
It reads four JSON pages:
and turns each one into a Lua dataset that other modules (like Module:GameSkills, Module:GamePassives, Module:GameSummons, and Module:GameEffects) can use.
This module is not meant to be called directly from templates with #invoke.
Instead, other Lua modules should require it and use the load* helper functions described below.
JSON format
edit sourceEach JSON page is expected to have the following top-level structure:
{
"version": "SpiritVale-0.8.2",
"schema_version": 1,
"generated_at": "2025-12-12T17:24:05.807675+00:00",
"records": [
{
"Name": "Some Skill",
"Internal Name": "SomeSkillInternalId",
"...": "other fields specific to this type"
},
{
"Name": "Another Skill",
"Internal Name": "AnotherSkill",
"...": "more data"
}
]
}
Key points:
version– game / patch version string.schema_version– JSON schema version number.generated_at– timestamp when the file was generated by the external tool.records– array of objects (skills, passives, summons, effects, etc.).- Each record must have an
"Internal Name"field, used as the stable ID.
The exact fields inside each record depend on the data type and are handled by the type-specific modules (Module:GameSkills, Module:GamePassives, Module:GameSummons, Module:GameEffects).
Return value
edit sourceEvery load* function returns the same dataset structure:
local dataset = {
meta = {
version = "SpiritVale-0.8.2",
schema_version = 1,
generated_at = "2025-12-12T17:24:05.807675+00:00",
},
records = { ... }, -- array of all records from the JSON
byId = { -- lookup table by "Internal Name"
["SomeSkillInternalId"] = { ...record... },
["AnotherSkill"] = { ...record... },
-- etc.
},
}
This makes it easy to either:
- Iterate over all records via
dataset.records, or - Grab a single record by its internal ID via
dataset.byId["Internal Name"].
Public functions
edit sourceloadSkills()
edit source
Reads Data:skills.json and returns a dataset for all active skills.
local GameData = require("Module:GameData")
local skills = GameData.loadSkills()
-- Access metadata
local meta = skills.meta
-- Iterate all skills
for _, skill in ipairs(skills.records) do
-- do something
end
-- Lookup by Internal Name
local bash = skills.byId["Bash"]
loadPassives()
edit source
Reads Data:passives.json and returns a dataset for all passive skills.
local GameData = require("Module:GameData")
local passives = GameData.loadPassives()
loadSummons()
edit source
Reads Data:summons.json and returns a dataset for all summons.
local GameData = require("Module:GameData")
local summons = GameData.loadSummons()
loadEffects()
edit source
Reads Data:effects.json and returns a dataset for all status effects / effects.
local GameData = require("Module:GameData")
local effects = GameData.loadEffects()
Usage pattern
edit sourceOther modules should:
require("Module:GameData").- Call the appropriate
load*function. - Use
.byIdfor fast lookups by internal ID. - Use
.recordswhen they need to iterate over all entries.
Example (skills):
local GameData = require("Module:GameData")
local p = {}
function p.infobox(frame)
local id = frame.args.id
local skills = GameData.loadSkills()
local rec = skills.byId[id]
-- build and return HTML using 'rec'
end
return p
This keeps all JSON loading and parsing logic in one place, and makes it easy to update the data files each patch without changing the Lua code.