Template:Resource link

From Against the Storm Official Wiki
Revision as of 19:10, 3 February 2023 by Aeredor (talk | contribs) (wrong function call)

-- 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.normalizeName(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



-- 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)

-- 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