Difference between revisions of "Template:BoM"
(finished code for list bom, need to clean up and move to actual position) |
(first "finished" version of list style bom) |
||
Line 1: | Line 1: | ||
− | {{#vardefine: recipeSource | {{{source|{{PAGENAME}} }}} }}{{#vardefine: outputMode | {{{mode| | + | {{#vardefine: recipeSource | {{{source|{{PAGENAME}} }}} }}{{#vardefine: outputMode | {{{mode|all}}} }}<!-- |
-->{{#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 26: | Line 26: | ||
List of basic resources + mana usage | List of basic resources + mana usage | ||
-->{{#switch: {{#var: outputMode}} | -->{{#switch: {{#var: outputMode}} | ||
− | | list | all = {{#vardefine: | + | | list | all = <br>{{#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) |
− | + | -->{{#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)--><!-- | |
− | | | + | |
− | + | -->{{#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 <!-- 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 }} | ||
+ | }} | ||
+ | {{#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 }} }} | ||
}} | }} | ||
+ | {{#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}} + {{#show: {{#var: recipeSource}} |?ManaCrafting}} }}{{Emoticon|emoticon=Mana}} (Ingredients: {{#var: totalMana}}{{Emoticon|emoticon=Mana}} / Item: {{#show: {{#var: recipeSource}} |?ManaCrafting}}{{Emoticon|emoticon=Mana}}) | ||
}}</div></div><!-- | }}</div></div><!-- | ||
--></includeonly><noinclude> | --></includeonly><noinclude> | ||
Line 51: | Line 82: | ||
<!-- needs empty lines removed--> | <!-- needs empty lines removed--> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</noinclude> | </noinclude> |
Revision as of 15:41, 4 January 2019
Generates a BoM (Bill of Materials) for an item. Has three modes:
- Show the most basic resources with all amounts added up. (WIP)
- Show a tree style list with all the needed resources as child of the intermediate ingredient with different levels of indentation (done)
- Show both
Uses sub-template Template:ResourceBreakdown