diff --git a/Makefile b/Makefile
index f540939..648b8c1 100644
--- a/Makefile
+++ b/Makefile
@@ -5,17 +5,21 @@ CARDS_DESTS := $(patsubst cards/%.yaml,cards/build/%.html,$(CARDS))
.PHONY: all
all: build/test_card.html build/test_card_rendered.html $(CARDS_DESTS) cards/build/all.html
+.PHONY: style
+style: build/style.xsl
+
.PHONY: 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"
-.PHONY: dev_test
-dev_test:
- git ls-files | entr bash -c "make build/test_card.html build/test_card_rendered.html"
.PHONY: clean
clean:
- rm build/* cards/build/*
+ rm -v build/* cards/build/*
build/test_card.html: build/card.xml build/style.xsl
xsltproc \
@@ -41,7 +45,7 @@ with open(sys.argv[2], "w") as f:
if sys.argv[1] == "ALL": f.write(f"\n\n
{filename} \n")
with open(filename) as f2: data = f2.read()
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:
data = f"{ex} "
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
from jinja2 import Environment, FileSystemLoader
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:
f.write(Environment(
loader=FileSystemLoader('templates'))
.get_template('card.xml.j2')
- .render(data=data))
+ .render(data=data, xml_data=xml_data))
endef
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"
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..75cfd60
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,3 @@
+There is no fun to be gained here, be warned.
+
+*Here be dragons*
diff --git a/style.html.j2 b/style.html.j2
index 0563f0f..e8fbe29 100644
--- a/style.html.j2
+++ b/style.html.j2
@@ -89,7 +89,13 @@
{% if card.icon %}
- {{ named_icon_to_emoji(card.icon) }}
+ {% if " " in card.icon %}
+ {% for icon in card.icon.split(" ") %}
+ {{ named_icon_to_emoji(icon) }}
+ {% endfor %}
+ {% else %}
+ {{ named_icon_to_emoji(card.icon) }}
+ {% endif %}
{% endif %}
@@ -99,33 +105,76 @@
+ {#
+ {% if card.cp %}
+ CP: {{ card.cp }}
+ {% endif %}
+ {% if card.power %}
+ Power: {{ card.power }}
+ {% endif %}
+ {% if card.difficulty %}
+ Difficulty: {{ card.difficulty }}
+ {% endif %}
+ {% if card.playcost %}
+ Playcost: {{ card.playcost }}
+ {% endif %}
+ {% if card.duration %}
+ Duration: {{ card.duration }}
+ {% endif %}
+ {% if card.range %}
+ Range: {{ card.range }}
+ {% endif %}
+ #}
+ {% if xml.playcost %}
+ {% for playcost in xml.playcost.split(",") %}
+ {{ playcost }}
+ {% endfor %}
+ {% endif %}
{% for property in card.properties %}
{{ property }}
{% endfor %}
- {% for cost in card.costs %}
-
- {% if cost.split() | length == 2 and cost.split()[0].isnumeric() %}
- {{ cost.split()[0] }}
- {{ cost.split()[1] }}
- {% else %}
- {{ cost }}
- {% endif %}
-
- {% endfor %}
+ {% for cost in card.costs %}
+
+ {% if cost.split(" ") | length == 2 and cost.split(" ")[0] | int(-1) != -1 %}
+ {{ cost.split(" ")[0] }}
+ {{ cost.split(" ")[1] }}
+ {% else %}
+ {{ cost }}
+ {% endif %}
+
+ {% endfor %}
+ {% for label, data in [
+ ["Difficulty", xml.difficulty],
+ ["Power", xml.power],
+ ["Range", xml.range],
+ ["Duration", xml.duration],
+ ["CP", xml.cp]
+ ] %}
+ {% if data %}
+
+ {{ data }}
+ {{ label }}
+
+ {% endif %}
+ {% endfor %}
+ {% if card.flavor %}
"{{ card.flavor }}"
+ {% endif %}
+ {% if card.description %}
{{ card.description | markdown | safe }}
- {% if card.steps %}
+ {% endif %}
+ {% if card.steps %}
{% for step in card.steps %}
{{ step }}
{% endfor %}
- {% endif %}
+ {% endif %}
diff --git a/style.js b/style.js
index 7fed17f..cc5d0c2 100644
--- a/style.js
+++ b/style.js
@@ -14,21 +14,19 @@ for (var i=0; i < xml_data_items.length; i++) {
}
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.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",
+ 'name': (context.xml.image.substr(0, 4) == "http")
+ ? 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,
'flip_x': false,
'flip_y': false,
@@ -37,7 +35,7 @@ if (!is_set(context.card.figures) && context.xml.image ) context.card.f
'rotation': 0,
}];
-var env = new nunjucks.Environment({
+var env = new nunjucks.Environment([], {
autoescape: true,
trimBlocks: true,
lstripBlocks: true,
@@ -61,6 +59,10 @@ env.addFilter('all', function(iterable) {
return true;
});
-rendered = env.renderString(jinja_template, context);
-//console.log(rendered);
+try {
+ rendered = env.renderString(jinja_template, context);
+} catch(err) {
+ rendered = "" + err + " ";
+}
+console.log(rendered);
document.write(rendered);
diff --git a/style.scss b/style.scss
index 4347e12..25ca021 100644
--- a/style.scss
+++ b/style.scss
@@ -8,25 +8,25 @@
border-color: black;
border-style: solid;
background-color: #444;
+ overflow: hidden;
- font-size: 3mm;
+ font-size: 2.5mm;
font-family: sans-serif;
display: grid;
- grid-template-columns: 5fr 3fr 2em;
- grid-template-rows: 1.5em var(--figure-size) 2.1em auto;
+ grid-template-columns: auto 1fr 0.9in;
+ grid-template-rows: 1.9em var(--figure-size) 2.1em auto;
grid-template-areas:
- "title title icon"
- "figure properties properties"
+ "icon title title"
+ "figure figure properties"
"costbar costbar costbar"
"description description description";
-
header {
grid-area: title;
- font-size: 1.5em;
+ font-size: 1.8em;
line-height: 1em;
margin-top: -1mm;
- margin-right: -1em;
+ margin-left: -1em;
border-radius: 1mm 1mm 0 0;
text-align: center;
background-color: #222;
@@ -38,6 +38,8 @@
text-align: center;
background-color: #222;
color: white;
+ padding-top: 0.6mm;
+ padding-left: 0.8mm;
white-space: nowrap;
}
figure {
@@ -90,6 +92,7 @@
background-color: #aaa;
padding: 0.5mm;
ul {
+ margin:0;
list-style-type: none;
padding: 0;
li{
@@ -135,7 +138,6 @@
border-radius: 0mm;
border-width: 0.3mm;
background-color: #fff;
- grid-template-rows: 1.6em var(--figure-size) 2.1em auto;
header {
margin-top: 0;
background-color: #ddd;
@@ -170,9 +172,9 @@
.fjomp_card.item {
--figure-size: 1.35in;
--figure-size: 1.5in;
- grid-template-columns: 1fr 2em;
+ grid-template-columns: auto 1fr;
grid-template-areas:
- "title icon"
+ "icon title"
"figure figure"
"costbar costbar"
"description description";
diff --git a/sync.py b/sync.py
index f7b62f2..74b4c5f 100755
--- a/sync.py
+++ b/sync.py
@@ -4,6 +4,8 @@ from requests.auth import HTTPBasicAuth
import json
import os
import requests
+import requests.packages.urllib3.util.connection as urllib3_cn
+import socket
import xmltodict
MY_COLLECTION = "Fjompens fjomperi"
@@ -11,22 +13,30 @@ MY_ID = "26"
AUTH = None
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():
- 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():
if collection["name"] == MY_COLLECTION and collection["id"] == MY_ID:
return collection["cards"]
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
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
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",
"id" : str(card_id),
"data" :xml_data,
@@ -110,13 +120,32 @@ def push_all():
else:
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 == "XSL Updated ":
+ print("Success!")
+ else:
+ print("Failed:")
+ print(resp.text)
+
+
if __name__ == "__main__":
import sys
if len(sys.argv) < 4:
- print(__file__, " \n\n\taction: either 'push' or 'pull'\n")
+ print(__file__, " \n\n\taction: either 'push', 'push_style' or 'pull'\n")
elif sys.argv[1].strip().lower() == "pull":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
pull_all()
elif sys.argv[1].strip().lower() == "push":
AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
push_all()
+ elif sys.argv[1].strip().lower() == "push_style":
+ AUTH = HTTPBasicAuth(sys.argv[2], sys.argv[3])
+ push_style()
diff --git a/templates/card.xml.j2 b/templates/card.xml.j2
index 1047525..47be01a 100644
--- a/templates/card.xml.j2
+++ b/templates/card.xml.j2
@@ -1,19 +1,5 @@
{{ data.strip() }}
-Mega Fireball
-Attack an enemy in range 5.
-
-Roll MAG hit dice. Deal that amount of FIRE damage to the target.
-https://freepngimg.com/download/fireball/27487-2-fireball-clipart.png
-18
-4
-MAG + (0 to 2)
-🔮🔥⚔️
-1
-
-2 ACT,
-Not Silenced,
-3 MP,
-Equipment has Catalyst property
+{{ xml_data }}
diff --git a/templates/style.xsl.j2 b/templates/style.xsl.j2
index 3b2cecc..fb3bbd5 100644
--- a/templates/style.xsl.j2
+++ b/templates/style.xsl.j2
@@ -2,12 +2,14 @@
{% set newline = "\n " %}
-
+{% set gt = "> " %}
+{% set lt = "< " %}
+{% set amp = "& " %}
{% filter replace(">", ">foobarhuehuehue")
- | replace("<", "< ")
- | replace(">foobarhuehuehue", "> ")
+ | replace("<", lt)
+ | replace(">foobarhuehuehue", gt)
| replace("\n", newline)
| replace("", "") %}
@@ -46,7 +48,7 @@
"difficulty",
"duration",
"playcost"] %}
-
+{{lt}}script type="text/html" class="xml_data" id="xml_data_{{ value }}"{{gt}} {{lt}}/script{{gt}}
{{ newline }}
{% endfor %}
@@ -63,9 +65,9 @@ var jinja_template =
{{ js_data.strip()
| replace(">", ">foobarhuehuehue")
| replace("&", "&spismegdinnisse")
- | replace("<", "< ")
- | replace(">foobarhuehuehue", "> ")
- | replace("&spismegdinnisse", "& ") }}
+ | replace("<", lt)
+ | replace(">foobarhuehuehue", gt)
+ | replace("&spismegdinnisse", amp) }}
{{ newline*2 }}
diff --git a/test_card.xml b/test_card.xml
new file mode 100644
index 0000000..d6a4cfb
--- /dev/null
+++ b/test_card.xml
@@ -0,0 +1,15 @@
+Mega Fireball
+Attack an enemy in range 5.
+
+Roll MAG hit dice. Deal that amount of FIRE damage to the target.
+https://freepngimg.com/download/fireball/27487-2-fireball-clipart.png
+18
+4
+MAG + (0 to 2)
+🔮🔥⚔️
+1
+
+2 ACT,
+Not Silenced,
+3 MP,
+Equipment has Catalyst property
diff --git a/test_card.yaml b/test_card.yaml
index 78bbda9..8c729ce 100644
--- a/test_card.yaml
+++ b/test_card.yaml
@@ -1,14 +1,6 @@
title: Hit enemy
icon: defence
-style: white item
-
-cp: XML
-power: XML
-difficulty: XML
-duration: XML
-playcost: XML
-range: XML
-
+style: white
tags:
- combat
costs: