Fix: AiScriptのreadlineの修正をPlay以外にも適用 (#12841)

* add AiScriptReadline() in api.ts

* apply AiScriptReadline on flash.vue

* AiScriptReadline → aiScriptReadline

* Update flash.vue

* Update scratchpad.vue

* Update WidgetAiscript.vue

* Update WidgetAiscriptApp.vue

* Update WidgetButton.vue

* Update plugin.ts
This commit is contained in:
FineArchs 2024-01-04 12:26:57 +09:00 committed by GitHub
parent da154c8209
commit f8d5a46dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 80 deletions

View File

@ -67,7 +67,7 @@ import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js'; import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkAsUi from '@/components/MkAsUi.vue'; import MkAsUi from '@/components/MkAsUi.vue';
import { AsUiComponent, AsUiRoot, registerAsUiLib } from '@/scripts/aiscript/ui.js'; import { AsUiComponent, AsUiRoot, registerAsUiLib } from '@/scripts/aiscript/ui.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import MkFolder from '@/components/MkFolder.vue'; import MkFolder from '@/components/MkFolder.vue';
import MkCode from '@/components/MkCode.vue'; import MkCode from '@/components/MkCode.vue';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
@ -162,15 +162,7 @@ async function run() {
THIS_ID: values.STR(flash.value.id), THIS_ID: values.STR(flash.value.id),
THIS_URL: values.STR(`${url}/play/${flash.value.id}`), THIS_URL: values.STR(`${url}/play/${flash.value.id}`),
}, { }, {
in: (q) => { in: aiScriptReadline,
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ result: a }) => {
ok(a ?? '');
});
});
},
out: (value) => { out: (value) => {
// nop // nop
}, },

View File

@ -44,7 +44,7 @@ import { Interpreter, Parser, utils } from '@syuilo/aiscript';
import MkContainer from '@/components/MkContainer.vue'; import MkContainer from '@/components/MkContainer.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import MkCodeEditor from '@/components/MkCodeEditor.vue'; import MkCodeEditor from '@/components/MkCodeEditor.vue';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
@ -86,19 +86,7 @@ async function run() {
root.value = _root.value; root.value = _root.value;
}), }),
}), { }), {
in: (q) => { in: aiScriptReadline,
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
out: (value) => { out: (value) => {
if (value.type === 'str' && value.value.toLowerCase().replace(',', '').includes('hello world')) { if (value.type === 'str' && value.value.toLowerCase().replace(',', '').includes('hello world')) {
claimAchievement('outputHelloWorldOnScratchpad'); claimAchievement('outputHelloWorldOnScratchpad');

View File

@ -4,7 +4,7 @@
*/ */
import { Interpreter, Parser, utils, values } from '@syuilo/aiscript'; import { Interpreter, Parser, utils, values } from '@syuilo/aiscript';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { inputText } from '@/os.js'; import { inputText } from '@/os.js';
import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions, pageViewInterruptors } from '@/store.js'; import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions, pageViewInterruptors } from '@/store.js';
@ -19,19 +19,7 @@ export async function install(plugin: Plugin): Promise<void> {
plugin: plugin, plugin: plugin,
storageKey: 'plugins:' + plugin.id, storageKey: 'plugins:' + plugin.id,
}), { }), {
in: (q): Promise<string> => { in: aiScriptReadline,
return new Promise(ok => {
inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
out: (value): void => { out: (value): void => {
console.log(value); console.log(value);
}, },

View File

@ -11,6 +11,16 @@ import { customEmojis } from '@/custom-emojis.js';
import { url, lang } from '@/config.js'; import { url, lang } from '@/config.js';
import { nyaize } from '@/scripts/nyaize.js'; import { nyaize } from '@/scripts/nyaize.js';
export function aiScriptReadline(q: string): Promise<string> {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ result: a }) => {
ok(a ?? '');
});
});
}
export function createAiScriptEnv(opts) { export function createAiScriptEnv(opts) {
return { return {
USER_ID: $i ? values.STR($i.id) : values.NULL, USER_ID: $i ? values.STR($i.id) : values.NULL,

View File

@ -25,7 +25,7 @@ import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, Wid
import { GetFormResultType } from '@/scripts/form.js'; import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import MkContainer from '@/components/MkContainer.vue'; import MkContainer from '@/components/MkContainer.vue';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
@ -69,19 +69,7 @@ const run = async () => {
storageKey: 'widget', storageKey: 'widget',
token: $i?.token, token: $i?.token,
}), { }), {
in: (q) => { in: aiScriptReadline,
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
out: (value) => { out: (value) => {
logs.value.push({ logs.value.push({
id: Math.random().toString(), id: Math.random().toString(),

View File

@ -18,7 +18,7 @@ import { Interpreter, Parser } from '@syuilo/aiscript';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import { GetFormResultType } from '@/scripts/form.js'; import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import MkAsUi from '@/components/MkAsUi.vue'; import MkAsUi from '@/components/MkAsUi.vue';
import MkContainer from '@/components/MkContainer.vue'; import MkContainer from '@/components/MkContainer.vue';
@ -64,19 +64,7 @@ async function run() {
root.value = _root.value; root.value = _root.value;
}), }),
}, { }, {
in: (q) => { in: aiScriptReadline,
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
out: (value) => { out: (value) => {
// nop // nop
}, },

View File

@ -16,7 +16,7 @@ import { Interpreter, Parser } from '@syuilo/aiscript';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js'; import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import { GetFormResultType } from '@/scripts/form.js'; import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js'; import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
@ -56,19 +56,7 @@ const run = async () => {
storageKey: 'widget', storageKey: 'widget',
token: $i?.token, token: $i?.token,
}), { }), {
in: (q) => { in: aiScriptReadline,
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
out: (value) => { out: (value) => {
// nop // nop
}, },