Skip to content

Commit

Permalink
Иди нахуй винда со своей ебучей кодировкой
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Aug 26, 2024
1 parent 5c3cdd0 commit d9148a6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Code/gui/conntect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from pathlib import Path

import dearpygui.dearpygui as dpg
from api.chat import ChatModule
from DMBotNetwork import Client
from misc import decode_string
from root_path import ROOT_PATH
from systems.loc import Localization as loc
from api.chat import ChatModule

logger = logging.getLogger("Connect")

class ConnectManager:
Expand All @@ -29,7 +31,8 @@ def create_connect_window(self):
dpg.add_button(label="send", callback=self.send_chat_msg)

async def send_chat_msg(self, *args):
await ChatModule.send_ooc(dpg.get_value("OOC_CHAT"))
value = dpg.get_value("OOC_CHAT")
await ChatModule.send_ooc(decode_string(value))

async def run_client(self, sender, app_data, user_data):
await Client.close_connection()
Expand Down
21 changes: 19 additions & 2 deletions Code/gui/fonts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import sys

import dearpygui.dearpygui as dpg
from root_path import ROOT_PATH


class FontManager:

@staticmethod
def load_fonts():
with dpg.font_registry():
with dpg.font(str(ROOT_PATH / 'Content' / 'Client' / 'fronts' / 'Monocraft' / 'Monocraft.otf'), 13) as default_font:
dpg.add_font_range_hint(dpg.mvFontRangeHint_Default)
dpg.add_font_range_hint(dpg.mvFontRangeHint_Cyrillic)


dpg.add_font_range(0x0391, 0x03C9) #Greek character range
dpg.add_font_range(0x2070, 0x209F) #Range of upper and lower numerical indices

if sys.platform == 'win32': # Иди нахуй винда
_remap_chars()

dpg.bind_font(default_font)

def _remap_chars():
biglet = 0x0410
for i1 in range(0x00C0, 0xE0):
dpg.add_char_remap(i1, biglet)
dpg.add_char_remap(i1 + 0x20, biglet + 0x20)
biglet += 1

dpg.add_char_remap(0x00A8, 0x0401) # Ё
dpg.add_char_remap(0x00B8, 0x0451) # ё
19 changes: 19 additions & 0 deletions Code/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys


def decode_string(instr : str):
"""Данную функцию нужно вызывать каждый раз при получении данных от пользователя (input_text). Винда у нас особая и не работает по нормальному. Язык стола зачарований из майна нам не нужен (и тот который блять на винде только)
"""
if not sys.platform == 'win32': # Иди нахуй винда
return instr

translation_table = str.maketrans({
chr(i): chr(i + 0x350) for i in range(0x00C0, 0x100)
})

translation_table.update({
0x00B8: chr(0x0451),
0x00A8: chr(0x0401)
})

return instr.translate(translation_table)

0 comments on commit d9148a6

Please sign in to comment.