Template:Recipe
From StarMade Wiki
Revision as of 17:35, 19 October 2014 by Der scheme (talk)
Error: Unknown block
Creates manufacturing trees.
Usage
{{recipe|grey hull}}
{{recipe|blue advanced armor wedge}}
{{recipe|blue advanced armor wedge|recursive=yes}}
Editing
Template was created using the following script:
#!/usr/bin/env ruby # # Author: Sebastian Dufner # License: I don't care, consider it public domain. # # Usage example: mw-recipe-template BLOCKCONFIG | xclip -sel clipboard require 'rexml/document' abort "Usage: mw-recipe-template BLOCKCONFIG" unless ARGV.size == 1 class Block Dependency = Struct.new(:block, :count) def self.blocks(block_config) blocks = {} doc = REXML::Document.new(File.open(block_config)) REXML::XPath::each(doc, '//Block') do |node| block = from_xml(node) blocks[block.type] = block end blocks.values.each do |block| block.dependencies.map! {|dep| Dependency.new(blocks[dep[0]], dep[1])} end end def self.from_xml(node) type = node.attributes['type'] name = node.attributes['name'] deps = node.find {|child| child.name == 'Consistence' if child.is_a? REXML::Element}.map do |item| [item.text, item.attributes['count']] if item.is_a? REXML::Element end Block.new(type, name, deps.compact) end private_class_method :from_xml def initialize(type, name, dependencies = []) @type, @name, @dependencies = type, name, dependencies end attr_accessor :type, :name, :dependencies def to_s(depth: 0, horizontal: true, note: nil) result = "{{tree|[[File:#{name}.png]]" result.concat '|root' if depth == 0 result.concat "|note=#{note}" if note result.concat '|class=' result.concat 'manufacturing_tree ' if depth == 0 if dependencies.size > 0 result.concat 'horizontal ' if horizontal result.concat 'single ' if dependencies.size == 1 && dependencies[0].block.dependencies.size == 0 result.concat '{{#ifeq: {{{recursive|no}}}|yes||single}}' if dependencies.size == 1 result.concat '|children=' result.concat '{{#ifeq: {{{recursive|no}}}|yes|' if depth == 1 dependencies.each do |dep| result.concat(dep.block.to_s( depth: depth + 1, horizontal: !horizontal, note: (dep.count == '1' ? nil : dep.count) )) end result.concat '|}}' if depth == 1 end result.concat '}}' end end template = '{{#switch: {{lc: {{{1}}}}}' Block.blocks(ARGV[0]).each do |block| template.concat "|#{block.name.downcase}=#{block.to_s}" end template.concat '|#default=Error: Unknown block}}' puts template
The above documentation is transcluded from Template:Recipe/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories and interwikis to the /doc subpage. Subpages of this template. |