crobi 10 лет назад
Родитель
Сommit
06567b43cf

+ 26
- 0
generator/components-test.html Просмотреть файл

@@ -39,15 +39,41 @@
39 39
         <card-contents>
40 40
             <card-subtitle>Medium beast</card-subtitle>
41 41
             <card-rule></card-rule>
42
+            <card-dndstats mode="both" str="13" dex="10" con="15" int="-" wis="-" cha="-"></card-dndstats>
43
+            <card-rule></card-rule>
42 44
             <card-property><h4>Armor class</h4><p>12 (natural armor)</p></card-property>
43 45
             <card-property><h4>Hit points</h4><p>7 (2d6)</p></card-property>
44 46
             <card-rule></card-rule>
47
+            <card-description><h4>Multiattack</h4><p>One bite and one claw.</p></card-description>
45 48
             <card-fill size="2"></card-fill>
49
+            <card-section>Actions</card-section>
50
+            <card-description><h4>Bite</h4><p>+4 to hit, 2d6+2 piercing damage.</p></card-description>
51
+            <card-description><h4>Claw</h4><p>+4 to hit, 1d8+2 piercing damage.</p></card-description>
46 52
         </card-contents>
47 53
         <card-title>
48 54
             <h1>Druid thingy</h1>
49 55
             <card-icon src="/icons/lorc/originals/svg/stag-head.svg"></card-icon>
50 56
         </card-title>
51 57
     </card-front>
58
+    &nbsp;
59
+    <card-front class="card-size-25x35" color="indigo">
60
+        <card-title size="12">
61
+            <h1>Wand of Magic Missile</h1>
62
+            <card-icon src="/icons/lorc/originals/svg/crystal-wand.svg"></card-icon>
63
+        </card-title>
64
+        <card-contents>
65
+            <card-subtitle>Wondrous item</card-subtitle>
66
+            <card-rule></card-rule>
67
+            <card-property><h4>Maximum charges</h4><p>7</p></card-property>
68
+            <card-property><h4>Recharge</h4><p>1d6+1</p></card-property>
69
+            <card-rule></card-rule>
70
+            <card-description><h4>Spells</h4><p>You can use your action to cast the following spells:</p></card-description>
71
+            <card-bullet>Magic missile</card-bullet>
72
+            <card-bullet>Magic missile</card-bullet>
73
+            <card-bullet>Magic missile</card-bullet>
74
+            <card-fill size="2"></card-fill>
75
+            <card-boxes size="2" count="7"></card-boxes>
76
+        </card-contents>
77
+    </card-front>
52 78
 </body>
53 79
 </html>

+ 151
- 0
generator/components/card-dndstats.html Просмотреть файл

@@ -0,0 +1,151 @@
1
+<template id="card-dndstats">
2
+    <style>
3
+        :host {
4
+            width: 100%;
5
+        }
6
+        table {
7
+            width: 100%;
8
+            border-spacing: 0;
9
+        }
10
+
11
+        th {
12
+            text-align: center;
13
+            padding: 0;
14
+            /*width: 16.666%;*/
15
+        }
16
+
17
+        th.hidden, td.hidden {
18
+            display: none;
19
+        }
20
+
21
+        td {
22
+            text-align: center;
23
+            padding: 0;
24
+        }
25
+    </style>
26
+
27
+    <table>
28
+        <tbody>
29
+            <tr id="headers">
30
+            </tr>
31
+            <tr id="values">
32
+            </tr>
33
+        </tbody>
34
+    </table>
35
+
36
+</template>
37
+
38
+<script>
39
+    (function(window, document) {
40
+        var elemName = 'card-dndstats';
41
+        var mainDoc = document;
42
+        var importDoc = document.currentScript.ownerDocument;
43
+
44
+        // Definition of stats
45
+        statNames = ["str", "dex", "con", "int", "wis", "cha"];
46
+        function getStatMod (value) {
47
+            var modValue = Math.floor((value - 10) / 2);
48
+            if (modValue >= 0)  {
49
+                return "+" + modValue;
50
+            } else {
51
+                return "" + modValue;
52
+            }
53
+        }
54
+        function getStatString (value, mode) {
55
+            switch (mode) {
56
+                case "both": return "" + value + "&nbsp;(" + getStatMod(value) + ")";
57
+                case "mod": return getStatMod(value);
58
+                case "stat": return "" + value;
59
+                default: return "" + value;
60
+            }
61
+        }
62
+
63
+        function updateStats (element) {
64
+            for (var i = 0; i < statNames.length; ++i) {
65
+                updateStat(element, statNames[i]);
66
+            }
67
+        }
68
+        function updateStat(element, name) {
69
+            var value = element.stats[name];
70
+            var root = element.shadowRoot;
71
+            var td = root.getElementById(name + "-value");
72
+            var th = root.getElementById(name + "-header");
73
+
74
+            if (value === null) {
75
+                td.className = "hidden";
76
+                th.className = "hidden";
77
+            } else {
78
+                td.className = "";
79
+                th.className = "";
80
+                if (value !== "" && value >= 0) {
81
+                    td.innerHTML = getStatString(value, element.mode);
82
+                } else {
83
+                    td.innerHTML = value;
84
+                }
85
+            }
86
+        }
87
+
88
+        var proto = Object.create(HTMLTableElement.prototype);
89
+        Object.defineProperty(proto, "stats", {
90
+            value: {str:0, dex:0, con:0, int:0, wis:0, cha:0},
91
+            writable: true,
92
+            configurable: false,
93
+            enumerable: false
94
+        });
95
+        Object.defineProperty(proto, "mode", {
96
+            value: "both",
97
+            writable: true,
98
+            configurable: false,
99
+            enumerable: false
100
+        });
101
+
102
+        proto.createdCallback = function () {
103
+            var template = importDoc.getElementById(elemName);
104
+            var clone = mainDoc.importNode(template.content, true);
105
+            var root = this.createShadowRoot();
106
+            root.appendChild(clone);
107
+
108
+            // Create all stat columns
109
+            var tr1 = root.getElementById("headers");
110
+            var tr2 = root.getElementById("values");
111
+            for (var i = 0; i < statNames.length; ++i) {
112
+                var stat = statNames[i];
113
+
114
+                var header = document.createElement("th");
115
+                header.innerHTML = stat.toUpperCase();
116
+                header.id = stat + "-header";
117
+                tr1.appendChild(header);
118
+
119
+                var value = document.createElement("td");
120
+                value.innerHTML = stat.toUpperCase();
121
+                value.id = stat + "-value";
122
+                tr2.appendChild(value);
123
+            }
124
+
125
+            // Update the initial content of the stats
126
+            this.mode = this.getAttribute("mode") || "both";
127
+            for (var i = 0; i < statNames.length; ++i) {
128
+                var stat = statNames[i];
129
+                this.stats[stat] = this.getAttribute(stat);
130
+            }
131
+            updateStats(this);
132
+        }
133
+        proto.attributeChangedCallback = function (name, oldValue, newValue) {
134
+            if (name == "mode") {
135
+                this.mode = newValue;
136
+                updateStats(this);
137
+            }
138
+            for (var i = 0; i < statNames.length; ++i) {
139
+                var stat = statNames[i];
140
+                if (stat == name) {
141
+                    this.stats[stat] = newValue;
142
+                    updateStat(this, stat);
143
+                    break;
144
+                }
145
+            }
146
+        }
147
+
148
+        mainDoc.registerElement(elemName, { prototype: proto });
149
+
150
+    })(window, document);
151
+</script>

+ 4
- 4
generator/components/card-front.html Просмотреть файл

@@ -20,13 +20,13 @@
20 20
         }
21 21
 
22 22
         ::content > card-title:first-child {
23
-            margin-top: -3px;
24
-            margin-bottom: 3px;
23
+            margin-top: -2px;
24
+            margin-bottom: 4px;
25 25
         }
26 26
 
27 27
         ::content > card-title:last-child {
28
-            margin-top: 3px;
29
-            margin-bottom: -3px;
28
+            margin-top: 4px;
29
+            margin-bottom: -2px;
30 30
         }
31 31
     </style>
32 32
 

+ 23
- 2
generator/components/card-title.html Просмотреть файл

@@ -16,7 +16,6 @@
16 16
 
17 17
         ::content > h1 {
18 18
             flex: 1;
19
-            font-size: 13pt;
20 19
             font-family: inherit;
21 20
             display: block;
22 21
             margin: 0;
@@ -28,14 +27,19 @@
28 27
             font-family: inherit;
29 28
             display: block;
30 29
             margin: 0;
30
+            margin-right: 2px;
31 31
         }
32 32
 
33 33
         ::content > card-icon {
34
-            height: 100%;
34
+            height: 28px;
35 35
         }
36 36
 
37 37
     </style>
38 38
 
39
+    <style id="font-size">
40
+        ::content > h1 {font-size: 13pt;}
41
+    </style>
42
+
39 43
     <content></content>
40 44
 
41 45
 </template>
@@ -47,11 +51,28 @@
47 51
         var importDoc = document.currentScript.ownerDocument;
48 52
 
49 53
         var proto = Object.create(HTMLElement.prototype);
54
+        Object.defineProperty(proto, "size", {
55
+            get: function () {
56
+                return "";
57
+            },
58
+            set: function (value) {
59
+                var root = this.shadowRoot;
60
+                var style = root.getElementById("font-size");
61
+                style.innerHTML = "::content > h1 {font-size: " + value + "pt;}";
62
+            }
63
+        });
50 64
         proto.createdCallback = function () {
51 65
             var template = importDoc.getElementById(elemName);
52 66
             var clone = mainDoc.importNode(template.content, true);
53 67
             var root = this.createShadowRoot();
54 68
             root.appendChild(clone);
69
+
70
+            this.size = this.getAttribute('size') || "13";
71
+        }
72
+        proto.attributeChangedCallback = function (name, oldValue, newValue) {
73
+            switch (name) {
74
+                case "size": this.size = newValue;
75
+            }
55 76
         }
56 77
 
57 78
         mainDoc.registerElement(elemName, { prototype: proto });

+ 1
- 0
generator/components/card.html Просмотреть файл

@@ -12,6 +12,7 @@
12 12
     <link rel="import" href="./card-description.html">
13 13
     <link rel="import" href="./card-fill.html">
14 14
     <link rel="import" href="./card-section.html">
15
+    <link rel="import" href="./card-dndstats.html">
15 16
 </head>
16 17
 <body>
17 18
 

Загрузка…
Отмена
Сохранить