partially port 48 to 49

This commit is contained in:
Peder Bergebakken Sundt 2022-11-29 23:16:31 +01:00
parent fda2f29235
commit 7a2d4c5801
4 changed files with 368 additions and 29 deletions

View File

@ -27,6 +27,6 @@ _(The pull is destructive.)_
### How do I build a style?
make render-style-48-file
make render-style-49-file
Where `49` is the style ID.

View File

@ -4,10 +4,12 @@ import nimja/parser
import sequtils
import strutils
import strformat
import math
import tables
import sugar
import sugar # lambda syntax
#import jscore
# XPATH JSON stuff
type Entry = object
@ -25,11 +27,7 @@ proc get(key: string): Entry =
for entry in entries:
if entry.xpath == fmt"/ability_card/{key}":
return entry
assert false
#proc get_first(path: str): Entry =
# for entry in entries:
# if entry
nil
type Component = object
key : string # db_entry
@ -54,16 +52,15 @@ for entry in entries:
# YAML stuff
# Nimja Stuff
proc renderIndex(
title : string,
entries : seq[Entry],
get : (string) -> Entry,
): string =
compileTemplateFile(getScriptDir() / "main.nimja", )
proc is_numeric*(s: string): bool =
try:
discard s.parseFloat()
result = true
except:
discard
document.write renderIndex(
"index",
entries,
get,
)
proc renderIndex(): string =
compileTemplateFile(getScriptDir() / "main.nimja")
document.write renderIndex()

View File

@ -1,4 +1,163 @@
{##}
{% let name = get("name") .content %}
{% let description = get("description").content %}
{% let image = get("image") .content %}
{% let procs = get("procs") .content %}
{% let cp = get("cp") .content %}
{% let range = get("range") .content %}
{% let aoe = get("aoe") .content %}
{% let duration = get("duration") .content %}
{% let power = get("power") .content %}
{% let playcost = get("playcost") .content %}
{% proc mk_cost_bar(): string = %}
<div class="bar">
{% for parts in playcost.split(",").map (x) => x.strip().split(" ") %}
{% if parts[0].is_numeric() %}
<section>
<big>{{ parts[0] }}</big><br>
<small>{{ parts[1..^1].join(" ") }}</small>
</section>
{% elif parts.len() == 1 %}
<section>
<big>{{ 1 }}</big><br>
<small>{{ playcost }}</small>
</section>
{% endif %}
{% endfor %}
</div>
{% endmacro %}
{% proc mk_effect_bar(): string = %}
<div class="bar">
<section>
<big>{{ power }}</big><br>
<small>power</small>
</section>
{## }
{% if duration != "" %}
<section>
<big>{{ duration }}</big><br>
<small>Duration</small>
</section>
{% endif %}
{##}
</div>
{% endmacro %}
{% proc mk_figure(): string = %}
<div class="layer">
<img src="{{ image }}">
</div>
{% endmacro %}
{% proc mk_desc(): string = %}
<div class="description vbox">
<div class="grow">{# start top-justified #}
<center><i>{{ description }}</i></center>
<div class="hbox">
<div class="grow">
{# column one #}
<table>
{% for proc_line in procs.splitlines() %}
{% let p = proc_line.split() %}
<tr>
{# number of dies #}<td>{{ p[0] }}
{# procs #}<td>{{ p[1] }}
{# arrow #}<td>{{ p[2] }}
{# effect #}<td>{{ p[3..^1].join("\n") }}
</tr>
{% endfor %}
</table>
</div>
<div>
{# column two #}
</div>
</div>
</div>{# end top-justified #}
<div>{# start bottom-justified #}
<center>
&#x274F; &#x274F; &#x274F; &#x274F; &#x274F;
&#x274F; &#x274F; &#x274F; &#x274F; &#x274F;
</center>
</div>{# end bottom-justified #}
</div>
{% endmacro %}
{% proc mk_sidebar(): string = %}
<div>
{% for _ in 0..<2 %}
<div class="range-grid">
{% for x in 1..7 %}{% for y in 1..7 %}
<div style="grid-row: {{ x }}; grid-column: {{ y }}; background: LightSkyBlue"></div>
{% endfor %}{% endfor %}
<div class="label">AoE</div>
{% for x in 1..7 %}{% for y in 1..7 %}
{% if (x-4)^2 + (y-4)^2 <= 3^2 %}
<div style="grid-row: {{ x }}; grid-column: {{ y }}; background: green"></div>
{% endif %}
{% endfor %}{% endfor %}
{% for (x, y) in [
(3, 3),
(3, 4),
(3, 5),
] %}
<div style="grid-row: {{ x }}; grid-column: {{ y }}; background: var(--color-bg-costbar)"></div>
{% endfor %}
{#
<div style="grid-row: 2; grid-column: 5; background: var(--color-bg-costbar)"></div>
#}
</div>
{% endfor %}
</div>
{% endproc %}
<div class="fjomp_card">
<header class="hbox">
<span class=" ">symbol</span>
<span class="grow">{{ name }}</span>
</header>
{{ mk_cost_bar() }}
<div class="hbox">
<div class="vbox grow">
<figure class="grow">
{{ mk_figure() }}
</figure>
</div>
{{ mk_sidebar() }}
</div>
{{ mk_effect_bar() }}
{{ mk_desc() }}
<div class="bar vbox">
{##}
{% if duration != "" %}
<div> Duration: {{ duration }} </div>
{% endif %}
{##}
{## }
<div>
&#x274F; &#x274F; &#x274F; &#x274F; &#x274F;
&#x274F; &#x274F; &#x274F; &#x274F; &#x274F;
</div>
{##}
<div class="rjust grow"> {{ cp }} CP </div>
</div>
</div>
<table>
<tr><th>range </th><td>{{ range }}</td></tr>
<tr><th>aoe </th><td>{{ aoe }}</td></tr>
<tr><th>duration</th><td>{{ duration }}</td></tr>
<tr><th>power </th><td>{{ power }}</td></tr>
<tr><th>playcost</th><td>{{ playcost }}</td></tr>
</table>
{## }
<ul>
{% for entry in entries %}
<li>
@ -7,13 +166,8 @@
</ul>
{##}
<div class="card">
<header>{{ get("name").content }}</header>
</div>
{## }
<ul>
{% for (idx, component) in components.pairs %}
<li>
@ -23,3 +177,4 @@
{{ component.attrs }}
{% endfor %}
</ul>
{##}

View File

@ -1,5 +1,192 @@
.a {
.b {
color: red;
}
// @mixin flex {
// property: value;
// }
// TODO: convert to SASS
// https://sass-lang.com/guide
@mixin flex {
display: flex;
flex-flow: column nowrap;
justify-content: flex-start;
align-items: stretch;
//gap: 0.5mm;
}
.vbox { @include flex; flex-flow: column nowrap; }
.hbox { @include flex; flex-flow: row nowrap; }
.rjust { text-align: right; }
.grow { flex: 1 1 auto; }
.fjomp_card {
--color-border: MidnightBlue;
--color-bg-figure: white;
--color-bg: PaleTurquoise; // PaleTurquoise;
--color-bg-body: LightCyan; // PaleTurquoise;
--color-bg-frame: PaleTurquoise; // LightSkyBlue;
--color-bg-costbar: SandyBrown; // DarkOrange;
--color-text-title: MidnightBlue;
--color-text-body: black;
--color-text-costbar: white;
--color-shadow-costbar:
+0.08em 0 0.05em Maroon,
-0.08em 0 0.05em Maroon,
0 0.08em 0.05em Maroon,
0 -0.08em 0.05em Maroon;
--figure-color: #555;
--figure-size: 0.9in;
--figure-size: 1.35in;
--figure-size: 1.5in;
@include flex;
flex-flow: column nowrap;
width: 2.5in;
height: 3.5in;
box-sizing: border-box;
border-style: solid;
border-radius: 0mm;
border-width: 0.3mm;
border-color: var(--color-border);
background-color: var(--color-bg);
overflow: hidden;
font-size: 2.5mm;
font-family: sans-serif;
header {
font-family: montserrat, sans-serif;
font-style: normal;
font-weight: 200;
font-size: 1.8em;
line-height: 1em;
//margin-left: -1em;
border-radius: 1mm 1mm 0 0;
text-align: center;
background-color: var(--color-bg-frame);
color: var(--color-text-title);
}
.bar {
background-color: var(--color-bg-costbar);
color: var(--color-text-costbar);
text-shadow: var(--color-shadow-costbar);
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: center;
text-align: center;
font-size: 1.1em;
section {
margin-top: 1mm;
font-size: 0.8em;
margin-left: 0.8mm;
margin-right: 0.8mm;
line-height: 0.9em;
}
}
figure {
background-color: var(--color-bg-figure);
overflow: hidden;
position: relative;
min-height: var(--figure-size);
min-width: var(--figure-size);
margin: 0;
.layer {
color: var(--figure-color);
position: absolute;
top: 0; right: 0; left: 0; bottom: 0;
height: var(--figure-size);
width: var(--figure-size);
margin: auto;
text-align: center;
>* {
width: 100%;
height: 100%;
}
img {
width: calc(var(--figure-size));
height: calc(var(--figure-size));
object-fit: contain;
}
img.colored {
transform: translateY(-10000px);
filter: drop-shadow(0px 10000px var(--figure-color));
}
.mdi,
.fa,
.oi,
.material-icons.figure {
font-size: calc(var(--figure-size) * 0.9);
line-height: var(--figure-size);
}
.lnr {
font-size: calc(var(--figure-size) * 0.8);
line-height: calc(var(--figure-size) * 0.95);
}
}
}
.description {
flex: 1 1 auto; // grow shrink basis
margin: 1mm;
border-radius: 1mm;
background-color: var(--color-bg-body);
color: var(--color-text-body);
font-size: 0.9em;
//position: relative;
}
.range-grid {
width: 0.75in;
height: 0.75in;
box-sizing: border-box;
border-style: solid;
border-radius: 0.5mm;
border-width: 0.3mm;
border-color: var(--color-border);
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
grid-gap: .3mm;
padding: .3mm;
.label {
z-index: 100;
display: block;
grid-row-start: 1;
grid-row-end: 3;
grid-column-start: 1;
grid-column-end: 8;
text-align: center;
text-shadow:
+0.5mm 0 0.5mm white,
-0.5mm 0 0.5mm white,
0 0.5mm 0.5mm white,
0 -0.5mm 0.5mm white;
}
>* {
overflow: hidden;
}
margin-right: -0.3mm; // card border
}
.range-grid + .range-grid {
margin-top: -0.3mm; // border width
}
}