mirror of
https://github.com/He4eT/cheap-glkote.git
synced 2026-05-05 08:57:25 +00:00
Dirty initial commit
This commit is contained in:
commit
eab87d32a9
13 changed files with 7039 additions and 0 deletions
106
src/cheapGlkOte.js
Normal file
106
src/cheapGlkOte.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
const GlkOte = require('./glkOte/glkote-term')
|
||||
|
||||
class CheapGlkOte extends GlkOte {
|
||||
constructor(handlers) {
|
||||
super()
|
||||
|
||||
this.window = null
|
||||
this.current_input_type = null
|
||||
|
||||
this.handlers = handlers
|
||||
}
|
||||
|
||||
sendFn(message) {
|
||||
this.send_response(
|
||||
this.current_input_type,
|
||||
this.window,
|
||||
message)
|
||||
this.current_input_type = null
|
||||
}
|
||||
|
||||
init(iface) {
|
||||
/* Only one window can be opened */
|
||||
const glk_window_open = iface.Glk.glk_window_open
|
||||
iface.Glk.glk_window_open = (splitwin, ...args) =>
|
||||
splitwin
|
||||
? null
|
||||
: glk_window_open(splitwin, ...args)
|
||||
|
||||
this.handlers.onInit()
|
||||
super.init(iface)
|
||||
}
|
||||
|
||||
update_inputs(data) {
|
||||
if (!data.length) return null
|
||||
|
||||
const {type} = data[0]
|
||||
if (['char', 'line'].includes(type)) {
|
||||
this.current_input_type = type
|
||||
this.handlers.onUpdateInputs(type)
|
||||
}
|
||||
}
|
||||
|
||||
accept_specialinput(data) {
|
||||
if (data.type === 'fileref_prompt') {
|
||||
const callback = ref =>
|
||||
this.send_response(
|
||||
'specialresponse', null, 'fileref_prompt', ref)
|
||||
|
||||
this.interface.Dialog.open(
|
||||
data.filemode !== 'read',
|
||||
data.filetype,
|
||||
data.gameid,
|
||||
callback)
|
||||
} else {
|
||||
this.error(
|
||||
'Request for unknown special input type: ' + data.type)
|
||||
}
|
||||
}
|
||||
|
||||
update_content(messages) {
|
||||
const filtered =
|
||||
messages.filter(content =>
|
||||
content.id === this.window.id)[0]
|
||||
|
||||
this.handlers.onUpdateContent(filtered)
|
||||
}
|
||||
|
||||
exit() {
|
||||
this.handlers.onExit()
|
||||
super.exit()
|
||||
}
|
||||
|
||||
cancel_inputs(data) {
|
||||
if (data.length === 0) {
|
||||
this.current_input_type = null
|
||||
this.handlers.onUpdateInputs(null)
|
||||
}
|
||||
}
|
||||
|
||||
disable(disable) {
|
||||
this.disabled = disable
|
||||
this.handlers.onDisable(disable)
|
||||
}
|
||||
|
||||
update_windows(data) {
|
||||
data.forEach(win => {
|
||||
if (win.type === 'buffer') {
|
||||
this.window = win
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
log(msg) {
|
||||
console.log(`[log]: ${msg}`)
|
||||
}
|
||||
|
||||
warning(msg) {
|
||||
console.warn(`[warning]: ${msg}`)
|
||||
}
|
||||
|
||||
error(message) {
|
||||
console.error(`[error]: ${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CheapGlkOte
|
||||
Loading…
Add table
Add a link
Reference in a new issue