Skip to content

Instantly share code, notes, and snippets.

@xyx0no646
Last active August 28, 2021 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyx0no646/b4049970c16dcd4ab526706fdf4a6a8a to your computer and use it in GitHub Desktop.
Save xyx0no646/b4049970c16dcd4ab526706fdf4a6a8a to your computer and use it in GitHub Desktop.
Web版吉里吉里SDL2の[edit]タグで日本語入力ができない問題を一応解決する、LinkEditLayerを誇張するマクロ(TJSスクリプト)
;Licence CC0 / author:@xyx0no646
;ご自由にお使いください
[iscript]
// LinkEditLayerを誇張する。
// Emscriptenの場合は、ClickされたらJavaScriptのPromptを出す
// それ以外はただのLinkEditLayer
// 2021/8/26 更新 文字列のEvalを避け、windowコンテキストを持って来るようにする
// キャンセル時の挙動を改善
class LinkEditLayer extends EditLayer
{
// メッセージレイヤに「リンク」として管理されるための
// 単一行編集レイヤ
var linkNum; // リンク番号
var exp; // 式
function onClick(){
// 全吉里吉里共通のクリック処理
super.onClick(...);
// Emscriptenの場合は特別処理!
if(System.platformName=="Emscripten") {
var words = Edit_text;
while(this.Edit_selStart !== 0) {
this.deleteBeforeCaret();
}
var js = KirikiriEmscriptenInterface.evalJS('window');
var result = js.prompt('入力してください',words);
if (typeof result == 'String') {
words = result;
}
this.insertCharacter(words);
}
}
function LinkEditLayer(win, par)
{
// コンストラクタ
super.EditLayer(...);
joinFocusChain = false; // フォーカスチェーンには参加しない
hint = "";
}
function finalize()
{
super.finalize(...);
}
function assign(src)
{
super.assign(src);
linkNum = src.linkNum;
exp = src.exp;
}
function onKeyDown(key, shift, process)
{
// 縦書きの時は右と左を入れ替える
if(Edit_vertical)
{
if(key == VK_LEFT) key = VK_RIGHT;
else if(key == VK_RIGHT) key = VK_LEFT;
}
super.onKeyDown(key, shift, process);
}
function onSearchPrevFocusable(layer)
{
super.onSearchPrevFocusable(parent.findPrevFocusable(this, layer));
}
function onSearchNextFocusable(layer)
{
super.onSearchNextFocusable(parent.findNextFocusable(this, layer));
}
function onFocus(prevfocused, direction)
{
parent.keyLink = linkNum;
super.onFocus(...);
}
function commit()
{
kag.inputTemp = text;
Scripts.eval(("(" + exp + ") = kag.inputTemp"));
}
}
[endscript]
;コピペ時は重複注意
[return]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment