BUH
This commit is contained in:
parent
0675db7afb
commit
fccf2d214d
19
Makefile
19
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<h1>{filename}</h1>\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"<pre style=\"color:red;\">{ex}</pre>"
|
||||
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"
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
There is no fun to be gained here, be warned.
|
||||
|
||||
*Here be dragons*
|
|
@ -89,7 +89,13 @@
|
|||
</header>
|
||||
{% if card.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) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<figure>
|
||||
|
@ -99,6 +105,31 @@
|
|||
</figure>
|
||||
<aside>
|
||||
<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 %}
|
||||
<li>{{ property }}</li>
|
||||
{% endfor %}
|
||||
|
@ -107,18 +138,36 @@
|
|||
<div class="costbar">
|
||||
{% for cost in card.costs %}
|
||||
<section>
|
||||
{% if cost.split() | length == 2 and cost.split()[0].isnumeric() %}
|
||||
<big>{{ cost.split()[0] }}</big><br>
|
||||
<small>{{ cost.split()[1] }}</small>
|
||||
{% if cost.split(" ") | length == 2 and cost.split(" ")[0] | int(-1) != -1 %}
|
||||
<big>{{ cost.split(" ")[0] }}</big><br>
|
||||
<small>{{ cost.split(" ")[1] }}</small>
|
||||
{% else %}
|
||||
{{ cost }}
|
||||
{% endif %}
|
||||
</section>
|
||||
{% 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 class="description">
|
||||
{% if card.flavor %}
|
||||
<center><i>"{{ card.flavor }}"</i></center>
|
||||
{% endif %}
|
||||
{% if card.description %}
|
||||
<center>{{ card.description | markdown | safe }}</center>
|
||||
{% endif %}
|
||||
{% if card.steps %}
|
||||
<ul>
|
||||
{% for step in card.steps %}
|
||||
|
|
26
style.js
26
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 = "<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);
|
||||
|
|
24
style.scss
24
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";
|
||||
|
|
39
sync.py
39
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 == "<span class='ui success'>XSL Updated</span>":
|
||||
print("Success!")
|
||||
else:
|
||||
print("Failed:")
|
||||
print(resp.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
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":
|
||||
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()
|
||||
|
|
|
@ -1,19 +1,5 @@
|
|||
<ability_card><yaml_data>
|
||||
{{ data.strip() }}
|
||||
</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>
|
||||
{{ xml_data }}
|
||||
</ability_card>
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
<xsl:output method="xml" omit-xml-declaration="yes" />
|
||||
<xsl:template match="/*">
|
||||
{% set newline = "<xsl:text disable-output-escaping='yes'>\n</xsl:text>" %}
|
||||
|
||||
{% set gt = "<xsl:text disable-output-escaping='yes'>></xsl:text>" %}
|
||||
{% set lt = "<xsl:text disable-output-escaping='yes'><</xsl:text>" %}
|
||||
{% set amp = "<xsl:text disable-output-escaping='yes'>&</xsl:text>" %}
|
||||
<html>
|
||||
|
||||
{% filter replace(">", ">foobarhuehuehue")
|
||||
| replace("<", "<xsl:text disable-output-escaping='yes'><</xsl:text>")
|
||||
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>></xsl:text>")
|
||||
| replace("<", lt)
|
||||
| replace(">foobarhuehuehue", gt)
|
||||
| replace("\n", newline)
|
||||
| replace("</xsl:text><xsl:text disable-output-escaping='yes'>", "") %}
|
||||
|
||||
|
@ -46,7 +48,7 @@
|
|||
"difficulty",
|
||||
"duration",
|
||||
"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 }}
|
||||
{% endfor %}
|
||||
|
||||
|
@ -63,9 +65,9 @@ var jinja_template =
|
|||
{{ js_data.strip()
|
||||
| replace(">", ">foobarhuehuehue")
|
||||
| replace("&", "&spismegdinnisse")
|
||||
| replace("<", "<xsl:text disable-output-escaping='yes'><</xsl:text>")
|
||||
| replace(">foobarhuehuehue", "<xsl:text disable-output-escaping='yes'>></xsl:text>")
|
||||
| replace("&spismegdinnisse", "<xsl:text disable-output-escaping='yes'>&</xsl:text>") }}
|
||||
| replace("<", lt)
|
||||
| replace(">foobarhuehuehue", gt)
|
||||
| replace("&spismegdinnisse", amp) }}
|
||||
</script>
|
||||
|
||||
{{ newline*2 }}
|
||||
|
|
|
@ -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>
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue