-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex (previous).js
99 lines (93 loc) · 3.11 KB
/
index (previous).js
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
const canvas = document.getElementById('game'),
ctx = canvas.getContext('2d'),
logo = new Image()
let lvl = 0,
nickname = undefined,
response = new Array,
scripts,
httpRequest = new XMLHttpRequest()
/*
httpRequest.onreadystatechange = (data) => {
scripts = JSON.parse(data.target.response).story[0]
}
httpRequest.open('GET', 'https://rawcdn.githack.com/EntryJSers/chammuh_assets/932802ca3b542079c40d6be718257dfb2cdeadc2/scripts/script.json')
httpRequest.send()
*/
httpRequest.onreadystatechange = (data) => {
scripts = JSON.parse(data.target.response)
}
httpRequest.open('GET', 'https://raw.githack.com/EntryJSers/chammuh/master/script.json')
httpRequest.send()
confirm = (title, id, placeholder, func) => {
Swal.fire({
title: title,
html:
`<input id="${id}" style="font-size: 1.2rem; border-radius: .3125em; padding: 1rem; border: 1px solid #eee" placeholder="${placeholder}">`,
focusConfirm: false,
confirmButtonText: '확인'
}).then((result) => {
if (result.value) {
func(id)
}
})
}
Swal.fire({
title: '이름이 뭐야?',
html:
`<input id="nameInput" style="font-size: 1.2rem; border-radius: .3125em; padding: 1rem; border: 1px solid #eee" placeholder="홍길동">`,
focusConfirm: false,
confirmButtonText: '확인'
}).then((result) => {
if (result.value) {
nickname = document.getElementById('nameInput').value
if (nickname == '') window.location.reload()
} else {
window.location.reload()
}
})
let cases = ''
const say = (scene) => {
for (let i = 0; i < scripts[scene].length; i++) {
console.log(i)
if (scripts[scene][i].type == 'conv') {
cases += `case ${Number(i) + 1}:\n printText(\`${scripts[scene][i].content[0]}\`)\n break\n`
}
if (scripts[scene][i].type == 'scene') {
say(scripts[scene][i].content)
}
/*
switch (scripts[scene][i].type) {
case 'conv':
cases += `case ${Number(i) + 1}:\n printText(\`${scripts[scene][i].content}\`)\n break\n`
break
case 'ques':
playQues(s.content, s.answer.contents, s.answer.scene)
break
case 'scene':
say(scripts[scene][i].content)
break
default:
console.error('에러다 에러 예상치 못한 타입이다')
break
}
*/
}
eval(`switch (lvl) {\n${cases}}`)
}
const printText = (text) => {
logo.src = `https://rawcdn.githack.com/EntryJSers/chammuh_assets/932802ca3b542079c40d6be718257dfb2cdeadc2/img/${lvl}.png`
ctx.clearRect(0, 430, canvas.width, canvas.height)
ctx.font = '24px Spoqa Han Sans'
ctx.fillStyle = 'white'
ctx.fillText(text, (canvas.width / 2) - (ctx.measureText(text).width / 2), 470)
}
window.addEventListener('load', () => {
printText('\n클릭해서 시작...')
})
logo.addEventListener('load', () => {
ctx.drawImage(logo, 0, 0, 960, 420)
}, false)
canvas.addEventListener('click', () => {
lvl += 1
say('main')
})