Panakotta00 / FicsIt-Networks

Control, Monitor, Manage and Automate your Satisfactory.
https://ficsit.app/mod/FicsItNetworks
GNU General Public License v3.0
156 stars 51 forks source link

DoubleByteCodeStrings not rendering #182

Closed VoiD2008 closed 2 years ago

VoiD2008 commented 2 years ago

strings with double byte characters works wrong for example

local string1 = "abc"
local string2 = "эюя" --cyrillic
print(#string1) -- outputs 3
print(#string2) -- outputs 6
print(string2) -- outputs squares in console and the same gpu:setText

as temporary workaround i made transliteration function but its ugly

local f = false
function parse(text)
    local textBuffer = ""
    local charCodes = {c384 = "a",c385 = "b",c386 = "v",c387 = "g",c388 = "d",c389 = "e",c354 = "e",c390 = "zh",c391 = "z",c392 = "i",c393 = "yi",c394 = "k",c395 = "l",c396 = "m",c397 = "n",c398 = "o",c399 = "p",c337 = "r",c338 = "s",c339 = "t",c340 = "u",c341 = "f",c342 = "h",c343 = "c",c344 = "ch",c345 = "sh",c346 = "sch",c350 = "e",c351 = "yu",c352 = "ya",c353 = "B",c354 = "V",c355 = "G",c356 = "D",c357 = "E",c358 = "ZH",c359 = "Z",c360 = "I",c361 = "YI",c362 = "K",c363 = "L",c364 = "M",c365 = "N",c366 = "O",c367 = "P",c368 = "R",c369 = "S",c370 = "T",c371 = "U",c372 = "F",c373 = "H",c374 = "C",c375 = "CH",c376 = "SH",c377 = "SCH",c381 = "E",c382 = "YU",c383 = "YA",c348 = "ii",c379 = "II",c349 = "`",c380 = "`",c347 = "`",c378 = "`"}
    for i = 1, #text do
        if f == false then
            local bt = string.byte(text, i)
            if bt == 208 or bt == 209 then
                local char = charCodes["c"..string.byte(text, i) + string.byte(text, i + 1)]
                if not char then
                    textBuffer = textBuffer.."_"
                else
                    textBuffer = textBuffer..char
                end
                f = true
            else
                textBuffer = textBuffer..string.sub(text, i, i)
            end
        else
            f = false
        end
    end
    return textBuffer
end
Panakotta00 commented 2 years ago

The the length of the string is different because Lua doesnt care native about that and uses single byte characters. Tho it mostly doesnt really matter. The input and output can handle it properly otherwise they would display two characters per double byte char. The symbols you see currently appear because it seems like the font doesnt support the characters you want to use... F.e. German Umlaute work "äüö" At least this seems to be case but i can't fully tell, gonna investigate further