Difference between revisions of "Template:BoM"

From ChatWars Wiki
Jump to: navigation, search
(remove thousands separator from the final bom mana and weight values of the resulting item to be in line with the total sums as they don't have thousands separators)
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#vardefine: recipeSource | {{{source|{{PAGENAME}} }}} }}{{#vardefine: outputMode | {{{mode|tree}}} }}<!--
+
{{#vardefine: recipeSource | {{{source|{{ReplaceNumericCharEncoding|string={{PAGENAME}} }} }}} }}{{#vardefine: outputMode | {{{mode|all}}} }}{{#vardefine: incomplete | {{#show: {{#var: recipeSource}} | ?BoolRecipeIncomplete }} }}<!--
 
-->{{#vardefine: resourceList|}}<includeonly><!--
 
-->{{#vardefine: resourceList|}}<includeonly><!--
 
--><div class="mw-collapsible mw-collapsed" style="width: 15%; overflow: visible;" data-expandtext="Show BoM" data-collapsetext="Hide BoM">
 
--><div class="mw-collapsible mw-collapsed" style="width: 15%; overflow: visible;" data-expandtext="Show BoM" data-collapsetext="Hide BoM">
Line 19: Line 19:
 
}}<!--
 
}}<!--
  
Tree style list of resources + intermediate steps-->
+
Tree style list of resources + intermediate steps-->{{#ifeq: {{#var: incomplete}} | true | <br>''ATTENTION: Recipe and thus Bill of Materials is incomplete!''<br> }}
 
{{#switch: {{#var: outputMode}}
 
{{#switch: {{#var: outputMode}}
 
   | tree | all = {{#var: outputBuffer}}
 
   | tree | all = {{#var: outputBuffer}}
Line 26: Line 26:
 
List of basic resources + mana usage
 
List of basic resources + mana usage
 
-->{{#switch: {{#var: outputMode}}
 
-->{{#switch: {{#var: outputMode}}
   | list | all = {{#vardefine: resourceList
+
   | list | all = <br>{{#arraydefine: outputBufferList | {{#var: outputBuffer}} | * }} <!-- load tree style BoM list into an array separated by * (generates empty elements for deeper indentations eg: ***)
                   | {{#ask:
+
              -->{{#arraydefine: emptyElementArray | * | * }} <!-- generates an array with 2 empty elements (same kind of empty as the ones generated in the step above)
                      [[-Has subobject::{{#var: recipeSource}}]] [[Crafting ingredient.ItemType::+]] [[Crafting ingredient.ItemType::!Recipe (Item)]] [[Crafting ingredient.ItemType::!Piece of Equipment]]
+
              -->{{#arraydiff: outputBufferList | outputBufferList | emptyElementArray }} <!-- filters out all empty elements from the outputbufferlist array by using the empty elements from emptylementarray as filter comparison
                      |mainlabel=-
+
              -->{{#arrayslice: outputBufferList | outputBufferList | 1}} <!-- remove the one empty element that somehow makes it through the filter (dont know dont care)--><!--
                       |headers=hide
+
 
                       |format=template
+
              -->{{#arraydefine: neededBasicResources}}{{#arraydefine: neededQuantities}}{{#vardefine: totalMana | 0 }}{{#vardefine: totalStock | 0 }}{{#vardefine: i | 0 }}<!--
                       |template=ResourceBreakdown
+
              -->{{#while:
                       |userparam=0;1<!-- first number is depth, second is multiplier-->
+
                   | {{#ifexpr: {{#var: i}} < {{#arraysize: outputBufferList}} | true }}
                       |sort=Qty,Crafting ingredient
+
                  | {{#vardefine: startPosResource | {{#expr: {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{!}} }} + 1 }} }}<!--
                       |order=desc,asc
+
                  -->{{#vardefine: endPosResource | {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | ]] }} }}<!--
                       |?Crafting ingredient
+
                  -->{{#vardefine: resource | {{#sub: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{#var: startPosResource}} | {{#expr: {{#var: endPosResource}} - {{#var: startPosResource}} }} }} }}<!--
                      |?Qty
+
                  -->{{#ifeq: {{#show: {{#var: resource}} |?BoolCraft }} | false <!-- checks if resource in that line is a basic resource that has to be added to the tally-->
 +
                      | {{#vardefine: arrayPos | {{#arraysearch: neededBasicResources | {{#var: resource}} }} }}<!--
 +
                      -->{{#if: {{#var: arrayPos}} <!-- if resource is found (already exists in that array) no new element is added, old element is modified, if not in the array yet, added-->
 +
                          |
 +
                          | {{#arraydefine: newResource | {{#var: resource}} }}<!--
 +
                          -->{{#arraymerge: neededBasicResources | neededBasicResources | newResource }}<!--
 +
                          -->{{#arraydefine: newQuantity | 0 }}<!--
 +
                          -->{{#arraymerge: neededQuantities | neededQuantities | newQuantity }}<!--
 +
                          -->{{#vardefine: arrayPos | {{#arraysearch: neededBasicResources | {{#var: resource}} }} }}
 +
                        }}<!--
 +
                       -->{{#vardefine: oldQuantitySum | {{#arrayindex: neededQuantities | {{#var: arrayPos}} }} }}<!--
 +
                       -->{{#vardefine: newQuantity | {{#sub: {{#arrayindex: outputBufferList | {{#var: i}} }} | 0 | {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | x }} }} }} <!-- extract quantity from string--><!--
 +
                       -->{{#arraydefine: new | {{#expr: {{#var: oldQuantitySum}} + {{#var: newQuantity}} }} }}<!--
 +
                       -->{{#arrayslice: quantitiesfront | neededQuantities | 0 | {{#var: arrayPos}} }}<!--
 +
                      -->{{#arrayslice: quantitiesback | neededQuantities | {{#expr: {{#var: arrayPos}} + 1 }} }}<!--
 +
                       -->{{#arraymerge: neededQuantities | quantitiesfront | new }}<!--
 +
                       -->{{#arraymerge: neededQuantities | neededQuantities | quantitiesback }}<!--
 +
                       -->{{#vardefine: totalStock | {{#expr: {{#var: totalStock}} + ( {{#var: newQuantity}} * {{#show: {{#var: resource}} |?Weight}} ) }} }}
 
                     }}
 
                     }}
 +
                    {{#ifeq: {{#rpos: {{#arrayindex: outputBufferList | {{#var: i}} }} | Mana }} | -1 <!-- checks if the item uses mana to add to the mana tally-->
 +
                      | <!-- this branch gets executed if there is no mana cost connected to that item-->
 +
                      | {{#vardefine: startPosMana | {{#expr: {{#rpos: {{#arrayindex: outputBufferList | {{#var: i}} }} | ,<nowiki> </nowiki> }} + 2 }} }}
 +
                        {{#vardefine: endPosMana | {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{Emoticon|emoticon=Mana}} }} }}
 +
                        {{#vardefine: mana | {{#sub: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{#var: startPosMana}} | {{#expr: {{#var: endPosMana}} - {{#var: startPosMana}} }} }} }}
 +
                        {{#vardefine: totalMana | {{#expr: {{#var: totalMana}} + {{#var: mana}} }} }}
 +
                    }}
 +
                    {{#vardefine: i | {{#expr: {{#var: i}} + 1 }} }}
 
                 }}
 
                 }}
 +
 +
 +
<!--          -->Basic resources sum:<br><!--
 +
              -->{{#vardefine: n | 0 }}<!--
 +
              -->{{#while:
 +
                  | {{#ifexpr: {{#var: n}} < {{#arraysize: neededBasicResources}} | true }}
 +
                  | {{#arrayindex: neededQuantities | {{#var: n}} }}x [[{{#arrayindex: neededBasicResources | {{#var: n}} }}]]<br>
 +
                    {{#vardefine: n | {{#expr: {{#var: n}} + 1 }} }}
 +
                }}<!--
 +
              -->[[Mana]] Cost: {{#expr: {{#var: totalMana}} + {{RemoveThousandSeparator|number={{#show: {{#var: recipeSource}} |?ManaCrafting}} }} }}{{Emoticon|emoticon=Mana}} (Ingredients: {{#var: totalMana}}{{Emoticon|emoticon=Mana}} / Item: {{RemoveThousandSeparator|number={{#show: {{#var: recipeSource}} |?ManaCrafting}} }}{{Emoticon|emoticon=Mana}})<br>
 +
<!--          -->Total [[stock]] weight of basic resources: {{#var: totalStock}}{{Emoticon|emoticon=Stock}}, stock weight of finished item: {{#if: {{#show: {{#var: recipeSource}} |?Weight }} | {{RemoveThousandSeparator|number={{#show: {{#var: recipeSource}} |?Weight }} }} | [[??]] }}{{Emoticon|emoticon=Stock}}
 
}}</div></div><!--
 
}}</div></div><!--
 
--></includeonly><noinclude>
 
--></includeonly><noinclude>
Generates a BoM (Bill of Materials) for an item. Has three modes:
+
Generates a BoM (Bill of Materials) for an item. Has three modes you can choose with the template parameter <code>outputMode</code>:
* Show the most basic resources with all amounts added up. (WIP)
+
* <code>outputMode = list</code> - Show the most basic resources with all amounts added up.
* Show a tree style list with all the needed resources as child of the intermediate ingredient with different levels of indentation (done)
+
* <code>outputMode = tree</code> - Show a tree style list with all the needed resources as child of the intermediate ingredient with different levels of indentation (done)
* Show both
+
* <code>outputMode = all</code> - Show both (Default mode in case parameter is left out)
  
 
Uses sub-template [[Template:ResourceBreakdown]]
 
Uses sub-template [[Template:ResourceBreakdown]]
 
[[Category:Template]]
 
[[Category:Template]]
 
<!-- unfinished code, shouldn't affect pages where this template is used-->
 
{{#arraydefine: outputBufferList | {{#var: outputBuffer}} | * }} <!-- load tree style BoM list into an array separated by * (generates empty elements for deeper indentations eg: ***)-->
 
{{#arraydefine: emptyElementArray | * | * }} <!-- generates an array with 2 empty elements (same kind of empty as the ones generated in the step above)-->
 
{{#arraysize: emptyElementArray}}/{{#arrayprint: emptyElementArray}}
 
{{#arraydiff: outputBufferList | outputBufferList | emptyElementArray }} <!-- filters out all empty elements from the outputbufferlist array by using the empty elements from emptylementarray as filter comparison-->
 
{{#arrayslice: outputBufferList | outputBufferList | 1}} <!-- remove the one empty element that somehow makes it through the filter (dont know dont care)-->
 
{{#arraysize: outputBufferList}}/{{#arrayprint: outputBufferList  | <br>}}
 
 
{{#arraydefine: basicResources | {{#ask: [[ItemType::Resource]] [[BoolCraft::false]] |mainlabel= |headers=none |order=asc |limit=5000}} }}
 
 
<!-- those two arrays should have the same length and should coincide with each other - index 0 in neededBasicResources should show "Thread" and the needed quantity of thread in neededQuantities-->
 
<!-- HOW CAN YOU PRINT THE LIST WITHOUT SHOWING THE ONES THAT HAVE 0 QUANTITY AND WITHOUT ITERATING OVER EVERY ELEMENT OF BOTH? arraydiffs? slices? Figure that shit out and you're golden-->
 
<!-- nevermind you just add each resource only after checking if that resource already exists and then add/modify the corresponding quantity in the other array -->
 
{{#arraydefine: neededBasicResources}}
 
{{#arraydefine: neededQuantities}}
 
{{#vardefine: i | 0 }}
 
<!--{{#while:
 
  | {{#ifexpr: {{#var: i}} < {{#arraysize: outputBufferList}} | true }}
 
  | {{#vardefine: startPosResource | {{#expr: {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{!}} }} + 1 }} }}
 
    {{#vardefine: endPosResource | {{#pos: {{#arrayindex: outputBufferList | {{#var: i}} }} | ]] }} }}
 
    {{#vardefine: resource | {{#sub: {{#arrayindex: outputBufferList | {{#var: i}} }} | {{#var: startPosResource}} | {{#expr: {{#var: endPosResource}}  {{#var: startPosResource}} }} }}
 
    {{#ifeq: {{#show: {{#var: resource}} |?BoolCraft }} | false
 
      |
 
    }}
 
}}-->
 
{{#arraysort: neededBasicResources |asc}}
 
 
<!-- everything below this comment is probably shit and can be thrown away-->
 
 
{{#vardefine: i | 0 }}{{#vardefine: x | 1 }}{{#vardefine: totalMana | 0 }}{{#vardefine: calcMana | true }}
 
{{#while: <!-- checks every kind of basic resource and adds all occurences into an array-->
 
  | {{#ifexpr: {{#var: i}} < {{#arraysize: basicResources}} | true }}
 
  | {{#vardefine: resourceQuantity | 0 }}
 
    {{#if: {{#pos: {{#var: outputBuffer}} | {{#arrayindex: outputBufferList | {{#var: i}} }} }} <!-- checks if resource even exists in recipe tree-->
 
      | {{#vardefine: n | 0 }}
 
        {{#while: <!-- iterates through all elements of the outputBufferList to search for resource XYZ-->
 
          | {{#ifexpr: {{#var: n}} < {{#arraysize: outputBufferList}} | true }}
 
          | {{#if: {{#pos: {{#arrayindex: outputBufferList | {{#var: n}} }} | {{#arrayindex: basicResources | {{#var: i}} }} }} <!-- checks if current line is a basic resource that has to be added to the basic resource list (+ quantity)-->
 
              | {{#vardefine: currentQuantity | {{#sub: {{#arrayindex: outputBufferList | {{#var: n}} }} | 0 | {{#expr: {{#pos: {{#arrayindex: outputBufferList | {{#var: n}} }} }} - 1 }} }} }} <!-- extract quantity from string-->
 
                {{#vardefine: resourceQuantity | {{#expr: {{#var: resourceQuantity}} + {{#var: currentQuantity}} }} }}
 
            }}
 
            {{#ifeq: {{#var: calcMana}} | true
 
              | {{#ifeq: {{#rpos: {{#arrayindex: outputBufferList | {{#var: n}} }} | Mana }} | -1 <!-- checks if the item uses mana to add to the mana tally-->
 
                  | <!-- this branch gets executed if there is no mana cost connected to that item-->
 
                  | {{#vardefine: startPosMana | {{#expr: {{#rpos: {{#arrayindex: outputBufferList | {{#var: n}} }} | ,<nowiki> </nowiki> }} + 2 }} }}
 
                    {{#vardefine: endPosMana | {{#pos: {{#arrayindex: outputBufferList | {{#var: n}} }} | {{Emoticon|emoticon=Mana}} }} }}
 
                    {{#vardefine: mana | {{#sub: {{#arrayindex: outputBufferList | {{#var: n}} }} | {{#var: startPosMana}} | {{#expr: {{#var: endPosMana}} - {{#var: startPosMana}} }} }} }}
 
                    {{#vardefine: totalMana | {{#expr: {{#var: totalMana}} + {{#var: mana}} }} }}
 
                }}
 
            }}
 
            {{#vardefine: n | {{#expr: {{#var: n}} + 1 }} }}
 
        }}
 
    }}
 
    {{#ifeq: {{#var: resourceQuantity}} | 0
 
      | <!--this branch gets executed if resource quantity is 0 of a given resource-->
 
      | {{#var: resourceQuantity}}x {{#arrayindex: basicResources | {{#var: i}} }},<nowiki> </nowiki>
 
    }}
 
    {{#vardefine: calcMana | false }}
 
    i: {{#vardefineecho: i | {{#expr: {{#var: i}} + 1 }} }}<br>
 
}}
 
Ingredient Mana cost: {{#var: totalMana}}{{Emoticon|emoticon=Mana}}
 
 
</noinclude>
 
</noinclude>

Latest revision as of 15:32, 31 October 2023

Generates a BoM (Bill of Materials) for an item. Has three modes you can choose with the template parameter outputMode:

  • outputMode = list - Show the most basic resources with all amounts added up.
  • outputMode = tree - Show a tree style list with all the needed resources as child of the intermediate ingredient with different levels of indentation (done)
  • outputMode = all - Show both (Default mode in case parameter is left out)

Uses sub-template Template:ResourceBreakdown