From 3524d06813cd4841056901111bf649b023274255 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 29 Jan 2024 16:55:59 -0500 Subject: [PATCH] - export `FFont::GetChar()` to ZScript --- src/common/scripting/interface/vmnatives.cpp | 20 ++++++++++++++++++++ wadsrc/static/zscript/engine/base.zs | 1 + 2 files changed, 21 insertions(+) diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 730465a34eb..8a5674afd1b 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -770,6 +770,26 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetDisplayTopOffset, GetDisplayTopOffset) ACTION_RETURN_FLOAT(GetDisplayTopOffset(self, code)); } +static int GetChar(FFont* font, int c) +{ + int texc = 0; + auto getch = font->GetChar(c, CR_UNDEFINED, nullptr); + if (getch) + texc = getch->GetID().GetIndex(); + return texc; +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetChar, ::GetChar) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_INT(mchar); + + if (numret > 0) ret[0].SetInt(::GetChar(self, mchar)); + if (numret > 1) ret[1].SetInt(self->GetCharWidth(mchar)); + return min(2, numret); +} + + //========================================================================== // // file system diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index f24b71d013d..f55919116a8 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -657,6 +657,7 @@ struct Font native native BrokenLines BreakLines(String text, int maxlen); native int GetGlyphHeight(int code); native int GetDefaultKerning(); + native TextureID, int GetChar(int c); } struct Console native