home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 July / maximum-cd-2010-07.iso / DiscContents / wesnoth-1.8-win32.exe / data / tools / unit_tree / animations.py < prev    next >
Encoding:
Text File  |  2008-10-06  |  4.0 KB  |  152 lines

  1. def write_animation(out, aa, name):
  2.     c = [0, 0]
  3.     for a in aa:
  4.         count_animations(out, name, a, c)
  5.     if c[1] > 1:
  6.         out.write("%d (%d)" % (c[0], c[1]))
  7.     else:
  8.         out.write("%d" % c[0])
  9.  
  10. def count_animations(out, name, a, c):
  11.     frames = a.get_subs("frame")
  12.     if frames:
  13.         c[0] += len(frames)
  14.         c[1] += 1
  15.     for a2 in a.get_subs("animation"):
  16.         count_animations(out, name, a2, c)
  17.     for a2 in a.get_subs("if"):
  18.         count_animations(out, name, a2, c)
  19.     for a2 in a.get_subs("else"):
  20.         count_animations(out, name, a2, c)
  21.  
  22. def write_table_row(out, unit, color, name = None):
  23.     anim_types = [
  24.         "attack_anim",
  25.         "defend",
  26.         "death",
  27.         "idle_anim",
  28.         "movement_anim",
  29.         "leading_anim",
  30.         "teleport",
  31.         "standing_anim",
  32.         "healing_anim",
  33.         "victory_anim",
  34.         "poison_anim",
  35.         "healed_anim",
  36.         "recruit_anim",
  37.         "levelin_anim",
  38.         "levelout_anim",
  39.         "extra_anim",
  40.     ]
  41.     
  42.     needed = {}
  43.     for at in anim_types: needed[at] = True
  44.  
  45.     needed["healing_anim"] = False
  46.     needed["leading_anim"] = False
  47.     needed["teleport"] = False
  48.     for abil in unit.get_subs("abilities"):
  49.         if abil.get_subs("heals"):
  50.             needed["healing_anim"] = True
  51.         if abil.get_subs("leadership"):
  52.             needed["leading_anim"] = True
  53.         if abil.get_subs("teleport"):
  54.             needed["teleport"] = True     
  55.  
  56.     if name == None: name = unit.id
  57.  
  58.     out.write("<tr><td class=\"%s\">%s</td>" % (color and "c1" or "c2", name))
  59.  
  60.     for t in anim_types:
  61.         if needed[t]:
  62.             aa = unit.get_subs(t)
  63.             if t == "extra_anim":
  64.                 out.write("<td class=\"none\">")
  65.             else:
  66.                 out.write("<td class=\"%s\">" % (aa and "ok" or "not"))
  67.             write_animation(out, aa, t)
  68.             out.write("</td>")
  69.         else:
  70.             out.write("<td class=\"none\">-</td>")
  71.  
  72.     out.write("</tr>\n")
  73.  
  74.     female = unit.get_first("female")
  75.     if female: write_table_row(out, female, color, name + "[f]")
  76.  
  77.     for variation in unit.get_all("variation"):
  78.         write_table_row(out, variation, color, name + "[%s]" %
  79.             variation.get_text_val("variation_name"))
  80.  
  81. def put_units(f, us):
  82.     f.write("<table>\n")
  83.     f.write("<tr>\n")
  84.     f.write("""
  85. <th>id</th>
  86. <th>attack</th>
  87. <th>defend</th>
  88. <th>death</th>
  89. <th>idle</th>
  90. <th>movement</th>
  91. <th>leading</th>
  92. <th>teleport</th>
  93. <th>standing</th>
  94. <th>healing</th>
  95. <th>victory</th>
  96. <th>poison</th>
  97. <th>healed</th>
  98. <th>recruit</th>
  99. <th>level in</th>
  100. <th>level out</th>
  101. <th>extra</th>
  102. """.lstrip())
  103.     f.write("</tr>\n")
  104.     
  105.     def by_race(u1, u2):
  106.         r1 = u1.rid
  107.         r2 = u2.rid
  108.         r = cmp(r1, r2)
  109.         if r == 0: r = cmp(u1.id, u2.id)
  110.         return r
  111.     us.sort(by_race)
  112.     race = None
  113.     color = 0
  114.     for u in us:
  115.         if u.race != race:
  116.             race = u.race
  117.             color ^= 1
  118.         write_table_row(f, u, color)
  119.  
  120.     f.write("</table>\n")
  121.  
  122. def write_table(f, wesnoth):
  123.     f.write("""
  124. <html>
  125. <head>
  126. <style type="text/css">
  127. th {font-size: small; }
  128. td {white-space: nowrap; width: 1px; }
  129. td.c1 {background-color: #fff080;}
  130. td.c2 {background-color: #80f0ff;}
  131. td.ok {border: solid 1px; background-color: #80ff80;}
  132. td.not {border: solid 1px; background-color: #ff8080;}
  133. td.none {border: solid 1px; background-color: #ffffff;}
  134. </style>
  135. </head>
  136. <body>
  137. """.lstrip())
  138.     f.write("<h1>animation statistics</h1>\n")
  139.     f.write("<i>total frames (number of animations)</i>\n")
  140.     
  141.     f.write("<h2>Mainline</h2>\n")
  142.     us = [x for x in wesnoth.unit_lookup.values() if x.campaign == "mainline"]
  143.     put_units(f, us)
  144.     
  145.     f.write("<h2>Campaigns and Addons</h2>\n")
  146.     us = [x for x in wesnoth.unit_lookup.values() if x.campaign != "mainline"]
  147.     put_units(f, us)
  148.  
  149.     f.write("</body></html>")
  150.     f.close()    
  151.  
  152.