Finish Classic 0.2 portability and release preparation (by Codex)
This commit is contained in:
1 parent
74ca973111
commit
6e5fa72ed5
13 files changed
+186
-25
No files matched your search
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include <RmlUi/Core.h>
|
||||
#include "launch/rml_path.hpp"
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -27,11 +29,15 @@ struct Renderer : Rml::RenderInterface {
|
||||
void EnableScissorRegion(bool) override {}
|
||||
void SetScissorRegion(Rml::Rectanglei) override {}
|
||||
Rml::TextureHandle LoadTexture(Rml::Vector2i &dimensions, const Rml::String &name) override {
|
||||
std::ifstream input(name, std::ios::binary);
|
||||
auto *files = Rml::GetFileInterface();
|
||||
const auto input = files->Open(name);
|
||||
if (!input)
|
||||
throw std::runtime_error("Stadium asset unavailable: " + name);
|
||||
unsigned char header[18]{};
|
||||
input.read(reinterpret_cast<char *>(header), sizeof(header));
|
||||
if (!input || header[2] != 2 || header[16] != 24)
|
||||
throw std::runtime_error("Stadium asset unavailable");
|
||||
const auto read = files->Read(header, sizeof(header), input);
|
||||
files->Close(input);
|
||||
if (read != sizeof(header) || header[2] != 2 || header[16] != 24)
|
||||
throw std::runtime_error("Invalid stadium asset: " + name);
|
||||
dimensions = {header[12] + 256 * header[13], header[14] + 256 * header[15]};
|
||||
return 1;
|
||||
}
|
||||
@@ -44,21 +50,41 @@ void require(bool value, const std::string &error) {
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char **argv) try {
|
||||
require(argc == 2, "launcher asset directory required");
|
||||
require(argc == 2 || (argc == 3 && std::string(argv[2]) == "unicode"), "launcher asset directory required");
|
||||
std::filesystem::path assets(argv[1]);
|
||||
struct Cleanup {
|
||||
std::filesystem::path path;
|
||||
~Cleanup() {
|
||||
if (!path.empty()) {
|
||||
std::error_code error;
|
||||
std::filesystem::remove_all(path, error);
|
||||
}
|
||||
}
|
||||
} cleanup;
|
||||
if (argc == 3) {
|
||||
cleanup.path = std::filesystem::temp_directory_path() /
|
||||
("openbmh-rml-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
std::filesystem::create_directory(cleanup.path);
|
||||
const auto unicode = cleanup.path / std::filesystem::path(u8"Fußball 日本語") / "launcher";
|
||||
std::filesystem::create_directories(unicode);
|
||||
std::filesystem::copy(assets, unicode, std::filesystem::copy_options::recursive);
|
||||
assets = unicode;
|
||||
}
|
||||
System system;
|
||||
Renderer renderer;
|
||||
bmh::rml::AssetFiles files;
|
||||
Rml::SetSystemInterface(&system);
|
||||
Rml::SetRenderInterface(&renderer);
|
||||
Rml::SetFileInterface(&files);
|
||||
require(Rml::Initialise(), "RmlUI initialization");
|
||||
struct Shutdown {
|
||||
~Shutdown() { Rml::Shutdown(); }
|
||||
} shutdown;
|
||||
const std::filesystem::path assets(argv[1]);
|
||||
for (const auto *weight : {"Regular", "Bold"})
|
||||
require(Rml::LoadFontFace((assets / (std::string("LatoLatin-") + weight + ".ttf")).string()),
|
||||
require(Rml::LoadFontFace(bmh::rml::asset_path(assets / (std::string("LatoLatin-") + weight + ".ttf"))),
|
||||
"font load");
|
||||
auto *context = Rml::CreateContext("test", {1100, 688});
|
||||
auto *document = context->LoadDocument((assets / "launcher.rml").string());
|
||||
auto *document = context->LoadDocument(bmh::rml::asset_path(assets / "launcher.rml"));
|
||||
require(document != nullptr, "launcher document load");
|
||||
document->Show();
|
||||
for (const auto size : {Rml::Vector2i(1100, 688), Rml::Vector2i(800, 540), Rml::Vector2i(2200, 1376)}) {
|
||||
|
||||
Reference in new issue
Block a user