From a610e42f43e8966e5e3911aaebcc9df7a52345a8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 23 Oct 2019 23:25:09 +1100 Subject: [PATCH] Attempt to intercept textinput events and replicate characters entered into in-game chat --- src/Window.c | 20 ++++++++++++++++---- src/World.c | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Window.c b/src/Window.c index c73a79c2b..130452d20 100644 --- a/src/Window.c +++ b/src/Window.c @@ -2995,13 +2995,17 @@ static EM_BOOL Window_Key(int type, const EmscriptenKeyboardEvent* ev , void* da (key >= KEY_INSERT && key <= KEY_MENU) || (key >= KEY_ENTER && key <= KEY_NUMLOCK && key != KEY_SPACE); } -static EM_BOOL Window_KeyPress(int type, const EmscriptenKeyboardEvent* ev, void* data) { +/* reused for touch keyboard input down in Window_OpenKeyboard */ +EMSCRIPTEN_KEEPALIVE void Window_ProcessKeyChar(int charCode) { char keyChar; - Window_CorrectFocus(); - - if (Convert_TryUnicodeToCP437(ev->charCode, &keyChar)) { + if (Convert_TryUnicodeToCP437(charCode, &keyChar)) { Event_RaiseInt(&InputEvents.Press, keyChar); } +} + +static EM_BOOL Window_KeyPress(int type, const EmscriptenKeyboardEvent* ev, void* data) { + Window_CorrectFocus(); + Window_ProcessKeyChar(ev->charCode); return true; } @@ -3188,6 +3192,13 @@ void Window_OpenKeyboard(void) { if (!elem) { elem = document.createElement('textarea'); elem.setAttribute('style', 'position:absolute; left:0; top:0; width:100%; height:100%; opacity:0.3; resize:none; pointer-events:none;'); + elem.addEventListener("textInput", + function(ev) { + for (var i = 0; i < ev.data.length; i++) { + var code = ev.data.charCodeAt(i); + ccall('Window_ProcessKeyChar', 'void', ['number'], [code]); + } + }, false); window.cc_inputElem = elem; } @@ -3196,6 +3207,7 @@ void Window_OpenKeyboard(void) { elem.click(); }); } + void Window_CloseKeyboard(void) { if (!Input_TouchMode) return; Platform_LogConst("CLOSE SESAME"); diff --git a/src/World.c b/src/World.c index 3944b79c1..a7c43177e 100644 --- a/src/World.c +++ b/src/World.c @@ -250,6 +250,10 @@ float Respawn_HighestSolidY(struct AABB* bb) { for (z = minZ; z <= maxZ; z++) { v.Z = (float)z; for (x = minX; x <= maxX; x++) { v.X = (float)x; + /* TODO: Maybe use how picking gets blocks, so the bedrock */ + /* just below and just on borders of the map is treated as such */ + /* Not sure if this is really necessary though, it seems to work */ + /* just fine already when you're standing on the bottom of the map. */ block = World_SafeGetBlock(x, y, z); Vec3_Add(&blockBB.Min, &v, &Blocks.MinBB[block]); Vec3_Add(&blockBB.Max, &v, &Blocks.MaxBB[block]);