68 lines
4.4 KiB
Python
68 lines
4.4 KiB
Python
"""Stage Bedrock views with Java platform adapters. Rendering stays upstream."""
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def replace(text, old, new):
|
|
if text.count(old) != 1:
|
|
raise ValueError(f"Bedrock UI adapter expected one occurrence of {old!r}")
|
|
return text.replace(old, new)
|
|
|
|
|
|
def region(text, start, end, content):
|
|
left = text.index(start)
|
|
right = text.index(end, left)
|
|
return text[:left] + content + text[right:]
|
|
|
|
|
|
def generate(src, out):
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
for name, location in {
|
|
"clickgui": "gui", "account_screen": "gui", "startup_intro": "gui", "music_player": "modules"
|
|
}.items():
|
|
content = (src / location / f"{name}.h").read_text(encoding="utf-8")
|
|
if name == "clickgui":
|
|
content = region(content, "#include \"imgui.h\"", "inline std::string key_name", '#include "ui_bridge.h"\n\n')
|
|
content = replace(content, "const bool menu_down = is_key_down(k_menu_key);", "const bool menu_down = false;")
|
|
content = replace(content, "const bool esc_down = is_key_down(VK_ESCAPE);", "const bool esc_down = false;")
|
|
content = replace(content, " void draw_backdrop() {", """ bool editing_hud() const { return editing_hud_; }
|
|
bool binding() const { return any_binding(); }
|
|
void escape() {
|
|
if (editing_hud_) editing_hud_ = false;
|
|
else close();
|
|
}
|
|
void draw_backdrop() {""")
|
|
content = replace(content, "if (is_key_down(vk)) {\n m.set_toggle_key",
|
|
"if (java_ui_binding_key(vk)) {\n m.set_toggle_key")
|
|
content = replace(content, "if (is_key_down(vk)) {\n // Keep",
|
|
"if (java_ui_binding_key(vk)) {\n // Keep")
|
|
content = replace(content, "for (auto& s:m.settings()) if (!s.hidden) draw_setting(s,inner_w);",
|
|
"for (auto& s:m.settings()) if (!s.hidden) draw_setting(s,inner_w);\n java_ui_module_extra(m,inner_w);")
|
|
elif name == "account_screen":
|
|
content = region(content, "#include", "namespace account_ui", '#include "ui_bridge.h"\n\n')
|
|
content = content.replace("licensing::client()", "java_ui_account_service()")
|
|
content = content.replace("licensing::config_path()", "java_ui_account_path()")
|
|
content = content.replace("licensing::saved_login::load(saved)", "licensing::saved_login::load(saved, java_ui_credential())")
|
|
content = content.replace("licensing::saved_login::forget()", "licensing::saved_login::forget(java_ui_credential())")
|
|
content = replace(content, 'L"http://127.0.0.1:8787/api",value', 'winrt::to_hstring(address).c_str(),value')
|
|
elif name == "startup_intro":
|
|
content = region(content, "#include <d3d11.h>", "namespace startup_intro", '#include "ui_bridge.h"\n\n')
|
|
content = replace(content, "Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture;", "java_ui_texture texture;")
|
|
content = replace(content, "void initialize_texture(ID3D11Device* device)", "void initialize_texture()")
|
|
content = replace(content, "if(!device || texture)return;", "if(texture)return;")
|
|
content = region(content, " D3D11_TEXTURE2D_DESC desc", " struct playback",
|
|
" texture.upload(128,128,pixels.data());\n }\n\n")
|
|
content = replace(content, "reinterpret_cast<ImTextureID>(texture.Get())", "ImTextureID(texture.Get())")
|
|
elif name == "music_player":
|
|
content = region(content, "#include", "class music_player", '#include "ui_bridge.h"\n#include "modules/text_hud.h"\n\n')
|
|
content = replace(content, "Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> image_;", "java_ui_texture image_;")
|
|
content = replace(content, "!art || !media_art::device || ", "!art || ")
|
|
content = region(content, " D3D11_TEXTURE2D_DESC desc", " }\n};",
|
|
" image_.upload(art->width,art->height,art->rgba.data());\n")
|
|
content = replace(content, " float text_font_size() const", " void release_texture() { image_.Reset(); }\n float text_font_size() const")
|
|
(out / f"bedrock_{name}.h").write_text(content, encoding="utf-8")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
generate(*(Path(arg) for arg in sys.argv[1:]))
|