forked from cartoon-battle/cartoon-battle.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard-builder.html
148 lines (129 loc) · 4.47 KB
/
card-builder.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: Card builder
weight: 10
---
<form class="form-horizontal" name="builder">
<div class="row"><div class="col-md-6">
<div class="form-group">
<div class=row>
<label for="card_name" class="col-sm-3 control-label">Name:</label>
<div class="col-sm-9">
<input id="card_name" class="form-control" value="Rodeo Peter">
</div>
</div>
<div class=row>
<label for="image" class="col-sm-3 control-label">Image:</label>
<div class="col-sm-9">
<input class="form-control" id="image" list="image_list">
<datalist id="image_list">
{% for image in site.data.images.images %}
<option>{{ image }}
{% endfor %}
</datalist>
</div>
</div>
<div class=row>
<label for="rarity" class="col-sm-3 control-label">Rarity:</label>
<div class="col-sm-9">
<select id="rarity" class="form-control">
<option>common
<option>rare
<option>epic
<option selected>legendary
</select>
</div>
</div>
<div class=row>
<label for="level" class="col-sm-3 control-label">Level:</label>
<div class="col-sm-5">
<select id="fusion" class="form-control">
<option selected>not fused
<option>once fused
<option>twice fused
</select>
</div>
<div class="col-sm-4">
<select id="level" class="form-control">
<option>1
<option>2
<option>3
<option>4
<option>5
<option selected>6
</select>
</div>
</div>
<div class=row>
<label for="attack" class="col-sm-3 control-label">Stats:</label>
<div class="col-sm-5">
<input id=attack class="form-control" placeholder=attack>
</div>
<div class="col-sm-4">
<input class="form-control" id=health placeholder=health>
</div>
</div>
<div class=row>
<label for="trait" class="col-sm-3 control-label">Trait:</label>
<div class="col-sm-9">
<select id="trait" class="form-control">
<option value="">none
{% for name in site.data.values.traits %}
<option>{{ name }}</option>
{% endfor %}
</select>
</div>
</div>
{% for name in (1..3) %}
{% capture name %}{% cycle 'alpha', 'bravo', 'charlie' %}{% endcapture %}
<div class=row>
<label for="skill_{{ name }}" class="col-sm-3 control-label">Skill:</label>
<div class="col-sm-5">
<select id="skill_{{ name }}" class="form-control" name=skill>
<option value="">none
{% for skill in site.data.values.skills %}
<option value="{{ skill[0] }}">{{ skill[1] }}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-4">
<input type=number class="form-control" placeholder="value" patter="\d+">
</div>
</div>
{% endfor %}
</div> <!-- .form-group -->
<div class=row>
<button class="btn btn-primary pull-right">Build</button>
</div>
</div>
<div class="col-sm-6" id=result></div>
</div>
</div>
</form>
<script>require(['cartoon-battle/Card'], function (Card) {
var card = new Card;
document.getElementById('result').appendChild(card.node);
// FORM ///////////////////////////
var form = document.forms.builder;
var skills = [].slice.apply(form.querySelectorAll('[name="skill"]'));
///////////////////////////////////
form.onsubmit = function update() {
card.setName(form.card_name.value);
card.setRarity(form.rarity.value);
card.setLevel(form.level.value);
card.setFuse(form.fusion.selectedIndex);
card.setImage(form.image.value);
card.setTrait(form.trait.value);
card.setAttack(form.attack.value);
card.setHealth(form.health.value);
card.setSkills(skills.map(function (e) {
return {
type: e.value,
value: parseInt(e.parentNode.parentNode.querySelector('input').value) || null
};
}).filter(function (s) {
return s.type && s.value
}));
return false;
};
});
</script>