forked from scipio241/FGO
-
Notifications
You must be signed in to change notification settings - Fork 5
/
fgo.html
344 lines (329 loc) · 12.3 KB
/
fgo.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<title>Fate Grand Order Card Generator</title>
<style type = "text/css">
body{
background: linear-gradient(-45deg, #F2F2F2 25%, #F5F5F5 0, #F5F5F5 50%, #F2F2F2 0, #F2F2F2 75%, #F5F5F5 0);
background-size: 100px 100px;
}
#main-container
{
background: linear-gradient(45deg, #F2F2F2 25%, #F5F5F5 0, #F5F5F5 50%, #F2F2F2 0, #F2F2F2 75%, #F5F5F5 0);
background-size: 100px 100px;
border: 1px solid #E0E0E0;
position: relative;
padding-top: 40px;
padding-bottom: 10px;
width: 100%;
max-width: 500px;
text-align: center;
margin: 0 auto;
}
#Canvas-container
{
position: relative;
max-width: 500px;
width: 100%;
margin: 0 auto;
}
@font-face {
font-family: FGO;
src: url('Font/honoka.ttf') format("truetype");
}
.toggle {
position: absolute;
visibility: hidden;
}
.toggle + label {
max-width: 250px;
width: 100%;
height: 39px;
margin: 0 auto;
display: block;
position: relative;
cursor: pointer;
outline: none;
user-select: none;
margin-bottom: 20px;
}
.toggle + label:before, .toggle + label:after {
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
color: #fff;
text-align: center;
line-height: 39px;
}
.toggle + label:after {
background-color: #1abc9c;
content: attr(data-on);
transition: transform 0.5s;
transform: rotateY(180deg);
backface-visibility: hidden;
}
.toggle + label:before {
background-color: #dddddd;
content: attr(data-off);
transition: transform 0.5s;
backface-visibility: hidden;
color: black;
}
#gold + label { border: 1px solid #cacaca; }
#gold + label:after { background: white; color: black; }
#gold + label:before { background: #ffeb04; }
.toggle:checked + label:before {
transform: rotateY(180deg);
}
.toggle:checked + label:after {
transform: rotateY(0deg);
}
.toggle_show:checked + label + div, .toggle_show + label + div + div {
display: none;
}
.toggle_show:checked + label + div + div, .toggle_show + label + div {
display: block;
}
</style>
<script type = "text/javascript">
function preLoadImg(url)
{
const img = new Image();
img.src = url;
}
function imgPreview(fileDom)
{
let reader;
if (window.FileReader) {
reader = new FileReader();
} else {
alert("Your device doesn't support uploading images.");
}
const file = fileDom.files[0];
const imageType = /^image\//g;
if (!imageType.test(file.type))
{
alert("Please upload a picture!");
return;
}
reader.onload = function(e)
{
const img = document.getElementById("preview");
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
function put_text(canvas, content, Hero_class, Hero_name, CE) {
let ATK = document.getElementById("ATK").value || 0;
let HP = document.getElementById("HP").value || 0;
let y = [727, 732, 753, 830];
if (CE) {
ATK = "+" + ATK;
HP = "+" + HP;
}
content.textAlign = "center";
content.font = "50px FGO";
content.lineWidth = 4;
content.strokeStyle = "black";
content.strokeText(Hero_class,250,y[0]);
content.fillStyle = "white";
content.fillText(Hero_class,250,y[0]);
content.font = "22px FGO";
content.strokeStyle = "black";
content.lineWidth = 3;
content.strokeText(Hero_name,250,y[2]);
content.fillStyle = "white";
content.fillText(Hero_name,250,y[2]);
content.font = "50px FGO";
content.strokeStyle = "black";
content.strokeText(ATK,130,y[3]);
let my_gradient = content.createLinearGradient(0,y[3] - 50 ,0,y[3]);
if (!CE && !document.getElementById('gold').checked) {
my_gradient.addColorStop(0.5,"#ffeb04");
my_gradient.addColorStop(0.6,"#b1a300");
my_gradient.addColorStop(1,"#ffeb04");
} else {
my_gradient.addColorStop(0.5,"white");
my_gradient.addColorStop(0.6,"#8f8f8f");
my_gradient.addColorStop(1,"white");
}
content.fillStyle = my_gradient;
content.fillText(ATK,130,y[3]);
content.strokeStyle = "black";
content.strokeText(HP,370,y[3]);
content.fillStyle = my_gradient;
content.fillText(HP,370,y[3]);
dataURL = canvas.toDataURL();
document.getElementById('pic_show').src = dataURL;
}
function get_pic(id)
{
const canvas = document.getElementById(id);
const content = canvas.getContext("2d");
content.clearRect(0, 0, canvas.width, canvas.height);
const img_logo = new Image();
const img_frame = new Image();
let img_hero = new Image();
img_logo.crossOrigin = '';
img_hero.crossOrigin = '';
const Hero_rarity = document.getElementById("Hero_rarity").value || 5;
img_hero = document.getElementById("preview");
if(!img_hero.src)
{
alert("Please upload a picture!"); return;
}
preLoadImg(img_hero.src);
if (document.getElementById("toggle").checked) {
let Hero_class = document.getElementById("Hero_class").value || "all";
const Hero_name = document.getElementById("Hero_name").value || "Unknown";
if (Hero_rarity == 0) {
img_logo.src = "img/fgo/" + Hero_class + "0.png";
} else if (Hero_rarity == 1 || Hero_rarity == 2) {
img_logo.src = "img/fgo/" + Hero_class + "1.png";
} else if (Hero_rarity == 3) {
img_logo.src = "img/fgo/" + Hero_class + "2.png";
} else {
img_logo.src = "img/fgo/" + Hero_class + "3.png";
}
img_frame.src = "img/fgo/S" + Hero_rarity + ".png";
preLoadImg(img_frame.src);
img_frame.onload = function()
{
content.drawImage(img_hero,0,0,500,730);
content.drawImage(img_frame,0,0,500,850);
const icon_pos = {
"saber": [ 213, 753 ],
"archer": [ 211, 753 ],
"lancer": [ 213, 753 ],
"caster": [ 215, 753 ],
"assassin": [ 213, 751 ],
"rider": [ 215, 754 ],
"berserker": [ 213, 751 ],
"ruler": [ 213, 753 ],
"shielder": [ 213, 750 ],
"avenger": [ 213, 752 ],
"mooncancer": [ 213, 752 ],
"alterego": [ 213, 752 ],
"beast": [ 213, 752 ],
"all": [ 213, 752 ],
"none": [ 213, 752 ],
}
preLoadImg(img_logo.src);
img_logo.onload = function () {
content.drawImage(img_logo,...icon_pos[Hero_class],76,76);
Hero_class = Hero_class.slice(0, 1).toUpperCase() + Hero_class.slice(1);
Hero_class = document.getElementById("Hero_subname").value || Hero_class;
put_text(canvas, content, Hero_class, Hero_name, false);
};
}
} else {
const Hero_class = document.getElementById("CE_subname").value || "Unknown";
const Hero_name = document.getElementById("CE_name").value || "Unknown";
img_frame.src = "img/fgo/CE" + Hero_rarity + ".png";
preLoadImg(img_frame.src);
img_frame.onload = function()
{
content.drawImage(img_hero,0,0,500,850);
content.drawImage(img_frame,0,0,500,850);
put_text(canvas, content, Hero_name, Hero_class, true);
}
}
resize();
}
function resize(){
width = document.body.clientWidth;
if(width <= 512)
{
document.getElementById("pic_show").style.width = "100%";
}
else{
document.getElementById("pic_show").style.width = "512px";
}
}
</script>
</head>
<body onresize = "resize()">
<div id = "main-container" >
<div style = "font-size: 35px; text-align: center; color: green">FGO Card Generator</div>
<div style = "text-align: center; font-size: 15px; padding-bottom: 20px">Original Code by juncaixinchi<br>Expanded by Aister<br>Even further by Azuto</div>
Rarity<br><br>
<select id = "Hero_rarity" style = "max-width:250px; width: 100%">
<option value = "0">0 ☆ (Servant only)</option>
<option value = "1">1 ☆</option>
<option value = "2">2 ☆</option>
<option value = "3">3 ☆</option>
<option value = "4">4 ☆</option>
<option value = "5">5 ☆</option>
<option value = "B">5B☆ (Servant only)</option>
</select><br><br>
<div style = "text-align: left; display:inline-block; width:50px">ATK:</div><input type = "number" id = "ATK">
<br>
<br>
<div style = "text-align: left; display:inline-block; width:50px">HP:</div><input type = "number" id = "HP">
<br>
<br>
<div id="switch">
Card Type<br><br>
<input id="toggle" class="toggle toggle_show" checked="checked" type="checkbox" value="1">
<label for="toggle" data-on="Servant (Click to switch)" data-off="Craft Essences (Click to switch)"></label>
<div>
Name<br><br>
<input type = "text" id = "CE_name" placeholder = "Name" style = "max-width:250px; width: 100%"><br><br>
Sub Name<br><br>
<input type = "text" id = "CE_subname" placeholder = "Class Name" style = "max-width:250px; width: 100%"><br><br>
</div>
<div>
Number Color<br><br>
<input id="gold" class="toggle" checked="checked" type="checkbox" value="1">
<label for="gold" data-on="White (Click to switch)" data-off="Gold (Click to switch)"></label>
Name<br><br>
<input type = "text" id = "Hero_name" placeholder = "Name" style = "max-width:250px; width: 100%"><br><br>
Class Name<br><br>
<input type = "text" id = "Hero_subname" placeholder = "Sub Name" style = "max-width:250px; width: 100%"><br><br>
Class Icon<br><br>
<select id = "Hero_class" style = "max-width:250px; width: 100%">
<option value = "saber">Saber</option>
<option value = "lancer">Lancer</option>
<option value = "archer">Archer</option>
<option value = "rider">Rider</option>
<option value = "caster">Caster</option>
<option value = "assassin">Assassin</option>
<option value = "berserker">Berserker</option>
<option value = "ruler">Ruler</option>
<option value = "shielder">Shielder</option>
<option value = "avenger">Avenger</option>
<option value = "mooncancer">Moon Cancer</option>
<option value = "alterego">Alter Ego</option>
<option value = "beast">Beast</option>
<option value = "all">All</option>
<option value = "none">None</option>
</select><br><br>
</div>
</div>
Please upload the photo<br><br>
<input type = "file" name = "file" onchange = "imgPreview(this)" value = "上传图片">
<br>
<br>
<a href = "#Canvas-position"><button onclick = "get_pic('myCanvas')">Generate!</button></a>
<br>
<p style = "font-size: 10pt">Tips: For best result, please use image size of 730 x 500!</p>
<!--两个例子:
<a href = "#Canvas-position"><button onclick = "get_zhou()">生成周天王!</button></a>
<a href = "#Canvas-position"><button onclick = "get_lei()">生成蕾姆!</button></a> -->
<img id = "preview" hidden = "hidden">
</div>
<div id = "Canvas-container">
<a name = "Canvas-position">
<canvas id = "myCanvas" width = "500" height = "850" style = "border:1px solid #c3c3c3" hidden = "hidden">
Your browser doesn't support Canvas, please use a more modern browser!
</canvas>
<img id = "pic_show">
</a>
</div>
</body>
</html>