about summary refs log tree commit diff stats
path: root/util/generate_gamedata.rb
blob: 5940480406cd835ec2445d465e230295bed1a9b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highligh
require 'yaml'

configpath = ARGV[0]
outputpath = ARGV[1]

config = YAML.load_file(configpath)
output = config.map do |panel|
  ret = panel
  if ret["color"].kind_of? String
    ret["color"] = [ret["color"]]
  end
  ret
end.map do |panel|
  ret = {}
  ret["id"] = "\"#{panel["id"]}\""
  ret["color"] = "[\"" + panel["color"].join("\",\"") + "\"]"
  ret["tag"] = "\"#{panel["tag"]}\""
  if panel.include? "subtag"
    ret["subtag"] = "\"#{panel["subtag"]}\""
  end
  if panel.include? "link"
    ret["link"] = "\"#{panel["link"]}\""
  end
  if panel.include? "copy_to_sign"
    copytos = []
    if panel["copy_to_sign"].kind_of? String
      copytos = [panel["copy_to_sign"]]
    else
      copytos = panel["copy_to_sign"]
    end
    ret["copy_to_sign"] = "[\"" + copytos.join("\",\"") + "\"]"
  end
    ret
end.map do |panel|
  "{" + panel.to_a.map do |element|
    "\"#{element[0]}\":#{element[1]}"
  end.join(",") + "}"
end.join(",")

header = "extends Node\n\nvar panels = ["
footer = "]"

File.write(outputpath, header + output + footer)