Difference between revisions of "Template:BoM"

From ChatWars Wiki
Jump to: navigation, search
(update to code for list style bom (still unfinished))
Line 6: Line 6:
 
{{#vardefine: outputBuffer
 
{{#vardefine: outputBuffer
 
   | {{#ask:
 
   | {{#ask:
     [[-Has subobject::<!--Lion Helmet-->{{#var: recipeSource}}]] [[Crafting ingredient.ItemType::+]] [[Crafting ingredient.ItemType::!Recipe (Item)]] [[Crafting ingredient.ItemType::!Piece of Equipment]]
+
     [[-Has subobject::{{#var: recipeSource}}]] [[Crafting ingredient.ItemType::+]] [[Crafting ingredient.ItemType::!Recipe (Item)]] [[Crafting ingredient.ItemType::!Piece of Equipment]]
 
     |mainlabel=-
 
     |mainlabel=-
 
     |headers=hide
 
     |headers=hide
Line 22: Line 22:
 
{{#switch: {{#var: outputMode}}
 
{{#switch: {{#var: outputMode}}
 
   | tree | all = {{#var: outputBuffer}}
 
   | tree | all = {{#var: outputBuffer}}
}}{{#ifeq: {{{testmode|}}} | true | {{#vardefineecho: a | <nowiki><nowiki></nowiki>{{#var: outputBuffer}}<nowiki></nowiki></nowiki>}}}}<!--
+
}}<!--
  
 
List of basic resources + mana usage
 
List of basic resources + mana usage
Line 57: Line 57:
 
{{#arrayslice: outputBufferList | outputBufferList | 1}} <!-- remove the one empty element that somehow makes it through the filter (dont know dont care)-->
 
{{#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>}}
 
{{#arraysize: outputBufferList}}/{{#arrayprint: outputBufferList  | <br>}}
{{#arraydefine: basicResources | {{#ask: [[ItemType::Resource]] [[BoolCraft::false]] |mainlabel= |link=none |headers=none |order=asc |sort=ItemID |limit=5000}} }}
 
  
{{#vardefine: i | 0 }}{{#vardefine: x | 1 }}{{#vardefine: totalMana | 0 }}
+
{{#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-->
 
{{#while: <!-- checks every kind of basic resource and adds all occurences into an array-->
 
   | {{#ifexpr: {{#var: i}} < {{#arraysize: basicResources}} | true }}
 
   | {{#ifexpr: {{#var: i}} < {{#arraysize: basicResources}} | true }}
 
   | {{#vardefine: resourceQuantity | 0 }}
 
   | {{#vardefine: resourceQuantity | 0 }}
     {{#if: {{#pos: {{#var: outputBuffer}} | {{!}}{{#arrayindex: outputBufferList | {{#var: i}} }}]] }} <!-- checks if resource even exists in recipe tree-->
+
     {{#if: {{#pos: {{#var: outputBuffer}} | {{#arrayindex: outputBufferList | {{#var: i}} }} }} <!-- checks if resource even exists in recipe tree-->
 
       | {{#vardefine: n | 0 }}
 
       | {{#vardefine: n | 0 }}
 
         {{#while: <!-- iterates through all elements of the outputBufferList to search for resource XYZ-->
 
         {{#while: <!-- iterates through all elements of the outputBufferList to search for resource XYZ-->
 
           | {{#ifexpr: {{#var: n}} < {{#arraysize: outputBufferList}} | true }}
 
           | {{#ifexpr: {{#var: n}} < {{#arraysize: outputBufferList}} | true }}
           | {{#if: {{#pos: {{#arrayindex: outputBufferList | {{#var: n}} }} | {{!}}{{#arrayindex: basicResources | {{#var: i}} }}]] }}
+
           | {{#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: 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}} }} }}
 
                 {{#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 }} }}
 
             {{#vardefine: n | {{#expr: {{#var: n}} + 1 }} }}
 
         }}
 
         }}
 
     }}
 
     }}
     {{#var: resourceQuantity}}x {{#arrayindex: basicResources | {{#var: i}} }}<br>
+
     {{#ifeq: {{#var: resourceQuantity}} | 0
     {{#vardefine: i | {{#expr: {{#var: i}} + 1 }} }}
+
      | <!--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>

Revision as of 16:13, 3 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


2/,


0/






i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
i: 8
i: 9
i: 10
i: 11
i: 12
i: 13
i: 14
i: 15
i: 16
i: 17
i: 18
i: 19
i: 20
i: 21
i: 22
i: 23
i: 24
i: 25
i: 26
i: 27
i: 28
i: 29
i: 30
i: 31
i: 32
i: 33
i: 34
i: 35
i: 36
i: 37
i: 38
i: 39
i: 40
i: 41
i: 42
i: 43
i: 44
i: 45
i: 46
i: 47
i: 48
i: 49
i: 50
i: 51
i: 52
i: 53
i: 54
i: 55
i: 56
i: 57
i: 58
Ingredient Mana cost: 0link={{{link}}}