Expand on the card model
This commit is contained in:
@@ -5,24 +5,49 @@ from common import Model
|
|||||||
import config
|
import config
|
||||||
|
|
||||||
class Card(Model):
|
class Card(Model):
|
||||||
filename = "[[filename_without_file_extention]]"
|
filename = ""#filename without extentions
|
||||||
title = "[[title]]"
|
title = "title"
|
||||||
figure = "code"#https://material.io/icons/
|
figure = "code"
|
||||||
description = "[[description]]"
|
figure_source = "material-icons"
|
||||||
|
#material-icons = https://material.io/icons/
|
||||||
|
#mdi = https://materialdesignicons.com/
|
||||||
|
#fa = http://fontawesome.io/icons/
|
||||||
|
#svg = the svgs/ folder
|
||||||
|
description = ""
|
||||||
steps = []
|
steps = []
|
||||||
effects = []
|
effects = []
|
||||||
cost = "free action"
|
cost = "free action"
|
||||||
power = None
|
power = None
|
||||||
cp = None
|
cp = None
|
||||||
|
gp = None#gold
|
||||||
flags = []
|
flags = []
|
||||||
|
notes = ""#not shown, but used to keep track of things
|
||||||
|
copies_owned = 1
|
||||||
|
|
||||||
def has_flag(self, flag): return flag in self.flags
|
def has_flag(self, flag):
|
||||||
|
return flag.lower() in map(lambda x: x.lower(), self.flags)
|
||||||
|
|
||||||
|
#todo: make the relevant ones into coroutines:
|
||||||
|
|
||||||
def from_file(filename, in_carddir=True):#yaml syntax
|
def from_file(filename, in_carddir=True):#yaml syntax
|
||||||
|
if filename[-5:] != ".yaml":
|
||||||
|
filename += ".yaml"
|
||||||
name = ".".join(os.path.basename(filename).split(".")[:-1])
|
name = ".".join(os.path.basename(filename).split(".")[:-1])
|
||||||
with open(os.path.join(config.carddir, filename) if in_carddir else filename, "r") as f:
|
with open(os.path.join(config.carddir, filename) if in_carddir else filename, "r") as f:
|
||||||
return from_yaml(f.read(), name)
|
return from_yaml(f.read(), name)
|
||||||
|
|
||||||
|
def to_file(card, in_carddir=True):
|
||||||
|
assert card.filename, "no filename set"
|
||||||
|
filename = card.filename+".yaml"
|
||||||
|
|
||||||
|
with open(os.path.join(config.carddir, filename) if in_carddir else filename, "w") as f:
|
||||||
|
f.write(to_yaml(card))
|
||||||
|
|
||||||
|
def del_file(card, in_carddir=True):
|
||||||
|
assert card.filename, "no filename set"
|
||||||
|
filename = card.filename+".yaml"
|
||||||
|
os.remove(os.path.join(config.carddir, filename) if in_carddir else filename)
|
||||||
|
|
||||||
def from_yaml(data, filename="from_yaml"):
|
def from_yaml(data, filename="from_yaml"):
|
||||||
card = Card()
|
card = Card()
|
||||||
card.filename = filename
|
card.filename = filename
|
||||||
@@ -30,5 +55,44 @@ def from_yaml(data, filename="from_yaml"):
|
|||||||
setattr(card, key, val)
|
setattr(card, key, val)
|
||||||
return card
|
return card
|
||||||
|
|
||||||
|
def to_yaml(card):
|
||||||
|
out = {}
|
||||||
|
for key in dir(card):
|
||||||
|
if "_" not in key[0] and key not in ("filename","has_flag"):
|
||||||
|
val = getattr(card, key)
|
||||||
|
if (val or val==0) and val != getattr(Card, key):
|
||||||
|
out[key] = val
|
||||||
|
return dump(out, default_flow_style=False)
|
||||||
|
|
||||||
def from_dir(path):
|
def from_dir(path):
|
||||||
return [from_file(i, in_carddir=False) for i in glob.glob(os.path.join(path, "*.yaml"))]
|
return [from_file(i, in_carddir=False) for i in glob.glob(os.path.join(path, "*.yaml"))]
|
||||||
|
|
||||||
|
def from_form(form):
|
||||||
|
card = Card()
|
||||||
|
for key, val in form.items():
|
||||||
|
if not val[0]: continue
|
||||||
|
if key in ("save", "delete"): continue
|
||||||
|
if type(getattr(Card, key)) in (tuple, list):
|
||||||
|
if len(val) == 1 and "\n" in val[0]:
|
||||||
|
val = val[0].strip().replace("\r\n", "\n").split("\n")
|
||||||
|
#val = [i for i in val if i]
|
||||||
|
setattr(card, key, val)
|
||||||
|
else:
|
||||||
|
setattr(card, key, val[0].strip().replace("\r\n", "\n"))
|
||||||
|
return card
|
||||||
|
|
||||||
|
def is_filename_vacant(filename, in_carddir=True):
|
||||||
|
if in_carddir:
|
||||||
|
filename = os.path.join(config.carddir, filename)
|
||||||
|
if filename[-5:] != ".yaml":
|
||||||
|
filename += ".yaml"
|
||||||
|
return not os.path.exists(filename)
|
||||||
|
|
||||||
|
class open_file:#contextmanager
|
||||||
|
def __init__(self, filename):
|
||||||
|
self.filename = filename
|
||||||
|
def __enter__(self):
|
||||||
|
self.card = from_file(self.filename)
|
||||||
|
return self.card
|
||||||
|
def __exit__(self, *args):
|
||||||
|
to_file(self.card)
|
||||||
|
|||||||
+32
-13
@@ -22,11 +22,11 @@ article {
|
|||||||
margin: 3mm 5mm;
|
margin: 3mm 5mm;
|
||||||
display: block;
|
display: block;
|
||||||
float: left;
|
float: left;
|
||||||
width: 5.5cm;
|
width: 5.6cm;
|
||||||
height: 8.9cm;
|
height: 8.9cm;
|
||||||
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2fr 1fr;
|
grid-template-columns: 5fr 2fr;
|
||||||
grid-template-rows: 2em 18mm 1.3em auto 1.5em;
|
grid-template-rows: 2em 18mm 1.3em auto 1.5em;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
"header header"
|
"header header"
|
||||||
@@ -36,11 +36,12 @@ article {
|
|||||||
"power cp";
|
"power cp";
|
||||||
|
|
||||||
border-radius: 2mm;
|
border-radius: 2mm;
|
||||||
grid-gap: 2mm 2mm;
|
grid-gap: 1.5mm 1.5mm;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 2mm;
|
border-width: 2mm;
|
||||||
border-color: #333;
|
border-color: #333;
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
article.effects {
|
article.effects {
|
||||||
grid-template-columns: 4fr 3fr;
|
grid-template-columns: 4fr 3fr;
|
||||||
@@ -57,28 +58,40 @@ article >* {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 1.4em;
|
line-height: 1.4em;
|
||||||
padding: 0 1mm;
|
padding: 0 1mm;
|
||||||
|
border-radius: 1mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
article h1 {
|
article h1 {
|
||||||
grid-area: header;
|
grid-area: header;
|
||||||
font-size: 1em;
|
|
||||||
padding: 1mm 0;
|
padding: 1mm 0;
|
||||||
font-size: 1.1em;
|
font-size: 1.2em;
|
||||||
|
line-height: 1.1em;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
article figure {
|
article figure {
|
||||||
grid-area: figure;
|
grid-area: figure;
|
||||||
background: #333;
|
background: none;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
article figure img{
|
article figure * {
|
||||||
height: 100%;
|
color: #999;
|
||||||
width: auto;
|
|
||||||
}
|
}
|
||||||
|
article figure img{
|
||||||
|
display: block;
|
||||||
|
height: 97%;
|
||||||
|
margin: auto auto;
|
||||||
|
}
|
||||||
|
article figure img.svg{
|
||||||
|
filter: invert(1) opacity(0.6);
|
||||||
|
}
|
||||||
|
article figure .mdi,
|
||||||
|
article figure .fa,
|
||||||
article figure .material-icons.figure {
|
article figure .material-icons.figure {
|
||||||
font-size: 1.7cm;
|
font-size: 1.7cm;
|
||||||
color: #999;
|
line-height: 1.7cm;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
article ul {
|
article ul {
|
||||||
@@ -88,14 +101,14 @@ article ul {
|
|||||||
}
|
}
|
||||||
|
|
||||||
article main {
|
article main {
|
||||||
padding: 2mm 0;
|
padding: 2mm 1mm;
|
||||||
grid-area: info;
|
grid-area: info;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
article main ol {
|
article main ol {
|
||||||
margin-top: 1mm;
|
margin-top: 1mm;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-left: 6mm;
|
padding-left: 5mm;
|
||||||
}
|
}
|
||||||
article main ol li + li{
|
article main ol li + li{
|
||||||
margin-top: 0.5mm;
|
margin-top: 0.5mm;
|
||||||
@@ -107,6 +120,7 @@ article main .bottom {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 2mm;
|
bottom: 2mm;
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
article .power {
|
article .power {
|
||||||
@@ -120,7 +134,8 @@ article .power:before{
|
|||||||
article .cost {
|
article .cost {
|
||||||
grid-area: cost;
|
grid-area: cost;
|
||||||
}
|
}
|
||||||
article .cp {
|
article .cp,
|
||||||
|
article .gp {
|
||||||
grid-area: cp;
|
grid-area: cp;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
@@ -128,3 +143,7 @@ article .cp:after{
|
|||||||
content: " CP";
|
content: " CP";
|
||||||
font-size: 0.7em;
|
font-size: 0.7em;
|
||||||
}
|
}
|
||||||
|
article .gp:after{
|
||||||
|
content: " Gold";
|
||||||
|
font-size: 0.6em;
|
||||||
|
}
|
||||||
|
|||||||
+72
-40
@@ -1,55 +1,87 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<link rel="stylesheet" href="card.css">
|
<link rel="stylesheet" href="card.css">
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
||||||
|
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css">
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
|
|
||||||
#foreach($card in $cards)
|
#foreach($card in $cards)
|
||||||
<article #if($card.effects) class="effects"#end>
|
<article #if($card.effects) class="effects"#end onclick="location.href='creator?filename=$escape_html($card.filename)'">
|
||||||
<h1>
|
<h1>
|
||||||
$escape_html($card.title)
|
$escape_html($card.title)
|
||||||
</h1>
|
</h1>
|
||||||
<figure>
|
<figure>
|
||||||
|
#if($card.figure_source == "material-icons")
|
||||||
<!--https://material.io/icons/-->
|
<!--https://material.io/icons/-->
|
||||||
<i class="material-icons figure">$escape_html($card.figure)</i>
|
<i class="material-icons figure">$escape_html($card.figure)</i>
|
||||||
</figure>
|
#elseif($card.figure_source == "mdi")
|
||||||
#if($card.effects)
|
<!--https://materialdesignicons.com/-->
|
||||||
<ul>
|
<i class="mdi mdi-$escape_html($card.figure)"></i>
|
||||||
#foreach($item in $card.effects)
|
#elseif($card.figure_source == "fa")
|
||||||
|
<!--http://fontawesome.io/icons/-->
|
||||||
|
<i class="fa fa-$escape_html($card.figure)"></i>
|
||||||
|
#elseif($card.figure_source == "svg")
|
||||||
|
<!--/cards/svg-->
|
||||||
|
<img class="svg" src="/svg/${escape_html($card.figure)}.svg">
|
||||||
|
#end
|
||||||
|
</figure>
|
||||||
|
#if($card.effects)
|
||||||
|
<ul>
|
||||||
|
#foreach($item in $card.effects)
|
||||||
|
#if($item)
|
||||||
<li>$escape_html($item)</li>
|
<li>$escape_html($item)</li>
|
||||||
#end
|
#end
|
||||||
</ul>
|
#end
|
||||||
#end
|
</ul>
|
||||||
<main>
|
#end
|
||||||
$escape_html($card.description)
|
<main>
|
||||||
#if($card.steps)
|
$escape_html($card.description)
|
||||||
<ol>
|
#if($card.steps)
|
||||||
#foreach($item in $card.steps)
|
<ol>
|
||||||
|
#foreach($item in $card.steps)
|
||||||
|
#if($item)
|
||||||
<li>$escape_html($item)</li>
|
<li>$escape_html($item)</li>
|
||||||
#end
|
#end
|
||||||
</ol>
|
#end
|
||||||
#end
|
</ol>
|
||||||
#if($card.flags)
|
#end
|
||||||
<div class="bottom">
|
#if($card.flags)
|
||||||
<small>-
|
<div class="bottom">
|
||||||
#foreach($flag in $card.flags)
|
<small>
|
||||||
$escape_html($flag.capitalize()) -
|
-
|
||||||
|
#foreach($flag in $card.flags)
|
||||||
|
#if(!$flag && $foreach.hasNext)
|
||||||
|
- <br> -
|
||||||
|
#else
|
||||||
|
$escape_html($flag.capitalize())#if($foreach.hasNext), #end
|
||||||
#end
|
#end
|
||||||
</small>
|
|
||||||
<br>
|
|
||||||
#if($card.has_flag("mastery"))
|
|
||||||
<big>
|
|
||||||
❏ ❏ ❏ ❏ ❏
|
|
||||||
❏ ❏ ❏ ❏ ❏
|
|
||||||
</big>
|
|
||||||
#end
|
#end
|
||||||
</div>
|
-
|
||||||
#end
|
</small>
|
||||||
</main>
|
<br>
|
||||||
<div class="cost">$escape_html($card.cost)</div>
|
#if($card.has_flag("mastery"))
|
||||||
#if($card.power)
|
<big>
|
||||||
<div class="power">$escape_html($card.power)</div>
|
❏ ❏ ❏ ❏ ❏
|
||||||
|
❏ ❏ ❏ ❏ ❏
|
||||||
|
</big>
|
||||||
|
#end
|
||||||
|
</div>
|
||||||
#end
|
#end
|
||||||
#if($card.power)
|
</main>
|
||||||
<div class="cp">$escape_html($card.cp)</div>
|
<div class="cost">$escape_html($card.cost)</div>
|
||||||
#end
|
#if($card.power)
|
||||||
</article>
|
<div class="power">$escape_html($card.power)</div>
|
||||||
|
#end
|
||||||
|
#if($card.cp)
|
||||||
|
<div class="cp">$escape_html($card.cp)</div>
|
||||||
|
#elseif($card.gp)
|
||||||
|
<div class="gp">$escape_html($card.gp)</div>
|
||||||
|
#end
|
||||||
|
</article>
|
||||||
|
#end
|
||||||
|
|
||||||
|
#if($was_saved)
|
||||||
|
<center style="position: absolute; bottom:0; width: 100%;">The card has been saved</center>
|
||||||
|
#end
|
||||||
|
#if($was_deleted)
|
||||||
|
<center style="position: absolute; bottom:0; width: 100%;">The card has been removed from storage</center>
|
||||||
#end
|
#end
|
||||||
|
|||||||
Reference in New Issue
Block a user