Add ability to read xml tags

This commit is contained in:
Peder Bergebakken Sundt 2019-10-06 16:03:07 +02:00
parent 1263c5aac2
commit 0675db7afb
9 changed files with 92 additions and 8 deletions

View File

@ -11,7 +11,7 @@ dev:
.PHONY: dev_test .PHONY: dev_test
dev_test: dev_test:
git ls-files | entr bash -c "make build/test_card_rendered.html" git ls-files | entr bash -c "make build/test_card.html build/test_card_rendered.html"
.PHONY: clean .PHONY: clean
clean: clean:

View File

@ -2,3 +2,4 @@ Jinja2
libsass libsass
Markdown Markdown
PyYAML PyYAML
xmltodict

View File

@ -45,7 +45,7 @@
{% else %} {% else %}
<img src="https://pvv.ntnu.no/~pederbs/cards/img/data/{{ figure.name }}"> <img src="https://pvv.ntnu.no/~pederbs/cards/img/data/{{ figure.name }}">
{% endif %} {% endif %}
{% elif not figure.type %} {% elif figure.type == "url" %}
{% if figure.color == true %} {% if figure.color == true %}
<img src="{{ figure.name }}" class="colored"> <img src="{{ figure.name }}" class="colored">
{% elif figure.color %} {% elif figure.color %}

View File

@ -1,9 +1,42 @@
var md = window.markdownit(); var md = window.markdownit();
var context = { var context = {
'xml' : {},
'card' : jsyaml.load(document.getElementById("yaml_data").innerHTML), 'card' : jsyaml.load(document.getElementById("yaml_data").innerHTML),
'alert' : alert, 'alert' : alert,
}; };
// read xml data
var xml_data_items = document.getElementsByClassName("xml_data")
for (var i=0; i < xml_data_items.length; i++) {
var key = xml_data_items[i].id.substr(9);
var val = xml_data_items[i].innerHTML;
context.xml[key] = val;
}
function is_set(asd) {
return typeof asd === 'undefined' || asd === "XML" || asd.length === 0;
}
if (!is_set(context.card.title) && context.xml.name ) context.card.title = context.xml.name;
if (!is_set(context.card.icon) && context.xml.symbol ) context.card.icon = context.xml.symbol;
if (!is_set(context.card.description) && context.xml.description) context.card.description = context.xml.description;
if (!is_set(context.card.cp) && context.xml.cp ) context.card.cp = context.xml.cp;
if (!is_set(context.card.power) && context.xml.power ) context.card.power = context.xml.power;
if (!is_set(context.card.difficulty) && context.xml.difficulty ) context.card.difficulty = context.xml.difficulty;
if (!is_set(context.card.duration) && context.xml.duration ) context.card.duration = context.xml.duration;
if (!is_set(context.card.playcost) && context.xml.playcost ) context.card.playcost = context.xml.playcost;
if (!is_set(context.card.range) && context.xml.range ) context.card.range = context.xml.range;
if (!is_set(context.card.figures) && context.xml.image ) context.card.figures = [{
'name': context.xml.image,
'type': "url",
'scale': 1.0,
'flip_x': false,
'flip_y': false,
'offset': [0.0, 0.0],
'opacity': 1,
'rotation': 0,
}];
var env = new nunjucks.Environment({ var env = new nunjucks.Environment({
autoescape: true, autoescape: true,
trimBlocks: true, trimBlocks: true,
@ -29,5 +62,5 @@ env.addFilter('all', function(iterable) {
}); });
rendered = env.renderString(jinja_template, context); rendered = env.renderString(jinja_template, context);
console.log(rendered); //console.log(rendered);
document.write(rendered); document.write(rendered);

View File

@ -13,7 +13,7 @@
font-family: sans-serif; font-family: sans-serif;
display: grid; display: grid;
grid-template-columns: 5fr 3fr auto; grid-template-columns: 5fr 3fr 2em;
grid-template-rows: 1.5em var(--figure-size) 2.1em auto; grid-template-rows: 1.5em var(--figure-size) 2.1em auto;
grid-template-areas: grid-template-areas:
"title title icon" "title title icon"
@ -26,6 +26,7 @@
font-size: 1.5em; font-size: 1.5em;
line-height: 1em; line-height: 1em;
margin-top: -1mm; margin-top: -1mm;
margin-right: -1em;
border-radius: 1mm 1mm 0 0; border-radius: 1mm 1mm 0 0;
text-align: center; text-align: center;
background-color: #222; background-color: #222;
@ -34,8 +35,10 @@
} }
.icon { .icon {
grid-area: icon; grid-area: icon;
text-align: center;
background-color: #222; background-color: #222;
color: white; color: white;
white-space: nowrap;
} }
figure { figure {
grid-area: figure; grid-area: figure;
@ -167,7 +170,7 @@
.fjomp_card.item { .fjomp_card.item {
--figure-size: 1.35in; --figure-size: 1.35in;
--figure-size: 1.5in; --figure-size: 1.5in;
grid-template-columns: 1fr; grid-template-columns: 1fr 2em;
grid-template-areas: grid-template-areas:
"title icon" "title icon"
"figure figure" "figure figure"

View File

@ -1,3 +1,19 @@
<ability_card><yaml_data> <ability_card><yaml_data>
{{ data.strip() }} {{ data.strip() }}
</yaml_data></ability_card> </yaml_data>
<name>Mega Fireball</name>
<description>Attack an enemy in range 5.
Roll MAG hit dice. Deal that amount of FIRE damage to the target.</description>
<image>https://freepngimg.com/download/fireball/27487-2-fireball-clipart.png</image>
<cp>18</cp>
<range>4</range>
<power>MAG + (0 to 2)</power>
<symbol>🔮🔥⚔️</symbol>
<difficulty>1</difficulty>
<duration></duration>
<playcost>2 ACT,
Not Silenced,
3 MP,
Equipment has Catalyst property</playcost>
</ability_card>

View File

@ -1,7 +1,8 @@
{% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" -%} {% set async = "media=\"none\" onload=\"if(media!='all')media='all'\"" -%}
{% if is_local %} {% if is_local %}
<meta http-equiv="refresh" content="0.5"> <meta http-equiv="refresh" content="1.0">
{# {#
<script type="text/javascript" src="http://livejs.com/live.js"></script> <script type="text/javascript" src="http://livejs.com/live.js"></script>
#} #}

View File

@ -34,6 +34,24 @@
{{ newline*2 }} {{ newline*2 }}
{# just name all the xml fields of interest here #}
{% for value in [
"name",
"description",
"image",
"cp",
"range",
"power",
"symbol",
"difficulty",
"duration",
"playcost"] %}
<script type="text/html" class="xml_data" id="xml_data_{{ value }}"><xsl:value-of select="{{ value }}"/></script>
{{ newline }}
{% endfor %}
{{ newline*2 }}
<script type="text/javascript"> <script type="text/javascript">
var jinja_template = var jinja_template =
{{ jinja_data.strip() | tojson | replace("\\n", "\\n\" +\n\"") }}; {{ jinja_data.strip() | tojson | replace("\\n", "\\n\" +\n\"") }};
@ -44,8 +62,10 @@ var jinja_template =
<script type="text/javascript"> <script type="text/javascript">
{{ js_data.strip() {{ js_data.strip()
| replace(">", ">foobarhuehuehue") | replace(">", ">foobarhuehuehue")
| replace("&", "&spismegdinnisse")
| replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>") | replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>")
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>") }} | replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>")
| replace("&spismegdinnisse", "<xsl:text disable-output-escaping='yes'>&amp;</xsl:text>") }}
</script> </script>
{{ newline*2 }} {{ newline*2 }}

View File

@ -1,4 +1,14 @@
title: Hit enemy title: Hit enemy
icon: defence
style: white item
cp: XML
power: XML
difficulty: XML
duration: XML
playcost: XML
range: XML
tags: tags:
- combat - combat
costs: costs: