This commit is contained in:
Peder Bergebakken Sundt 2019-10-06 21:43:37 +02:00
parent 0675db7afb
commit fccf2d214d
10 changed files with 164 additions and 79 deletions

View File

@ -5,17 +5,21 @@ CARDS_DESTS := $(patsubst cards/%.yaml,cards/build/%.html,$(CARDS))
.PHONY: all .PHONY: all
all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html
.PHONY: style
style: build/style.xsl
.PHONY: dev .PHONY: dev
dev: dev:
git ls-files | entr bash -c "make build/test_card.html build/test_card_rendered.html"
.PHONY: dev_all
dev_all:
git ls-files | entr bash -c "make all" git ls-files | entr bash -c "make all"
.PHONY: dev_test
dev_test:
git ls-files | entr bash -c "make build/test_card.html build/test_card_rendered.html"
.PHONY: clean .PHONY: clean
clean: clean:
rm build/* cards/build/* rm -v build/* cards/build/*
build/test_card.html: build/card.xml build/style.xsl build/test_card.html: build/card.xml build/style.xsl
xsltproc \ xsltproc \
@ -41,7 +45,7 @@ with open(sys.argv[2], "w") as f:
if sys.argv[1] == "ALL": f.write(f"\n\n<h1>{filename}</h1>\n") if sys.argv[1] == "ALL": f.write(f"\n\n<h1>{filename}</h1>\n")
with open(filename) as f2: data = f2.read() with open(filename) as f2: data = f2.read()
try: try:
data = e.get_template('style.html.j2').render(card=yaml.load(data)) data = e.get_template('style.html.j2').render(card=yaml.load(data), xml={})
except Exception as ex: except Exception as ex:
data = f"<pre style=\"color:red;\">{ex}</pre>" data = f"<pre style=\"color:red;\">{ex}</pre>"
f.write("\n" + data) f.write("\n" + data)
@ -63,14 +67,15 @@ cards/build/all.html: $(CARDS) style.html.j2 build/style.css templates/card_head
define PYTHON_MAKE_CARD_XML define PYTHON_MAKE_CARD_XML
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
with open("test_card.yaml") as f: data = f.read() with open("test_card.yaml") as f: data = f.read()
with open("test_card.xml") as f: xml_data = f.read()
with open("build/card.xml", "w") as f: with open("build/card.xml", "w") as f:
f.write(Environment( f.write(Environment(
loader=FileSystemLoader('templates')) loader=FileSystemLoader('templates'))
.get_template('card.xml.j2') .get_template('card.xml.j2')
.render(data=data)) .render(data=data, xml_data=xml_data))
endef endef
export PYTHON_MAKE_CARD_XML export PYTHON_MAKE_CARD_XML
build/card.xml: test_card.yaml templates/card.xml.j2 build/card.xml: test_card.yaml test_card.xml templates/card.xml.j2
python3 -c "$$PYTHON_MAKE_CARD_XML" python3 -c "$$PYTHON_MAKE_CARD_XML"

3
readme.md Normal file
View File

@ -0,0 +1,3 @@
There is no fun to be gained here, be warned.
*Here be dragons*

View File

@ -89,7 +89,13 @@
</header> </header>
{% if card.icon %} {% if card.icon %}
<div class="icon"> <div class="icon">
{% if " " in card.icon %}
{% for icon in card.icon.split(" ") %}
{{ named_icon_to_emoji(icon) }}
{% endfor %}
{% else %}
{{ named_icon_to_emoji(card.icon) }} {{ named_icon_to_emoji(card.icon) }}
{% endif %}
</div> </div>
{% endif %} {% endif %}
<figure> <figure>
@ -99,6 +105,31 @@
</figure> </figure>
<aside> <aside>
<ul> <ul>
{#
{% if card.cp %}
<li>CP: {{ card.cp }}</li>
{% endif %}
{% if card.power %}
<li>Power: {{ card.power }}</li>
{% endif %}
{% if card.difficulty %}
<li>Difficulty: {{ card.difficulty }}</li>
{% endif %}
{% if card.playcost %}
<li>Playcost: {{ card.playcost }}</li>
{% endif %}
{% if card.duration %}
<li>Duration: {{ card.duration }}</li>
{% endif %}
{% if card.range %}
<li>Range: {{ card.range }}</li>
{% endif %}
#}
{% if xml.playcost %}
{% for playcost in xml.playcost.split(",") %}
<li>{{ playcost }}</li>
{% endfor %}
{% endif %}
{% for property in card.properties %} {% for property in card.properties %}
<li>{{ property }}</li> <li>{{ property }}</li>
{% endfor %} {% endfor %}
@ -107,18 +138,36 @@
<div class="costbar"> <div class="costbar">
{% for cost in card.costs %} {% for cost in card.costs %}
<section> <section>
{% if cost.split() | length == 2 and cost.split()[0].isnumeric() %} {% if cost.split(" ") | length == 2 and cost.split(" ")[0] | int(-1) != -1 %}
<big>{{ cost.split()[0] }}</big><br> <big>{{ cost.split(" ")[0] }}</big><br>
<small>{{ cost.split()[1] }}</small> <small>{{ cost.split(" ")[1] }}</small>
{% else %} {% else %}
{{ cost }} {{ cost }}
{% endif %} {% endif %}
</section> </section>
{% endfor %} {% endfor %}
{% for label, data in [
["Difficulty", xml.difficulty],
["Power", xml.power],
["Range", xml.range],
["Duration", xml.duration],
["CP", xml.cp]
] %}
{% if data %}
<section>
<big>{{ data }}</big><br>
<small>{{ label }}</small>
</section>
{% endif %}
{% endfor %}
</div> </div>
<div class="description"> <div class="description">
{% if card.flavor %}
<center><i>"{{ card.flavor }}"</i></center> <center><i>"{{ card.flavor }}"</i></center>
{% endif %}
{% if card.description %}
<center>{{ card.description | markdown | safe }}</center> <center>{{ card.description | markdown | safe }}</center>
{% endif %}
{% if card.steps %} {% if card.steps %}
<ul> <ul>
{% for step in card.steps %} {% for step in card.steps %}

View File

@ -14,21 +14,19 @@ for (var i=0; i < xml_data_items.length; i++) {
} }
function is_set(asd) { function is_set(asd) {
return typeof asd === 'undefined' || asd === "XML" || asd.length === 0; return !(typeof asd === 'undefined' || asd.length === 0);
} }
if (!is_set(context.card.title) && context.xml.name ) context.card.title = context.xml.name; 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.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.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 = [{ if (!is_set(context.card.figures) && context.xml.image ) context.card.figures = [{
'name': context.xml.image, 'name': (context.xml.image.substr(0, 4) == "http")
'type': "url", ? context.xml.image
: context.xml.image.split(":").slice(1).join(":"),
'type': (context.xml.image.substr(0, 4) == "http")
? "url"
: context.xml.image.split(":")[0],
'scale': 1.0, 'scale': 1.0,
'flip_x': false, 'flip_x': false,
'flip_y': false, 'flip_y': false,
@ -37,7 +35,7 @@ if (!is_set(context.card.figures) && context.xml.image ) context.card.f
'rotation': 0, 'rotation': 0,
}]; }];
var env = new nunjucks.Environment({ var env = new nunjucks.Environment([], {
autoescape: true, autoescape: true,
trimBlocks: true, trimBlocks: true,
lstripBlocks: true, lstripBlocks: true,
@ -61,6 +59,10 @@ env.addFilter('all', function(iterable) {
return true; return true;
}); });
try {
rendered = env.renderString(jinja_template, context); rendered = env.renderString(jinja_template, context);
//console.log(rendered); } catch(err) {
rendered = "<pre style=\"font-size:0.8em; width:100%; border-radius:5px; padding:2mm; box-sizing: border-box; border: 2px solid black; white-space: normal; background-color:#ff8888;\">" + err + "</pre>";
}
console.log(rendered);
document.write(rendered); document.write(rendered);

View File

@ -8,25 +8,25 @@
border-color: black; border-color: black;
border-style: solid; border-style: solid;
background-color: #444; background-color: #444;
overflow: hidden;
font-size: 3mm; font-size: 2.5mm;
font-family: sans-serif; font-family: sans-serif;
display: grid; display: grid;
grid-template-columns: 5fr 3fr 2em; grid-template-columns: auto 1fr 0.9in;
grid-template-rows: 1.5em var(--figure-size) 2.1em auto; grid-template-rows: 1.9em var(--figure-size) 2.1em auto;
grid-template-areas: grid-template-areas:
"title title icon" "icon title title"
"figure properties properties" "figure figure properties"
"costbar costbar costbar" "costbar costbar costbar"
"description description description"; "description description description";
header { header {
grid-area: title; grid-area: title;
font-size: 1.5em; font-size: 1.8em;
line-height: 1em; line-height: 1em;
margin-top: -1mm; margin-top: -1mm;
margin-right: -1em; margin-left: -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;
@ -38,6 +38,8 @@
text-align: center; text-align: center;
background-color: #222; background-color: #222;
color: white; color: white;
padding-top: 0.6mm;
padding-left: 0.8mm;
white-space: nowrap; white-space: nowrap;
} }
figure { figure {
@ -90,6 +92,7 @@
background-color: #aaa; background-color: #aaa;
padding: 0.5mm; padding: 0.5mm;
ul { ul {
margin:0;
list-style-type: none; list-style-type: none;
padding: 0; padding: 0;
li{ li{
@ -135,7 +138,6 @@
border-radius: 0mm; border-radius: 0mm;
border-width: 0.3mm; border-width: 0.3mm;
background-color: #fff; background-color: #fff;
grid-template-rows: 1.6em var(--figure-size) 2.1em auto;
header { header {
margin-top: 0; margin-top: 0;
background-color: #ddd; background-color: #ddd;
@ -170,9 +172,9 @@
.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 2em; grid-template-columns: auto 1fr;
grid-template-areas: grid-template-areas:
"title icon" "icon title"
"figure figure" "figure figure"
"costbar costbar" "costbar costbar"
"description description"; "description description";

39
sync.py
View File

@ -4,6 +4,8 @@ from requests.auth import HTTPBasicAuth
import json import json
import os import os
import requests import requests
import requests.packages.urllib3.util.connection as urllib3_cn
import socket
import xmltodict import xmltodict
MY_COLLECTION = "Fjompens fjomperi" MY_COLLECTION = "Fjompens fjomperi"
@ -11,22 +13,30 @@ MY_ID = "26"
AUTH = None AUTH = None
CARD_STYLE = 6 # Fjompens's card style CARD_STYLE = 6 # Fjompens's card style
##FORCE_IPV4 = False
##def allowed_gai_family(): # used to force either ipv4 or ipv6
## family = socket.AF_INET
## if not FORCE_IPV4 and urllib3_cn.HAS_IPV6:
## family = socket.AF_INET6 # force ipv6 only if it is available
## return family
##urllib3_cn.allowed_gai_family = allowed_gai_family
def get_card_ids(): def get_card_ids():
resp = requests.get("http://pvv.org/~andreasd/cards/command.php?cmd=get_all_cards", auth=AUTH) resp = requests.get("https://www.pvv.ntnu.no/~andreasd/cards/command.php?cmd=get_all_cards", auth=AUTH)
for collection in resp.json(): for collection in resp.json():
if collection["name"] == MY_COLLECTION and collection["id"] == MY_ID: if collection["name"] == MY_COLLECTION and collection["id"] == MY_ID:
return collection["cards"] return collection["cards"]
def get_card_xml(card_id:int): def get_card_xml(card_id:int):
resp = requests.get(f"http://pvv.org/~andreasd/cards/command.php?cmd=get_card_xml&id={card_id}", auth=AUTH) resp = requests.get(f"https://www.pvv.ntnu.no/~andreasd/cards/command.php?cmd=get_card_xml&id={card_id}", auth=AUTH)
return resp.text return resp.text
def get_card_style_id(card_id:int): def get_card_style_id(card_id:int):
resp = requests.get(f"http://pvv.org/~andreasd/cards/command.php?cmd=get_card_style&id={card_id}", auth=AUTH) resp = requests.get(f"https://www.pvv.ntnu.no/~andreasd/cards/command.php?cmd=get_card_style&id={card_id}", auth=AUTH)
return resp.text return resp.text
def set_card_xml(card_id:int, xml_data): def set_card_xml(card_id:int, xml_data):
resp = requests.post(f"http://pvv.org/~andreasd/cards/command.php", auth=AUTH, data={ resp = requests.post(f"https://www.pvv.ntnu.no/~andreasd/cards/command.php", auth=AUTH, data={
"cmd" : "update_card_text", "cmd" : "update_card_text",
"id" : str(card_id), "id" : str(card_id),
"data" :xml_data, "data" :xml_data,
@ -110,13 +120,32 @@ def push_all():
else: else:
print("FAILED!") print("FAILED!")
def push_style():
print(f"POSTing build/style.xsl to site... ", end="")
with open("build/style.xsl") as f:
xsl_data = f.read()
resp = requests.post(f"http://pvv.org/~andreasd/cards/command.php", auth=AUTH, data={
"cmd" : "update_style_xsl",
"id" : str(CARD_STYLE),
"xsl" : str(xsl_data),
})
if resp.ok and resp.text == "<span class='ui success'>XSL Updated</span>":
print("Success!")
else:
print("Failed:")
print(resp.text)
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
if len(sys.argv) < 4: if len(sys.argv) < 4:
print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'push' or 'pull'\n") print(__file__, "<action> <uname> <passwd>\n\n\taction: either 'push', 'push_style' or 'pull'\n")
elif sys.argv[1].strip().lower() == "pull": elif sys.argv[1].strip().lower() == "pull":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3]) AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
pull_all() pull_all()
elif sys.argv[1].strip().lower() == "push": elif sys.argv[1].strip().lower() == "push":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3]) AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_all() push_all()
elif sys.argv[1].strip().lower() == "push_style":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_style()

View File

@ -1,19 +1,5 @@
<ability_card><yaml_data> <ability_card><yaml_data>
{{ data.strip() }} {{ data.strip() }}
</yaml_data> </yaml_data>
<name>Mega Fireball</name> {{ xml_data }}
<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> </ability_card>

View File

@ -2,12 +2,14 @@
<xsl:output method="xml" omit-xml-declaration="yes" /> <xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="/*"> <xsl:template match="/*">
{% set newline = "<xsl:text disable-output-escaping='yes'>\n</xsl:text>" %} {% set newline = "<xsl:text disable-output-escaping='yes'>\n</xsl:text>" %}
{% set gt = "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>" %}
{% set lt = "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>" %}
{% set amp = "<xsl:text disable-output-escaping='yes'>&amp;</xsl:text>" %}
<html> <html>
{% filter replace(">", ">foobarhuehuehue") {% filter replace(">", ">foobarhuehuehue")
| replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>") | replace("<", lt)
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>") | replace(">foobarhuehuehue", gt)
| replace("\n", newline) | replace("\n", newline)
| replace("</xsl:text><xsl:text disable-output-escaping='yes'>", "") %} | replace("</xsl:text><xsl:text disable-output-escaping='yes'>", "") %}
@ -46,7 +48,7 @@
"difficulty", "difficulty",
"duration", "duration",
"playcost"] %} "playcost"] %}
<script type="text/html" class="xml_data" id="xml_data_{{ value }}"><xsl:value-of select="{{ value }}"/></script> {{lt}}script type="text/html" class="xml_data" id="xml_data_{{ value }}"{{gt}}<xsl:value-of select="{{ value }}"/>{{lt}}/script{{gt}}
{{ newline }} {{ newline }}
{% endfor %} {% endfor %}
@ -63,9 +65,9 @@ var jinja_template =
{{ js_data.strip() {{ js_data.strip()
| replace(">", ">foobarhuehuehue") | replace(">", ">foobarhuehuehue")
| replace("&", "&spismegdinnisse") | replace("&", "&spismegdinnisse")
| replace("<", "<xsl:text disable-output-escaping='yes'>&lt;</xsl:text>") | replace("<", lt)
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>&gt;</xsl:text>") | replace(">foobarhuehuehue", gt)
| replace("&spismegdinnisse", "<xsl:text disable-output-escaping='yes'>&amp;</xsl:text>") }} | replace("&spismegdinnisse", amp) }}
</script> </script>
{{ newline*2 }} {{ newline*2 }}

15
test_card.xml Normal file
View File

@ -0,0 +1,15 @@
<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>

View File

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