Module:ResourceData: Difference between revisions

From Against the Storm Official Wiki
m (Aeredor moved page Module:IconFilenames to Module:ResourceData without leaving a redirect: expanding the data beyond icon filenames; specializing this data file to resources)
(specialized to resources only; added inner tables to lookup both icon filename and wiki page name)
Line 1: Line 1:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Lua storage table for looking up image files based on in-game names.
-- Lua storage table for looking up wiki pages, names, and resources
-- based on in-game names. All data is in English.
--
--
-- The table contains some deconfliction, but only for spaces and just a few
-- The table contains some deconfliction, but only for spaces, apostrophes, and
-- cases of singular and plural versions.
-- some singular/plural.
-- Use in-game names for things, and help keep this table updated as the game
-- Use in-game names for things, and help keep this table updated as the game
-- is updated.
-- is updated.
Line 10: Line 11:
-- a string.lower on the argument so that the lookup table can accept any case  
-- a string.lower on the argument so that the lookup table can accept any case  
-- and still function properly. Otherwise, we would need the table to define
-- and still function properly. Otherwise, we would need the table to define
-- Berries = "Berries.png" and berries = "Berries.png" which would suck.
-- both Berries = "Berries" and berries = "Berries" which would multiply our
-- work.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------




-- for returning when REQUIRE'd by other Lua modules.
-- for returning when REQUIRE'd by other Lua modules.
local IconFilenames = {}
local ResourceData = {}




Line 25: Line 27:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------


local tableStrStrFilenames = {
-- a design decision of this table is to make the key the same as the page name.
-- (the lookup methods will automatically make it lowercase.)
-- that way, whenever .page is referenced, it can be used again to retrieve
-- the rest of the data.
local tableStrStrData = {


---------------------------------------
---------------------------------------
-- Resources
-- Resources
---------------------------------------
---------------------------------------
     -- Raw Food
     -- Raw Food
["berries"] = "Berries.png",
["berries"] = {iconfile="Berries.png", page="Berries"},
["eggs"] = "Eggs.png",
["eggs"] = {iconfile="Eggs.png", page="Eggs"},
["insects"] = "Insects.png",
["insects"] = {iconfile="Insects.png", page="Insects"},
["meat"] = "Meat.png",
["meat"] = {iconfile="Meat.png", page="Meat"},
["mushrooms"] = "Mushrooms.png",
["mushrooms"] = {iconfile="Mushrooms.png", page="Mushrooms"},
["roots"] = "Roots.png",
["roots"] = {iconfile="Roots.png", page="Roots"},
["vegetables"] = "Vegetables.png",
["vegetables"] = {iconfile="Vegetables.png", page="Vegetables"},
-- Complex Food
-- Complex Food
["biscuits"] = "Biscuits.png",
["biscuits"] = {iconfile="Biscuits.png", page="Biscuits"},
["jerky"] = "Jerky.png",
["jerky"] = {iconfile="Jerky.png", page="Jerky"},
[string.lower("PickledGoods")] = "PickledGoods.png",
["pickled goods"] = {iconfile="PickledGoods.png", page="Pickled Goods"},
["pickled goods"] = "PickledGoods.png",
["pie"] = {iconfile="Pie.png", page="Pie"},
["pie"] = "Pie.png",
["skewers"] = {iconfile="Skewers.png", page="Skewers"},
["skewers"] = "Skewers.png",
-- Building Materials
-- Building Materials
["bricks"] = "Bricks.png",
["bricks"] = {iconfile="Bricks.png", page="Bricks"},
["fabric"] = "Fabric.png",
["fabric"] = {iconfile="Fabric.png", page="Fabric"},
["planks"] = "Planks.png",
["planks"] = {iconfile="Planks.png", page="Planks"},
["parts"] = "Parts.png",
["parts"] = {iconfile="Parts.png", page="Parts"},
[string.lower("WildfireEssence")] = "Wildfire Essence.png",
["wildfire essence"] = {iconfile="Wildfire Essence.png", page="Wildfire Essence"},
["wildfire essence"] = "Wildfire Essence.png",
-- Consumable Items
-- Consumable Items
["coats"] = "Coats.png",
["coats"] = {iconfile="Coats.png", page="Coats"},
["ale"] = "Ale.png",
["ale"] = {iconfile="Ale.png", page="Ale"},
["cosmetics"] = "Cosmetics.png",
["cosmetics"] = {iconfile="Cosmetics.png", page="Cosmetics"},
["incense"] = "Incense.png",
["incense"] = {iconfile="Incense.png", page="Incense"},
["scrolls"] = "Scrolls.png",
["scrolls"] = {iconfile="Scrolls.png", page="Scrolls"},
[string.lower("TrainingGear")] = "TrainingGear.png",
["training gear"] = {iconfile="TrainingGear.png", page="Training Gear"},
["training gear"] = "TrainingGear.png",
["wine"] = {iconfile="Wine.png", page="Wine"},
["wine"] = "Wine.png",
-- Crafting Materials
-- Crafting Materials
["clay"] = "Clay.png",
["clay"] = {iconfile="Clay.png", page="Clay"},
[string.lower("CopperOre")] = "CopperOre.png",
["copper ore"] = {iconfile="CopperOre.png", page="Copper Ore"},
["copper ore"] = "CopperOre.png",
["crystalized dew"] = {iconfile="CrystalizedDew.png", page="Crystalized Dew"},
[string.lower("CrystalizedDew")] = "CrystalizedDew.png",
["grain"] = {iconfile="Grain.png", page="Grain"},
["crystalized dew"] = "CrystalizedDew.png",
["herbs"] = {iconfile="Herbs.png", page="Herbs"},
["grain"] = "Grain.png",
["leather"] = {iconfile="Leather.png", page="Leather"},
["herbs"] = "Herbs.png",
["plant fiber"] = {iconfile="PlantFiber.png", page="Plant Fiber"},
["leather"] = "Leather.png",
["reeds"] = {iconfile="Reeds.png", page="Reeds"},
["plantfiber"] = "PlantFiber.png",
["resin"] = {iconfile="Resin.png", page="Resin"},
["plant fiber"] = "PlantFiber.png",
["sparkdew"] = {iconfile="Sparkdew.png", page="Sparkdew"},
["reeds"] = "Reeds.png",
["stone"] = {iconfile="Stone.png", page="Stone"},
["reed"] = "Reeds.png",
["resin"] = "Resin.png",
["sparkdew"] = "Sparkdew.png",
["stone"] = "Stone.png",
-- Refined Crafting Materials
-- Refined Crafting Materials
["barrels"] = "Barrels.png",
["barrels"] = {iconfile="Barrels.png", page="Barrels"},
["barrel"] = "Barrels.png",
["copper bars"] = {iconfile="CopperBar.png", page="Copper Bars"},
["copperbar"] = "CopperBar.png",
["flour"] = {iconfile="Flour.png", page="Flour"},
["copper bar"] = "CopperBar.png",
["pigment"] = {iconfile="Pigment.png", page="Pigment"},
["flour"] = "Flour.png",
["pottery"] = {iconfile="Pottery.png", page="Pottery"},
["pigment"] = "Pigment.png",
["waterskins"] = {iconfile="Waterskins.png", page="Waterskins"},
["pigments"] = "Pigment.png",
["pottery"] = "Pottery.png",
["waterskins"] = "Waterskins.png",
["waterskin"] = "Waterskins.png",
-- Trade Goods
-- Trade Goods
["buildingmaterials"] = "BuildingMaterials.png",
["amber"] = {iconfile="Amber.png", page="Amber"},
["packofbuildingmaterials"] = "BuildingMaterials.png",
["ancient tablet"] = {iconfile="AncientTablet.png", page="Ancient Tablet"},
["crops"] = "Crops.png",
["pack of building materials"] = {iconfile="BuildingMaterials.png", page="Pack of Building Materials"},
["packofcrops"] = "Crops.png",
["pack of crops"] = {iconfile="Crops.png", page="Pack of Crops"},
["luxurygoods"] = "Luxury.png",
["pack of luxury goods"] = {iconfile="Luxury.png", page="Pack of Luxury Goods"},
["packofluxurygoods"] = "Luxury.png",
["pack of provisions"] = {iconfile="Provisions.png", page="Pack of Provisions"},
["provisions"] = "Provisions.png",
["pack of trade goods"] = {iconfile="TradeGoods.png", page="Pack of Trade Goods"},
["packofprovisions"] = "Provisions.png",
-- Meta resources
["tradegoods"] = "TradeGoods.png",
["artifacts"] = {iconfile="Icon MetaResource Artifact.png", page="Artifacts"},
["packoftradegoods"] = "TradeGoods.png",
["food stockpiles"] = {iconfile="Icon MetaResource FoodStockpiles.png", page="Food Stockpiles"},
["amber"] = "Amber.png",
["machinery"] = {iconfile="Icon MetaResource Machinery.png", page="Machinery"},
[string.lower("AncientTablet")] = "AncientTablet.png",
["ancient tablet"] = "AncientTablet.png",
["foodstockpiles"] = "Icon MetaResource FoodStockpiles.png",
["food stockpiles"] = "Icon MetaResource FoodStockpiles.png",
["metafood"] = "Icon MetaResource FoodStockpiles.png",
["machinery"] = "Icon MetaResource Machinery.png",
["metamachinery"] = "Icon MetaResource Machinery.png",
["artifact"] = "Icon MetaResource Artifact.png",
["artifacts"] = "Icon MetaResource Artifact.png",
[string.lower("MetaArtifact")] = "Icon MetaResource Artifact.png",
-- Fuel & Exploration
-- Fuel & Exploration
["coal"] = "Coal.png",
["coal"] = {iconfile="Coal.png", page="Coal"},
["oil"] = "Oil.png",
["oil"] = {iconfile="Oil.png", page="Oil"},
["seamarrow"] = "SeaMarrow.png",
["sea marrow"] = {iconfile="SeaMarrow.png", page="Sea Marrow"},
["sea marrow"] = "SeaMarrow.png",
["wood"] = {iconfile="Wood.png", page="Wood"},
["wood"] = "Wood.png",
["simple tools"] = {iconfile="SimpleTools.png", page="Simple Tools"},
["simpletools"] = "SimpleTools.png",
["infused tools"] = {iconfile="InfusedTools.png", page="Infused Tools"},
["simple tools"] = "SimpleTools.png",
["purging fire"] = {iconfile="PurgingFire.png", page="Purging Fire"},
["infusedtools"] = "InfusedTools.png",
}
["infused tools"] = "InfusedTools.png",
 
["purgingfire"] = "PurgingFire.png",
 
["purging fire"] = "PurgingFire.png",
 
-------------------------------------------------------------------------------
-- Main lookup functions
-- Accepts the in-game name and returns the name of the page on the wiki
-- associated with that in-game item, resource, building, etc.
-------------------------------------------------------------------------------
 
 
 
-- returns the whole data table for the specified key
-- need to run normalize function first
function ResourceData.getData(strArg)
 
-- normalize input
    local strArg = ResourceData.trimWhitespace(strArg)
-- Get it from the big table below and return it.
    return tableStrStrData[strArg]
end
 
 
 
-- simpler version if all that's needed is the iconfile.
-- error handling by the calling module is required.
function ResourceData.getIconFilename(strArg)
 
local data = getData(strArg)
-- if this particular data block doesn't have a iconfile, this will return nil
-- therefore, error handling will be necessary
return data.iconfile or nil
end
 
 
 
-- simpler version if all that's needed is the page name.
-- error handling by the calling module is required.
function ResourceData.getPagename(strArg)
 
local data = getData(strArg)
---------------------------------------
-- if this particular data block doesn't have a page name, this will return nil
-- Buildings
-- therefore, error handling will be necessary
---------------------------------------
return data.page or nil
end
 
 
 
-- simpler version if all that's needed is the description.
-- error handling by the calling module is required.
function ResourceData.getDescription(strArg)
 
local data = getData(strArg)
-- Starting Buildings
-- if this particular data block doesn't have a description, this will return nil
["ancienthearth"] = "Small Hearth icon.png",
-- therefore, error handling will be necessary
["ancient hearth"] = "Small Hearth icon.png",
return data.description or nil
["mainwarehouse"] = "Main_Storage_icon.png",
end
["main warehouse"] = "Main_Storage_icon.png",
-- Camps
["foragers'camp"] = "Forager's Camp icon",
["foragers' camp"] = "Forager's Camp icon",
["forager'scamp"] = "Forager's Camp icon",
["forager's camp"] = "Forager's Camp icon",
["harvesters'camp"] = "Harvester Camp icon.png",
["harvesters' camp"] = "Harvester Camp icon.png",
["harvester'scamp"] = "Harvester Camp icon.png",
["harvester's camp"] = "Harvester Camp icon.png",
["herbalists'camp"] = "Herbalist's_Camp_icon.png",
["herbalists' camp"] = "Herbalist's_Camp_icon.png",
["herbalist'scamp"] = "Herbalist's_Camp_icon.png",
["herbalist's camp"] = "Herbalist's_Camp_icon.png",
["stonecutters'camp"] = "Stonecutter's Camp icon.png",
["stonecutters' camp"] = "Stonecutter's Camp icon.png",
["stonecutter'scamp"] = "Stonecutter's Camp icon.png",
["stonecutter's camp"] = "Stonecutter's Camp icon.png",
["woodcutters'camp"] = "Woodcutters Camp icon",
["woodcutters' camp"] = "Woodcutters Camp icon",
["woodcutter'scamp"] = "Woodcutters Camp icon",
["woodcutter's camp"] = "Woodcutters Camp icon",
["trappers'camp"] = "Trapper's Camp icon.png",
["trappers' camp"] = "Trapper's Camp icon.png",
["trapper'scamp"] = "Trapper's Camp icon.png",
["trapper's camp"] = "Trapper's Camp icon.png",
-- Food Production
["farmfield"] = "Farmfield_icon.png",
["farm field"] = "Farmfield_icon.png",
["herbgarden"] = "HerbGarden_icon.png",
["herb garden"] = "HerbGarden_icon.png",
["plantation"] = "Plantation_icon.png",
["smallfarm"] = "SmallFarm_icon.png",
["small farm"] = "SmallFarm_icon.png",
["bakery"] = "Bakery_icon.png",
["cellar"] = "Cellar_icon.png",
["cookhouse"] = "Cookhouse_icon.png",
["ranch"] = "Ranch_icon.png",
["smokehouse"] = "Smokehouse_icon.png",
["grill"] = "Grill_icon.png",
-- Housing
["shelter"] = "Shelter icon.png",
["bigshelter"] = "Big Shelter icon.png",
["big shelter"] = "Big Shelter icon.png",
["humanhouse"] = "Human House icon.png",
["human house"] = "Human House icon.png",
["beaverhouse"] = "Beaver House icon.png",
["beaver house"] = "Beaver House icon.png",
["lizardhouse"] = "Lizard House icon.png",
["lizard house"] = "Lizard House icon.png",
["harpyhouse"] = "Harpy House icon.png",
["harpy house"] = "Harpy House icon.png",
-- Industry
["crudeworkstation"] = "Crude_Workstation_icon.png",
["crude workstation"] = "Crude_Workstation_icon.png",
["makeshiftpost"] = "Makeshift_Post_icon.png",
["makeshift post"] = "Makeshift_Post_icon.png",
["raincollector"] = "Rain_Collector_icon.png",
["rain collector"] = "Rain_Collector_icon.png",
["mine"] = "Mine_icon.png",
["carpenter"] = "Carpenter_icon.png",
["weaver"] = "Weaver_icon.png",
["clothier"] = "Clothier_icon.png",
["brickyard"] = "Brickyard_icon.png",
["kiln"] = "Kiln_icon.png",
["rainmill"] = "Rain_Mill_icon.png",
["rain mill"] = "Rain_Mill_icon.png",
["provisioner"] = "Provisioner_icon.png",
["artisan"] = "Artisan_icon.png",
["brewery"] = "Brewery_icon.png",
["cooperage"] = "Cooperage_icon.png",
["druids'hut"] = "Druid_icon.png",
["druids' hut"] = "Druid_icon.png",
["druid'shut"] = "Druid_icon.png",
["druid's hut"] = "Druid_icon.png",
["leatherworker"] = "Leatherworks_icon.png",
["lumbermill"] = "Lumbermill_icon.png",
["lumber mill"] = "Lumbermill_icon.png",
["press"] = "Press_icon.png",
["scribe"] = "Scribe_icon.png",
["smelter"] = "Smelter_icon.png",
-- City Buildings
["smallhearth"] = "Temporary_Hearth_icon.png",
["small hearth"] = "Temporary_Hearth_icon.png",
["warehouse"] = "Storage_icon.png",
["tradingpost"] = "Trading_Post_icon.png",
["trading post"] = "Trading_Post_icon.png",
["blightpost"] = "Blight_Post_icon.png",
["blight post"] = "Blight_Post_icon.png",
["hydrant"] = "Hydrant_icon.png",
["forsakenaltar"] = "Altar_icon.png",
["forsaken altar"] = "Altar_icon.png",
-- Service Buildings
[string.lower("BathHouse")] = "Bath_House_icon.png",
["bath house"] = "Bath_House_icon.png",
["clanhall"] = "Clan_Hall_icon.png",
["clan hall"] = "Clan_Hall_icon.png",
["explorers'lodge"] = "Explorers_Lodge_icon.png",
["explorers' lodge"] = "Explorers_Lodge_icon.png",
["explorer'slodge"] = "Explorers_Lodge_icon.png",
["explorer's lodge"] = "Explorers_Lodge_icon.png",
["guildhouse"] = "Guild_House_icon.png",
["guild house"] = "Guild_House_icon.png",
["monastery"] = "Monastery_icon.png",
["tavern"] = "Tavern_icon.png",
["temple"] = "Temple_icon.png"
}






-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Main lookup function
-- Helper functions
-- Accepts the name of an icon, as it appears in the game, and returns the
-- filename associated with that in-game item, resource, building, etc.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------


function IconFilenames.getIconFilename(strIconName)


-- Convert the key to lower case for case-insensitive lookups
 
    local strLowercaseIconName = string.lower(strIconName)
-- Remove any preceeding or trailing whitespace characters from the argument
function ResourceData.trimWhitespace(strArg)
-- Get it from the big table below and return it.
return (s:gsub("^%s*(.-)%s*$", "%1"))
     return tableStrStrFilenames[strLowercaseIconName]
end
 
 
 
-- Normalize the argument to the standard in-game name, and the one that
-- is used as the key in the big lookup table.
--
-- This function will also make the argument lowercase to reduce the need
-- to specify more possible alternatives to normalize.
function ResourceData.normalizeName(strArg)
strArg = string.lower(strArg)
strArg = trimWhitespace(strArg)
-- no other functions need this lookup table, so it's defined locally
-- to this function
local tableStrStrAlternatives = {
---------------------------------------
-- Resources
---------------------------------------
-- Raw Food
["berry"] = "berries",
["egg"] = "eggs",
["insect"] = "insects",
["meats"] = "meat",
["mushroom"] = "mushrooms",
["root"] = "roots",
["vegetable"] = "vegetables",
--Complex Food
["biscuit"] = "biscuits",
["pickledgoods"] = "pickled goods",
["pickledgood"] =  "pickled goods",
["pickled good"] = "pickled goods",
["pies"] = "pie",
["skewer"] = "skewers",
-- Building Materials
["brick"] = "bricks",
["fabrics"] = "fabric",
["plank"] = "planks",
["part"] = "parts",
["wildfireessence"] =    "wildfire essence",
["wild fire essence"] =  "wildfire essence",
["wildfireessences"] =  "wildfire essence",
["wild fire essences"] = "wildfire essence",
-- Consumable items
["coat"] = "coats",
["ales"] = "ale",
["cosmetic"] = "cosmetics",
["incenses"] = "incense",
["insense"] = "incense",
["scroll"] = "scrolls",
["traininggear"] =  "training gear",
["traininggears"] =  "training gear",
["training gears"] = "training gear",
["wines"] = "wine",
-- Crafting materials
["clays"] = "clay",
["copperore"] =  "copper ore",
["copperores"] =  "copper ore",
["copper ores"] = "copper ore",
["crystalizeddew"] =    "crystalized dew",
["crystalizeddews"] =  "crystalized dew",
["crystallizeddew"] =  "crystalized dew",
["crystallizeddews"] =  "crystalized dew",
["crystalized dews"] =  "crystalized dew",
["crystallized dew"] =  "crystalized dew",
["crystallized dews"] = "crystalized dew",
["grains"] = "grain",
["herb"] = "herbs",
["leathers"] = "leather",
["flax"] =        "plant fiber",
["plantfiber"] =  "plant fiber",
["plantfibers"] =  "plant fiber",
["plant fibers"] = "plant fiber",
["reed"] = "reeds",
["spark dew"] = "sparkdew",
["stones"] = "stone",
-- Refined crafting materials
["barrel"] =  "barrels",
["barrell"] =  "barrels",
["barrells"] = "barrels",
["copperbar"] =  "copper bars",
["copperbars"] =  "copper bars",
["copper bar"] = "copper bars",
["flours"] = "flour",
["pigments"] = "pigment",
["waterskin"] =  "waterskins",
["water skin"] =  "waterskins",
["water skins"] = "waterskins",
-- Trade goods
["ambers"] = "amber",
["coin"] =  "amber",
["tablet"] =          "ancient tablet",
["tablets"] =        "ancient tablet",
["ancienttablet"] =  "ancient tablet",
["ancienttablets"] =  "ancient tablet",
["ancient tablets"] = "ancient tablet",
["buildingmaterial"] =            "pack of building materials",
["buildingmaterials"] =          "pack of building materials",
["building material"] =          "pack of building materials",
["building materials"] =          "pack of building materials",
["packofbuildingmaterial"] =      "pack of building materials",
["packofbuildingmaterials"] =    "pack of building materials",
["pack of building materials"] =  "pack of building materials",
["packsofbuildingmaterial"] =    "pack of building materials",
["packsofbuildingmaterials"] =    "pack of building materials",
["packs of building materials"] = "pack of building materials",
["crop"] =          "pack of crops",
["crops"] =        "pack of crops",
["packofcrop"] =    "pack of crops",
["packofcrops"] =  "pack of crops",
["pack of crop"] =  "pack of crops",
["packsofcrop"] =  "pack of crops",
["packsofcrops"] =  "pack of crops",
["packs of crop"] = "pack of crops",
["luxury"] =              "pack of luxury goods",
["luxuries"] =            "pack of luxury goods",
["luxurygood"] =          "pack of luxury goods",
["luxurygoods"] =          "pack of luxury goods",
["luxury good"] =          "pack of luxury goods",
["luxury goods"] =        "pack of luxury goods",
["packofluxuries"] =      "pack of luxury goods",
["packofluxurygood"] =    "pack of luxury goods",
["packofluxurygoods"] =    "pack of luxury goods",
["pack of luxury good"] =  "pack of luxury goods",
["packsofluxuries"] =      "pack of luxury goods",
["packsofluxurygood"] =    "pack of luxury goods",
["packsofluxurygoods"] =  "pack of luxury goods",
["packs of luxury good"] = "pack of luxury goods",
["provision"] =          "pack of provisions",
["provisions"] =        "pack of provisions",
["packofprovision"] =    "pack of provisions",
["packofprovisions"] =  "pack of provisions",
["pack of provision"] =  "pack of provisions",
["packsofprovision"] =  "pack of provisions",
["packsofprovisions"] =  "pack of provisions",
["packs of provision"] = "pack of provisions",
["tradegood"] =          "pack of trade goods",
["tradegoods"] =          "pack of trade goods",
["trade good"] =          "pack of trade goods",
["trade goods"] =        "pack of trade goods",
["packoftradegood"] =    "pack of trade goods",
["packoftradegoods"] =    "pack of trade goods",
["pack of trade good"] =  "pack of trade goods",
["packsoftradegood"] =    "pack of trade goods",
["packsoftradegoods"] =  "pack of trade goods",
["packs of trade good"] = "pack of trade goods",
-- Meta resources
["artifact"] =      "artifacts",
["metaartifact"] =  "artifacts",
["metaartifacts"] = "artifacts",
["meta artifact"] =  "artifacts",
["meta artifacts"] = "artifacts",
["food"] =          "food stockpiles",
["foods"] =          "food stockpiles",
["metafood"] =      "food stockpiles",
["metafoods"] =      "food stockpiles",
["meta food"] =      "food stockpiles",
["meta foods"] =      "food stockpiles",
["foodstockpile"] =  "food stockpiles",
["foodstockpiles"] = "food stockpiles",
["food stockpile"] = "food stockpiles",
["meta foodstockpile"] =  "food stockpiles",
["meta foodstockpiles"] = "food stockpiles",
["meta food stockpile"] = "food stockpiles",
["meta food stockpiles"] = "food stockpiles",
["machinary"] =     "machinery",
["metamachinery"] = "machinery",
["meta machinery"] = "machinery",
-- Fuel & Exploration
["coals"] = "coal",
["oils"] = "oil",
["seamarrow"] =  "sea marrow",
["seamarrows"] =  "sea marrow",
["sea marrows"] = "sea marrow",
["woods"] = "wood",
["simpletool"] =  "simple tools",
["simpletools"] = "simple tools",
["simple tool"] = "simple tools",
["infusedtool"] =  "infused tools",
["infusedtools"] = "infused tools",
["infused tool"] = "infused tools",
["purgingfire"] = "purging fire",
["purgingfires"] = "purging fire",
} -- the end of the huge tableStrStrAlternatives
-- if nothing is found, the result of the lookup will be nil, so
-- just return whatever was passed in as the argument (lowercase)
-- we can assume that the input argument is fine or does not exist
return tableStrStrAlternatives[strArg] or strArg
end
end


Line 262: Line 376:
-- Return when required into another Module.
-- Return when required into another Module.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
return IconFilenames
return ResourceData

Revision as of 18:57, 3 February 2023

Documentation for this module may be created at Module:ResourceData/doc

-------------------------------------------------------------------------------
-- Lua storage table for looking up wiki pages, names, and resources 
-- based on in-game names. All data is in English.
--
-- The table contains some deconfliction, but only for spaces, apostrophes, and
-- some singular/plural.
-- Use in-game names for things, and help keep this table updated as the game
-- is updated.
--
-- Using the table requires a locally defined lookup function that performs 
-- a string.lower on the argument so that the lookup table can accept any case 
-- and still function properly. Otherwise, we would need the table to define
-- both Berries = "Berries" and berries = "Berries" which would multiply our
-- work.
-------------------------------------------------------------------------------


-- for returning when REQUIRE'd by other Lua modules.
local ResourceData = {}



-------------------------------------------------------------------------------
-- Main data table, with string keys and string values.
-- Some of these are defined inline with string.lower to make the key easier
-- to spell and read correctly.
-------------------------------------------------------------------------------

-- a design decision of this table is to make the key the same as the page name.
-- (the lookup methods will automatically make it lowercase.)
-- that way, whenever .page is referenced, it can be used again to retrieve 
-- the rest of the data.
local tableStrStrData = {

	---------------------------------------
	-- Resources
	---------------------------------------
    -- Raw Food
	["berries"] = {iconfile="Berries.png", page="Berries"},
	["eggs"] = {iconfile="Eggs.png", page="Eggs"},
	["insects"] = {iconfile="Insects.png", page="Insects"},
	["meat"] = {iconfile="Meat.png", page="Meat"},
	["mushrooms"] = {iconfile="Mushrooms.png", page="Mushrooms"},
	["roots"] = {iconfile="Roots.png", page="Roots"},
	["vegetables"] = {iconfile="Vegetables.png", page="Vegetables"},
	-- Complex Food
	["biscuits"] = {iconfile="Biscuits.png", page="Biscuits"},
	["jerky"] = {iconfile="Jerky.png", page="Jerky"},
	["pickled goods"] = {iconfile="PickledGoods.png", page="Pickled Goods"},
	["pie"] = {iconfile="Pie.png", page="Pie"},
	["skewers"] = {iconfile="Skewers.png", page="Skewers"},
	-- Building Materials
	["bricks"] = {iconfile="Bricks.png", page="Bricks"},
	["fabric"] = {iconfile="Fabric.png", page="Fabric"},
	["planks"] = {iconfile="Planks.png", page="Planks"},
	["parts"] = {iconfile="Parts.png", page="Parts"},
	["wildfire essence"] = {iconfile="Wildfire Essence.png", page="Wildfire Essence"},
	-- Consumable Items
	["coats"] = {iconfile="Coats.png", page="Coats"},
	["ale"] = {iconfile="Ale.png", page="Ale"},
	["cosmetics"] = {iconfile="Cosmetics.png", page="Cosmetics"},
	["incense"] = {iconfile="Incense.png", page="Incense"},
	["scrolls"] = {iconfile="Scrolls.png", page="Scrolls"},
	["training gear"] = {iconfile="TrainingGear.png", page="Training Gear"},
	["wine"] = {iconfile="Wine.png", page="Wine"},
	-- Crafting Materials
	["clay"] = {iconfile="Clay.png", page="Clay"},
	["copper ore"] = {iconfile="CopperOre.png", page="Copper Ore"},
	["crystalized dew"] = {iconfile="CrystalizedDew.png", page="Crystalized Dew"},
	["grain"] = {iconfile="Grain.png", page="Grain"},
	["herbs"] = {iconfile="Herbs.png", page="Herbs"},
	["leather"] = {iconfile="Leather.png", page="Leather"},
	["plant fiber"] = {iconfile="PlantFiber.png", page="Plant Fiber"},
	["reeds"] = {iconfile="Reeds.png", page="Reeds"},
	["resin"] = {iconfile="Resin.png", page="Resin"},
	["sparkdew"] = {iconfile="Sparkdew.png", page="Sparkdew"},
	["stone"] = {iconfile="Stone.png", page="Stone"},
	-- Refined Crafting Materials
	["barrels"] = {iconfile="Barrels.png", page="Barrels"},
	["copper bars"] = {iconfile="CopperBar.png", page="Copper Bars"},
	["flour"] = {iconfile="Flour.png", page="Flour"},
	["pigment"] = {iconfile="Pigment.png", page="Pigment"},
	["pottery"] = {iconfile="Pottery.png", page="Pottery"},
	["waterskins"] = {iconfile="Waterskins.png", page="Waterskins"},
	-- Trade Goods
	["amber"] = {iconfile="Amber.png", page="Amber"},
	["ancient tablet"] = {iconfile="AncientTablet.png", page="Ancient Tablet"},
	["pack of building materials"] = {iconfile="BuildingMaterials.png", page="Pack of Building Materials"},
	["pack of crops"] = {iconfile="Crops.png", page="Pack of Crops"},
	["pack of luxury goods"] = {iconfile="Luxury.png", page="Pack of Luxury Goods"},
	["pack of provisions"] = {iconfile="Provisions.png", page="Pack of Provisions"},
	["pack of trade goods"] = {iconfile="TradeGoods.png", page="Pack of Trade Goods"},
	-- Meta resources
	["artifacts"] = {iconfile="Icon MetaResource Artifact.png", page="Artifacts"},
	["food stockpiles"] = {iconfile="Icon MetaResource FoodStockpiles.png", page="Food Stockpiles"},
	["machinery"] = {iconfile="Icon MetaResource Machinery.png", page="Machinery"},
	-- Fuel & Exploration
	["coal"] = {iconfile="Coal.png", page="Coal"},
	["oil"] = {iconfile="Oil.png", page="Oil"},
	["sea marrow"] = {iconfile="SeaMarrow.png", page="Sea Marrow"},
	["wood"] = {iconfile="Wood.png", page="Wood"},
	["simple tools"] = {iconfile="SimpleTools.png", page="Simple Tools"},
	["infused tools"] = {iconfile="InfusedTools.png", page="Infused Tools"},
	["purging fire"] = {iconfile="PurgingFire.png", page="Purging Fire"},
}



-------------------------------------------------------------------------------
-- Main lookup functions
-- Accepts the in-game name and returns the name of the page on the wiki
-- associated with that in-game item, resource, building, etc.
-------------------------------------------------------------------------------



-- returns the whole data table for the specified key
-- need to run normalize function first
function ResourceData.getData(strArg)

	-- normalize input
    local strArg = ResourceData.trimWhitespace(strArg)
	
	-- Get it from the big table below and return it.
    return tableStrStrData[strArg]
end



-- simpler version if all that's needed is the iconfile.
-- error handling by the calling module is required.
function ResourceData.getIconFilename(strArg)

	local data = getData(strArg)
	
	-- if this particular data block doesn't have a iconfile, this will return nil
	-- therefore, error handling will be necessary
	return data.iconfile or nil
end



-- simpler version if all that's needed is the page name.
-- error handling by the calling module is required.
function ResourceData.getPagename(strArg)

	local data = getData(strArg)
	
	-- if this particular data block doesn't have a page name, this will return nil
	-- therefore, error handling will be necessary
	return data.page or nil
end



-- simpler version if all that's needed is the description.
-- error handling by the calling module is required.
function ResourceData.getDescription(strArg)

	local data = getData(strArg)
	
	-- if this particular data block doesn't have a description, this will return nil
	-- therefore, error handling will be necessary
	return data.description or nil
end



-------------------------------------------------------------------------------
-- Helper functions
-------------------------------------------------------------------------------



-- Remove any preceeding or trailing whitespace characters from the argument
function ResourceData.trimWhitespace(strArg)
	
	return (s:gsub("^%s*(.-)%s*$", "%1"))
end



-- Normalize the argument to the standard in-game name, and the one that 
-- is used as the key in the big lookup table.
--
-- This function will also make the argument lowercase to reduce the need
-- to specify more possible alternatives to normalize.
function ResourceData.normalizeName(strArg)
	
	strArg = string.lower(strArg)
	strArg = trimWhitespace(strArg)
	
	-- no other functions need this lookup table, so it's defined locally
	-- to this function
	local tableStrStrAlternatives = {
	
		---------------------------------------
		-- Resources
		---------------------------------------
		-- Raw Food
		["berry"] = "berries",
		["egg"] = "eggs",
		["insect"] = "insects",
		["meats"] = "meat",
		["mushroom"] = "mushrooms",
		["root"] = "roots",
		["vegetable"] = "vegetables",
		--Complex Food
		["biscuit"] = "biscuits",
		["pickledgoods"] = "pickled goods",
		["pickledgood"] =  "pickled goods",
		["pickled good"] = "pickled goods",
		["pies"] = "pie",
		["skewer"] = "skewers",
		-- Building Materials
		["brick"] = "bricks",
		["fabrics"] = "fabric",
		["plank"] = "planks",
		["part"] = "parts",
		["wildfireessence"] =    "wildfire essence",
		["wild fire essence"] =  "wildfire essence",
		["wildfireessences"] =   "wildfire essence",
		["wild fire essences"] = "wildfire essence",
		-- Consumable items
		["coat"] = "coats",
		["ales"] = "ale",
		["cosmetic"] = "cosmetics",
		["incenses"] = "incense",
		["insense"] = "incense",
		["scroll"] = "scrolls",
		["traininggear"] =   "training gear",
		["traininggears"] =  "training gear",
		["training gears"] = "training gear",
		["wines"] = "wine",
		-- Crafting materials
		["clays"] = "clay",
		["copperore"] =   "copper ore",
		["copperores"] =  "copper ore",
		["copper ores"] = "copper ore",
		["crystalizeddew"] =    "crystalized dew",
		["crystalizeddews"] =   "crystalized dew",
		["crystallizeddew"] =   "crystalized dew",
		["crystallizeddews"] =  "crystalized dew",
		["crystalized dews"] =  "crystalized dew",
		["crystallized dew"] =  "crystalized dew",
		["crystallized dews"] = "crystalized dew",
		["grains"] = "grain",
		["herb"] = "herbs",
		["leathers"] = "leather",
		["flax"] =         "plant fiber",
		["plantfiber"] =   "plant fiber",
		["plantfibers"] =  "plant fiber",
		["plant fibers"] = "plant fiber",
		["reed"] = "reeds",
		["spark dew"] = "sparkdew",
		["stones"] = "stone",
		-- Refined crafting materials
		["barrel"] =   "barrels",
		["barrell"] =  "barrels",
		["barrells"] = "barrels",
		["copperbar"] =   "copper bars",
		["copperbars"] =  "copper bars",
		["copper bar"] = "copper bars",
		["flours"] = "flour",
		["pigments"] = "pigment",
		["waterskin"] =   "waterskins",
		["water skin"] =  "waterskins",
		["water skins"] = "waterskins",
		-- Trade goods
		["ambers"] = "amber",
		["coin"] =   "amber",
		["tablet"] =          "ancient tablet",
		["tablets"] =         "ancient tablet",
		["ancienttablet"] =   "ancient tablet",
		["ancienttablets"] =  "ancient tablet",
		["ancient tablets"] = "ancient tablet",
		["buildingmaterial"] =            "pack of building materials",
		["buildingmaterials"] =           "pack of building materials",
		["building material"] =           "pack of building materials",
		["building materials"] =          "pack of building materials",
		["packofbuildingmaterial"] =      "pack of building materials",
		["packofbuildingmaterials"] =     "pack of building materials",
		["pack of building materials"] =  "pack of building materials",
		["packsofbuildingmaterial"] =     "pack of building materials",
		["packsofbuildingmaterials"] =    "pack of building materials",
		["packs of building materials"] = "pack of building materials",
		["crop"] =          "pack of crops",
		["crops"] =         "pack of crops",
		["packofcrop"] =    "pack of crops",
		["packofcrops"] =   "pack of crops",
		["pack of crop"] =  "pack of crops",
		["packsofcrop"] =   "pack of crops",
		["packsofcrops"] =  "pack of crops",
		["packs of crop"] = "pack of crops",
		["luxury"] =               "pack of luxury goods",
		["luxuries"] =             "pack of luxury goods",
		["luxurygood"] =           "pack of luxury goods",
		["luxurygoods"] =          "pack of luxury goods",
		["luxury good"] =          "pack of luxury goods",
		["luxury goods"] =         "pack of luxury goods",
		["packofluxuries"] =       "pack of luxury goods",
		["packofluxurygood"] =     "pack of luxury goods",
		["packofluxurygoods"] =    "pack of luxury goods",
		["pack of luxury good"] =  "pack of luxury goods",
		["packsofluxuries"] =      "pack of luxury goods",
		["packsofluxurygood"] =    "pack of luxury goods",
		["packsofluxurygoods"] =   "pack of luxury goods",
		["packs of luxury good"] = "pack of luxury goods",
		["provision"] =          "pack of provisions",
		["provisions"] =         "pack of provisions",
		["packofprovision"] =    "pack of provisions",
		["packofprovisions"] =   "pack of provisions",
		["pack of provision"] =  "pack of provisions",
		["packsofprovision"] =   "pack of provisions",
		["packsofprovisions"] =  "pack of provisions",
		["packs of provision"] = "pack of provisions",
		["tradegood"] =           "pack of trade goods",
		["tradegoods"] =          "pack of trade goods",
		["trade good"] =          "pack of trade goods",
		["trade goods"] =         "pack of trade goods",
		["packoftradegood"] =     "pack of trade goods",
		["packoftradegoods"] =    "pack of trade goods",
		["pack of trade good"] =  "pack of trade goods",
		["packsoftradegood"] =    "pack of trade goods",
		["packsoftradegoods"] =   "pack of trade goods",
		["packs of trade good"] = "pack of trade goods",
		-- Meta resources
		["artifact"] =      "artifacts",
		["metaartifact"] =  "artifacts",
		["metaartifacts"] = "artifacts",
		["meta artifact"] =  "artifacts",
		["meta artifacts"] = "artifacts",
		["food"] =           "food stockpiles",
		["foods"] =          "food stockpiles",
		["metafood"] =       "food stockpiles",
		["metafoods"] =      "food stockpiles",
		["meta food"] =       "food stockpiles",
		["meta foods"] =      "food stockpiles",
		["foodstockpile"] =  "food stockpiles",
		["foodstockpiles"] = "food stockpiles",
		["food stockpile"] = "food stockpiles",
		["meta foodstockpile"] =  "food stockpiles",
		["meta foodstockpiles"] = "food stockpiles",
		["meta food stockpile"] = "food stockpiles",
		["meta food stockpiles"] = "food stockpiles",
		["machinary"] =     "machinery",
		["metamachinery"] = "machinery",
		["meta machinery"] = "machinery",
		-- Fuel & Exploration
		["coals"] = "coal",
		["oils"] = "oil",
		["seamarrow"] =   "sea marrow",
		["seamarrows"] =  "sea marrow",
		["sea marrows"] = "sea marrow",
		["woods"] = "wood",
		["simpletool"] =  "simple tools",
		["simpletools"] = "simple tools",
		["simple tool"] = "simple tools",
		["infusedtool"] =  "infused tools",
		["infusedtools"] = "infused tools",
		["infused tool"] = "infused tools",
		["purgingfire"] = "purging fire",
		["purgingfires"] = "purging fire",
		
	} -- the end of the huge tableStrStrAlternatives
	
	-- if nothing is found, the result of the lookup will be nil, so 
	-- just return whatever was passed in as the argument (lowercase)
	-- we can assume that the input argument is fine or does not exist
	return tableStrStrAlternatives[strArg] or strArg
end



-------------------------------------------------------------------------------
-- Return when required into another Module.
-------------------------------------------------------------------------------
return ResourceData