Template:Resource link: Difference between revisions

From Against the Storm Official Wiki
(wrong function call)
m (added note about s after the link)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
-------------------------------------------------------------------------------
<includeonly>{{#invoke:ResourceLink|resourceLink|resource={{{1|{{{resource|}}} }}}|iconsize={{{2|{{{iconsize|}}} }}} }}</includeonly><noinclude>
-- 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.
-------------------------------------------------------------------------------


'''Resource_link''' is a template creates links to resources (or goods) on the wiki and includes an icon for improved recognition. Reuses standardizes icon size templates for consistency.


-- for returning when REQUIRE'd by other Lua modules.
The [[Template:rl]] is a shortcut to this template.
local ResourceData = {}


== Overview ==


This template should be used liberally across the wiki, wherever the names of goods are mentioned in paragraphs or in tables. The accompanying icons will help skimming for expert players and orientation for new players.


-------------------------------------------------------------------------------
Since the rendering of the template ends in a standard wikilink, you can append an ''s'' after the template to write the plural of the good if it isn't already plural. Just like a regular wiki link, <code><nowiki>{{rl|Reed}}s</nowiki></code> yields {{rl|Reed}}s, plural, with the ''s'' included in the link text.
-- 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.
For in-paragraph display, which is presumed to be the most common utilization, the default icon size is <code>small</code>, or {{ImgS}} from [[Template:ImgS]]. For use in tables where more spacing between lines doesn't hurt readability or aesthetics, it is recommended to use <code>med</code>, which will increase the size of the icons to {{ImgM}} (from [[Template:ImgM]]).
-- (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 = {


---------------------------------------
Use your judgment when writing content. The first mention of a resource in a paragraph should probably be done with this template. But you may find that paragraphs densely mentioning resources become harder not easier to read. You may decide that after the first mention of the resource, it's better for subsequent references to be in plain text or with this template but without an icon.
-- 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"},
}


== Usage ==


<pre>
{{Resource link|resource|iconsize}}
</pre>


-------------------------------------------------------------------------------
== Parameters ==
-- 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.
-------------------------------------------------------------------------------


Only the first parameter, <code>resource</code> is required, and it must be spelled correctly to match the in-game name of the resource or good. The other parameter is optional but improve this template's applicability to more instances of its use. You may include or omit any parameters' names.


{|class="wikitable"
|-
! Parameter !! Type !! Description
|-
| resource || string || '''Required.''' The in-game name of the good whose page you want to link to and whose icon you want to display.
|-
| iconsize || string || One of the following values to indicate the desired size of the icon:<br />
<table><tr><td>
* <code>none</code>
* <code>small</code>
* <code>med</code>
* <code>large</code>
* <code>huge</code>
</td><td>
which will prevent an icon from displaying<br />
which sizes the icon to {{ImgS}} from [[Template:ImgS]], '''default'''<br />
which sizes the icon to {{ImgM}} from [[Template:ImgM]]<br />
which sizes the icon to {{ImgL}} from [[Template:ImgL]]<br />
which sizes the icon to {{ImgH}} from [[Template:ImgH]]
</td></tr></table>
|}


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


-- normalize input
When the template is called without a resource name, the template reminds you that it is required.
    local strArg = ResourceData.normalizeName(strArg)
-- Get it from the big table below and return it.
    return tableStrStrData[strArg]
end


'''Example:'''


<pre>
{{Resource link}}
</pre>


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


local data = getData(strArg)
'''{{Resource link}}'''
-- 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


When providing the name of a good, it is important that it is spelled correctly, including any punctuation or spaces. Otherwise, you will see an error message:


'''Example:'''


-- simpler version if all that's needed is the page name.
Broken: <code><nowiki>{{Resource link|TrainingGear}}</nowiki></code>
-- error handling by the calling module is required.
function ResourceData.getPagename(strArg)


local data = getData(strArg)
'''{{Resource link|TrainingGear}}'''
-- 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


Fixed: <code><nowiki>{{Resource link|Training Gear}}</nowiki></code>


{{Resource link|Training Gear}}


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


local data = getData(strArg)
Here are ways to call the template and the expected result:
-- 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


{| class="wikitable"
! Parameters !! Examples !! Expected outcome
|-
| None
| <code><nowiki>{{Resource link}}</nowiki></code><br />or <code><nowiki>{{rl}}</nowiki></code>
| An error.
|-
| resource only
| <code><nowiki>{{Resource link|Biscuits}}</nowiki></code>
|rowspan="2"| A small, text-sized icon and link, best for within paragraphs.
|-
|rowspan="4"| resource and iconsize
| <code><nowiki>{{rl|Crystalized Dew|small}}</nowiki></code>
|-
| <code><nowiki>{{rl|Training Gear|med}}</nowiki></code>
| A moderately-sized resource icon and a link, best in dense tables.
|-
| <code><nowiki>{{rl|Flour|large}}</nowiki></code>
| A large resource icon and a link, best as featured items within tables.
|-
| <code><nowiki>{{rl|Pack of Trade Goods|huge}}</nowiki></code>
| A very large resource icon and a link, in case you every need one this big.
|}


The following are generated by calling the template.


-------------------------------------------------------------------------------
1 <code><nowiki>{{Resource link|Biscuits|none}}</nowiki></code> yields:
-- Helper functions
-------------------------------------------------------------------------------


{{Resource link|Biscuits|none}}


2. <code><nowiki>{{Resource link|Biscuits|small}}</nowiki></code> yields:


-- Normalize the argument to the standard in-game name, and the one that
{{Resource link|Biscuits|small}}
-- 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


3. <code><nowiki>{{Resource link|Biscuits|med}}</nowiki></code> yields:


{{Resource link|Biscuits|med}}


-------------------------------------------------------------------------------
4. <code><nowiki>{{Resource link|Biscuits|large}}</nowiki></code> yields:
-- Return when required into another Module.
 
-------------------------------------------------------------------------------
{{Resource link|Biscuits|large}}
return ResourceData
 
5. <code><nowiki>{{Resource link|Biscuits|huge}}</nowiki></code> yields:
 
{{Resource link|Biscuits|huge}}
 
The following are additional incorrect usages of the template:
 
6. With no resource but an icon size, <code><nowiki>{{Resource link||large}}</nowiki></code> yields:
 
'''{{Resource link||large}}'''
 
Finally, providing an icon size that is not recognized does not break the template. There is a default icon size instead of returning an error.
 
9. With a valid resource but invalid icon size, <code><nowiki>{{Resource link|Biscuits|gigantic}}</nowiki></code> yields:
 
{{Resource link|Biscuits|gigantic}}</noinclude>

Latest revision as of 17:30, 25 December 2023


Resource_link is a template creates links to resources (or goods) on the wiki and includes an icon for improved recognition. Reuses standardizes icon size templates for consistency.

The Template:rl is a shortcut to this template.

Overview

This template should be used liberally across the wiki, wherever the names of goods are mentioned in paragraphs or in tables. The accompanying icons will help skimming for expert players and orientation for new players.

Since the rendering of the template ends in a standard wikilink, you can append an s after the template to write the plural of the good if it isn't already plural. Just like a regular wiki link, {{rl|Reed}}s yields Reed Reeds, plural, with the s included in the link text.

For in-paragraph display, which is presumed to be the most common utilization, the default icon size is small, or x18px from Template:ImgS. For use in tables where more spacing between lines doesn't hurt readability or aesthetics, it is recommended to use med, which will increase the size of the icons to x30px (from Template:ImgM).

Use your judgment when writing content. The first mention of a resource in a paragraph should probably be done with this template. But you may find that paragraphs densely mentioning resources become harder not easier to read. You may decide that after the first mention of the resource, it's better for subsequent references to be in plain text or with this template but without an icon.

Usage

{{Resource link|resource|iconsize}}

Parameters

Only the first parameter, resource is required, and it must be spelled correctly to match the in-game name of the resource or good. The other parameter is optional but improve this template's applicability to more instances of its use. You may include or omit any parameters' names.

Parameter Type Description
resource string Required. The in-game name of the good whose page you want to link to and whose icon you want to display.
iconsize string One of the following values to indicate the desired size of the icon:
  • none
  • small
  • med
  • large
  • huge

which will prevent an icon from displaying
which sizes the icon to x18px from Template:ImgS, default
which sizes the icon to x30px from Template:ImgM
which sizes the icon to x60px from Template:ImgL
which sizes the icon to x84px from Template:ImgH

Errors

When the template is called without a resource name, the template reminds you that it is required.

Example:

{{Resource link}}

Yields:

The Resource_link template requires the name of a resource.

When providing the name of a good, it is important that it is spelled correctly, including any punctuation or spaces. Otherwise, you will see an error message:

Example:

Broken: {{Resource link|TrainingGear}}

No goods found with that name: TrainingGear.

Fixed: {{Resource link|Training Gear}}

Training Gear Training Gear

Additional Examples and Errors

Here are ways to call the template and the expected result:

Parameters Examples Expected outcome
None {{Resource link}}
or {{rl}}
An error.
resource only {{Resource link|Biscuits}} A small, text-sized icon and link, best for within paragraphs.
resource and iconsize {{rl|Crystalized Dew|small}}
{{rl|Training Gear|med}} A moderately-sized resource icon and a link, best in dense tables.
{{rl|Flour|large}} A large resource icon and a link, best as featured items within tables.
{{rl|Pack of Trade Goods|huge}} A very large resource icon and a link, in case you every need one this big.

The following are generated by calling the template.

1 {{Resource link|Biscuits|none}} yields:

Biscuits

2. {{Resource link|Biscuits|small}} yields:

Biscuits Biscuits

3. {{Resource link|Biscuits|med}} yields:

Biscuits Biscuits

4. {{Resource link|Biscuits|large}} yields:

Biscuits Biscuits

5. {{Resource link|Biscuits|huge}} yields:

Biscuits Biscuits

The following are additional incorrect usages of the template:

6. With no resource but an icon size, {{Resource link||large}} yields:

The Resource_link template requires the name of a resource.

Finally, providing an icon size that is not recognized does not break the template. There is a default icon size instead of returning an error.

9. With a valid resource but invalid icon size, {{Resource link|Biscuits|gigantic}} yields:

Biscuits Biscuits