Using this The code just give "data", and there is a HTML template file to be filled in with the data.
and this engine generates a HTML file that can be viewed as a webpage.
the in-game help shows this generated HTML.
The HELP
i have found a help for a perl templaing engine having the same synthax(or is it the same?), here it is:
https://metacpan.org/pod/HTML::Template
the real one:
http://html-tmpl-java.sourceforge.net/
LOOPS:
in template: looks like this (see the item "tmpl_loop"):
Code: Select all
<tmpl_loop up_spells_details>
<tr onClick="toggleMe('<tmpl_var name="up_spell_id">')">
<td class="txt_spell_bonus"><img width="32" src="<tmpl_var up_spell_img>" /> </td>
<td class="txt_spell_bonus"><tmpl_var up_spell_name></td>
<td class="txt_spell_bonus"><tmpl_var up_spell_chance></td>
<td class="txt_spell_bonus"><tmpl_var up_spell_range></td>
<td class="txt_spell_bonus"><tmpl_var up_spell_timeout></td>
<td class="txt_spell_bonus"><tmpl_var up_spell_cooldown></td>
</tr>
<tr class='collapsible_row' id="<tmpl_var name="up_spell_id">">
<td colspan="6" width="100%" class="txt_spell_bonus" >
<p>
<tmpl_var name="up_spell_desc">
</p>
<p>
<!-- <tmpl_var name="up_spell_action"> -->
Tranlsated Name of unit effect (ActionUnitID)
</p>
</td>
</tr>
</tmpl_loop>
(fills up to template everything needed for the "loop")
i try to make Yellow the interesting parts:
in nutshell:
you create a vector of hashtables,
and in a loop you fill the vector adding one hashtable with key-value pairs for each row,
finally adding the vector to templating engine with name up_spell_details in this example.
not so complex, this little method does everything.
private static void appendSpells(Unit u, String imgLocationPrefix, Template t) {
Code: Select all
//up_spells_details: abilites detailed list
//fetching the spells he can cast
Unit sample = UnitSamples.samples.get(u.type);
if (sample.weaponEffectOptions != null && sample.weaponEffectOptions.size() > 0) {
Vector<Hashtable<String, String>> v = new Vector<Hashtable<String, String>>();
int[] weaponOptions = ZTSPacket.arrayMergeSafe(
sample.weaponEffectOptions.get(Unit.WEAPON_EFFECT_SLOT_SPELLCAST),
sample.weaponEffectOptions.get(Unit.WEAPON_EFFECT_SLOT_WP_1)
);
for (int wo : weaponOptions) {
Hashtable<String, String> h = new Hashtable<String, String>();
EffectDef ef = Const.effectDefs.get(wo);
h.put("up_spell_img", imgLocationPrefix + ef.getImageNameOfEffect().imageName);
h.put("up_spell_id", ef.effectNameString);
h.put("up_spell_name", ef.getName());
//getting the descriptive text if any
String descr = "(no description)";
int descID = Unit.getDescrtiptiveTXTid(ef.effectNameString);
if (descID != 0) {
descr = ZTSApplication.getContext().getString(descID);
}
h.put("up_spell_desc", descr);
h.put("up_spell_chance", Math.round(ef.chancePercent * 100) + "%");
h.put("up_spell_range", String.valueOf(ef.castRangeModifier + u.convertRange));
if (ef.hasTimeout() && ef.lastsTurnNr > 0)
h.put("up_spell_timeout", String.valueOf(ef.lastsTurnNr));
else
h.put("up_spell_timeout", "Instant");
if (ef.hasCooldown())
h.put("up_spell_cooldown", String.valueOf(ef.cooldownTurnNr));
else
h.put("up_spell_cooldown", "-");
v.addElement(h);
}
t.setParam("up_spells_details", v);
}//spells
}