Skip to content

Commit 0c1fa48

Browse files
authored
Merge pull request #211 from EndoHizumi/copilot/implement-missing-functionality
Implement auto mode, skip mode toggle, and expose Store as public API
2 parents 283c532 + 6e97bf5 commit 0c1fa48

3 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/core/defaultUIHandler.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export class DefaultUIHandler {
6464
const styleTags = Array.from(document.head.getElementsByTagName('style'))
6565
styleTags.forEach((tag) => document.head.removeChild(tag))
6666

67+
gameContainer.tabIndex = 0
68+
gameContainer.style.outline = 'none'
6769
// HTMLコンテンツを注入する
6870
gameContainer.innerHTML = mainDiv.innerHTML
6971

@@ -76,6 +78,8 @@ export class DefaultUIHandler {
7678
styleEl.textContent = styleContent
7779
document.head.appendChild(styleEl)
7880
}
81+
82+
gameContainer.focus()
7983
} else {
8084
// 古いダイアログ用スタイルシートを削除する
8185
document.head
@@ -221,14 +225,16 @@ export class DefaultUIHandler {
221225
if (inputAbortController) inputAbortController.abort()
222226
inputAbortController = new AbortController()
223227
const { signal } = inputAbortController
224-
const { onNext, setSkip } = data
228+
const { onNext, setSkip, toggleAuto, toggleSkip } = data
225229
gameContainer.addEventListener(
226230
'keydown',
227231
(e: KeyboardEvent) => {
228232
if (e.key === 'Enter') {
229233
onNext()
230234
} else if (e.key === 'Control') {
231-
setSkip(true, true)
235+
toggleSkip()
236+
} else if (e.key.toLowerCase() === 'a' && toggleAuto) {
237+
toggleAuto()
232238
}
233239
},
234240
{ signal },
@@ -237,12 +243,19 @@ export class DefaultUIHandler {
237243
'keyup',
238244
(e: KeyboardEvent) => {
239245
if (e.key === 'Control') {
240-
setSkip(true, false)
246+
toggleSkip()
241247
}
242248
},
243249
{ signal },
244250
)
245-
gameContainer.addEventListener('click', () => onNext(), { signal })
251+
gameContainer.addEventListener(
252+
'click',
253+
() => {
254+
gameContainer.focus()
255+
onNext()
256+
},
257+
{ signal },
258+
)
246259
})
247260
}
248261
}

src/core/index.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export class Core {
8080
this.drawer.isSkip = drawerSkip
8181
this.isNext = coreNext
8282
},
83+
toggleAuto: () => { this.isAuto = !this.isAuto },
84+
toggleSkip: () => { this.isSkip = !this.isSkip },
8385
})
8486

8587
await this.textHandler('タップでスタート')
@@ -225,7 +227,7 @@ export class Core {
225227
await this.eventBus.emit('text:show', {
226228
name: scenarioObject.name || '',
227229
content: scenarioObject.content,
228-
speed: scenarioObject.speed || 25,
230+
speed: this.isSkip ? 1 : scenarioObject.speed || 25,
229231
expandVariable: this.expandVariable.bind(this),
230232
waitFn: this.waitHandler.bind(this),
231233
})
@@ -254,15 +256,26 @@ export class Core {
254256
if (typeof line.wait === 'string' && !isNaN(Number(line.wait))) {
255257
line.wait = Number(line.wait)
256258
}
259+
260+
// スキップモードが有効な場合は全ての待機をスキップする
261+
if (this.isSkip) {
262+
return
263+
}
264+
257265
if (typeof line.wait === 'number') {
258266
if (line.wait > 0 || this.isAuto) {
259267
const waitTime = line.wait || 1500
260268
// 指定された時間だけ待機
261269
await sleep(waitTime)
262270
}
263271
} else {
264-
// 改行ごとに入力待ち
265-
await this.clickWait()
272+
if (this.isAuto) {
273+
// オートモードが有効な場合はデフォルト時間後に自動進行する
274+
await sleep(1500)
275+
} else {
276+
// 改行ごとに入力待ち
277+
await this.clickWait()
278+
}
266279
}
267280
}
268281

@@ -271,7 +284,7 @@ export class Core {
271284
this.drawer.setVisibility('#waitCircle', true)
272285
return new Promise((resolve) => {
273286
const intervalId = setInterval(() => {
274-
if (this.isNext) {
287+
if (this.isNext || this.isAuto || this.isSkip) {
275288
this.drawer.setVisibility('#waitCircle', false)
276289
clearInterval(intervalId)
277290
this.isNext = false
@@ -750,6 +763,15 @@ export class Core {
750763
getSaveList: () => this.getSaveList(),
751764
deleteSave: (slot) => this.deleteSave(slot),
752765
},
766+
store: this.store,
767+
playback: {
768+
toggleAuto: () => { this.isAuto = !this.isAuto },
769+
setAuto: (value) => { this.isAuto = value },
770+
getAuto: () => this.isAuto,
771+
toggleSkip: () => { this.isSkip = !this.isSkip },
772+
setSkip: (value) => { this.isSkip = value },
773+
getSkip: () => this.isSkip,
774+
},
753775
sandbox: {
754776
execute: this.executeScenario.bind(this),
755777
},
@@ -803,7 +825,7 @@ export class Core {
803825
async loadHandler(line) {
804826
const slot = line.slot || 'auto'
805827

806-
const saveDataRaw = this.store.get ? this.store.get(`save_${slot}`) : this.store[`save_${slot}`]
828+
const saveDataRaw = this.store.get(`save_${slot}`)
807829
if (!saveDataRaw) {
808830
throw new Error(`セーブデータが見つかりません: スロット${slot}`)
809831
}
@@ -882,6 +904,6 @@ export class Core {
882904
}
883905

884906
deleteSave(slot) {
885-
delete this.store[`save_${slot}`]
907+
this.store.remove(`save_${slot}`)
886908
}
887909
}

src/utils/store.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ interface StoreData {
66

77
export interface Store extends StoreData {
88
set(key: string, value: any): void;
9+
get(key: string): any;
10+
remove(key: string): void;
911
}
1012

1113
export const generateStore = (): Store => {
@@ -16,7 +18,14 @@ export const generateStore = (): Store => {
1618
set(key: string, value: any): void {
1719
storejs.set(key, value);
1820
this[key] = value;
19-
}
21+
},
22+
get(key: string): any {
23+
return storejs.get(key);
24+
},
25+
remove(key: string): void {
26+
storejs.remove(key);
27+
delete (this as StoreData)[key];
28+
},
2029
};
2130

2231
return store;

0 commit comments

Comments
 (0)