xpack install #7

Open
Persson-dev wants to merge 12 commits from xpack into main
14 changed files with 120 additions and 155 deletions
Showing only changes of commit 19d953891b - Show all commits

5
.gitignore vendored
View File

@@ -17,3 +17,8 @@ doc/mockups/*
data/pieces/*.bin data/pieces/*.bin
data/config/*.bin data/config/*.bin
data/config/keybinds/*.bin data/config/keybinds/*.bin
# flatpak files
flatpak/.flatpak-builder
flatpak/builddir
flatpak/repo

2
flatpak/FlatpakLaunch.sh Normal file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
JMINOS_DATA="/app/share" /app/bin/graph

View File

@@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Version=1.0
Name=Jminos
Exec=/usr/bin/graph
Terminal=false
Categories=Games;
Comment=Amazing stacker game by the J

View File

@@ -0,0 +1,40 @@
id: org.zulianc.jminos
runtime: org.freedesktop.Platform
runtime-version: "24.08"
sdk: org.freedesktop.Sdk
command: FlatpakLaunch.sh
finish-args:
- --socket=x11
- --device=dri
modules:
- name: xmake
buildsystem: simple
no-autogen: true
cleanup: ['*']
build-commands:
- ./configure --prefix=/app
- make -j $(nproc)
- prefix=/app ./scripts/get.sh __local__ __install_only__
sources:
- type: git
url: https://github.com/xmake-io/xmake.git
tag: v3.0.1
- name: jminos
buildsystem: simple
build-options:
build-args:
- --share=network
build-commands:
- xmake f --policies=package.install_locally -m release -y
- xmake
- xmake install -o output
- install -D output/bin/* ${FLATPAK_DEST}/bin
- cp -r output/data ${FLATPAK_DEST}/share
- install -D flatpak/FlatpakLaunch.sh ${FLATPAK_DEST}/bin
- install -D flatpak/org.zulianc.jminos.desktop ${FLATPAK_DEST}/share/applications
sources:
- type: dir
path: ..

View File

@@ -15,9 +15,7 @@ AppMenu::AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings>
settings(settings), settings(settings),
renderWindow(renderWindow) { renderWindow(renderWindow) {
const Asset& file = getResource(AssetName::data_fonts_pressstart_prstartk_ttf); this->pressStartFont = sf::Font(AssetManager::getResourcePath("data/fonts/pressstart/prstart.ttf"));
this->pressStartFont = sf::Font(file.data, file.size);
} }
void AppMenu::updateMetaBinds() { void AppMenu::updateMetaBinds() {

View File

@@ -23,9 +23,7 @@ SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menu
std::string textureName = ACTION_NAMES[action]; std::string textureName = ACTION_NAMES[action];
textureName = std::regex_replace(textureName, std::regex(" "), ""); textureName = std::regex_replace(textureName, std::regex(" "), "");
const Asset& textureData = getResource("data/images/keybinds/" + textureName + ".png"); this->iconTextures[action] = sf::Texture(AssetManager::getResourcePath("data/images/keybinds/" + textureName + ".png"), false, {{0, 0}, {16, 16}});
this->iconTextures[action] = sf::Texture(textureData.data, textureData.size, false, {{0, 0}, {16, 16}});
} }
} }

View File

@@ -6,6 +6,7 @@
#include <set> #include <set>
#include <fstream> #include <fstream>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "../Utils/AssetManager.h"
Keybinds::Keybinds(int layoutNumber) : Keybinds::Keybinds(int layoutNumber) :
@@ -20,7 +21,7 @@ Keybinds::Keybinds(int layoutNumber) :
} }
void Keybinds::loadKeybindsFromFile() { void Keybinds::loadKeybindsFromFile() {
std::ifstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::binary); std::ifstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::binary);
for (Action action : ACTION_LIST_IN_ORDER) { for (Action action : ACTION_LIST_IN_ORDER) {
this->keybinds.at(action).clear(); this->keybinds.at(action).clear();
@@ -47,7 +48,7 @@ void Keybinds::loadKeybindsFromFile() {
void Keybinds::saveKeybindsToFile() const { void Keybinds::saveKeybindsToFile() const {
if (!this->modifiable) return; if (!this->modifiable) return;
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::trunc | std::ios::binary); std::ofstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::trunc | std::ios::binary);
char byte; char byte;
for (Action action : ACTION_LIST_IN_ORDER) { for (Action action : ACTION_LIST_IN_ORDER) {

View File

@@ -3,6 +3,7 @@
#include "../Core/Menu.h" #include "../Core/Menu.h"
#include "Keybinds.h" #include "Keybinds.h"
#include "PiecesType.h" #include "PiecesType.h"
#include "../Utils/AssetManager.h"
#include <vector> #include <vector>
#include <optional> #include <optional>
@@ -49,7 +50,7 @@ void Settings::loadPieces(int loadablePiecesSizeRequest) {
} }
void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> loadablePiecesSizeRequest) { void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> loadablePiecesSizeRequest) {
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary); std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
char byte; char byte;
// file format version // file format version
@@ -158,7 +159,7 @@ void Settings::saveSettingsToFile() const {
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile(); this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary); std::ofstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::trunc | std::ios::binary);
char byte; char byte;
// file format version // file format version

View File

@@ -4,6 +4,8 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include "../Utils/AssetManager.h"
[[nodiscard]] bool resetSettingsFile(); [[nodiscard]] bool resetSettingsFile();
[[nodiscard]] bool resetKeybindFile(int layout); [[nodiscard]] bool resetKeybindFile(int layout);
@@ -18,7 +20,7 @@ int main() {
PiecesFiles pf; PiecesFiles pf;
bool warned = false; bool warned = false;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin"))) {
#ifndef DEBUG #ifndef DEBUG
if (!warned && i > DEBUG_PIECES_SIZE) { if (!warned && i > DEBUG_PIECES_SIZE) {
std::cout << "IMPORTANT: You are currently in release mode, if you do not wish to generate big pieces (can take several minutes), type 'xmake f -m debug'." << std::endl; std::cout << "IMPORTANT: You are currently in release mode, if you do not wish to generate big pieces (can take several minutes), type 'xmake f -m debug'." << std::endl;
@@ -36,7 +38,7 @@ int main() {
bool releasePiecesGenerated = true; bool releasePiecesGenerated = true;
for (int i = DEBUG_PIECES_SIZE + 1; i <= RELEASE_PIECES_SIZE; i++) { for (int i = DEBUG_PIECES_SIZE + 1; i <= RELEASE_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin"))) {
releasePiecesGenerated = false; releasePiecesGenerated = false;
} }
} }
@@ -47,29 +49,29 @@ int main() {
bool everythingGenerated = true; bool everythingGenerated = true;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
std::string filePath = "data/pieces/" + std::to_string(i) + "minos.bin"; auto filePath = AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin");
if (!std::filesystem::exists(filePath)) { if (!std::filesystem::exists(filePath)) {
std::cout << "ERROR: Could not open file " + filePath << std::endl; std::cout << "ERROR: Could not open file " << filePath << std::endl;
everythingIsOK &= false; everythingIsOK &= false;
} }
} }
// CHECK CONFIG FILES // CHECK CONFIG FILES
if (!std::filesystem::exists("data/config/settings.bin")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/settings.bin"))) {
std::cout << "INFO: Settings file not found, generating..." << std::endl; std::cout << "INFO: Settings file not found, generating..." << std::endl;
everythingIsOK &= resetSettingsFile(); everythingIsOK &= resetSettingsFile();
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) { for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(i) + ".bin"))) {
std::cout << "INFO: Keybind file number " << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl; std::cout << "INFO: Keybind file number " << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
everythingIsOK &= resetKeybindFile(i); everythingIsOK &= resetKeybindFile(i);
} }
} }
} }
else { else {
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary); std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
char byte; char byte;
settingsFile.get(byte); settingsFile.get(byte);
@@ -99,14 +101,14 @@ int main() {
bool resetSettingsFile() { bool resetSettingsFile() {
if (!std::filesystem::exists("data/config")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/config"))) {
std::filesystem::create_directories("data/config"); std::filesystem::create_directories(AssetManager::getResourcePath("data/config"));
} }
std::string filePath ="data/config/settings.bin"; auto filePath = AssetManager::getResourcePath("data/config/settings.bin");
std::ofstream settingsFile(filePath, std::ios::trunc | std::ios::binary); std::ofstream settingsFile(filePath, std::ios::trunc | std::ios::binary);
if (!settingsFile.good()) { if (!settingsFile.good()) {
std::cerr << "ERROR: Could not open file " + filePath << std::endl; std::cerr << "ERROR: Could not open file " << filePath << std::endl;
return false; return false;
} }
@@ -180,14 +182,14 @@ bool resetKeybindFile(int layout) {
return false; return false;
} }
if (!std::filesystem::exists("data/config/keybinds")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds"))) {
std::filesystem::create_directories("data/config/keybinds"); std::filesystem::create_directories(AssetManager::getResourcePath("data/config/keybinds"));
} }
std::string filePath = "data/config/keybinds/layout" + std::to_string(layout) + ".bin"; auto filePath = AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(layout) + ".bin");
std::ofstream layoutFile(filePath, std::ios::trunc | std::ios::binary); std::ofstream layoutFile(filePath, std::ios::trunc | std::ios::binary);
if (!layoutFile.good()) { if (!layoutFile.good()) {
std::cerr << "ERROR: Could not open file " + filePath << std::endl; std::cerr << "ERROR: Could not open file " << filePath << std::endl;
return false; return false;
} }

View File

@@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "../Common/Compression.h" #include "../Common/Compression.h"
#include "../Utils/AssetManager.h"
PiecesFiles::PiecesFiles() { PiecesFiles::PiecesFiles() {
@@ -140,7 +141,7 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
} }
bool PiecesFiles::getFilePath(int polyominoSize, std::string& filePath) const { bool PiecesFiles::getFilePath(int polyominoSize, std::string& filePath) const {
std::string dataFolderPath = "data/pieces/"; auto dataFolderPath = AssetManager::getResourcePath("data/pieces");
if (!std::filesystem::exists(dataFolderPath)) { if (!std::filesystem::exists(dataFolderPath)) {
std::filesystem::create_directories(dataFolderPath); std::filesystem::create_directories(dataFolderPath);
@@ -150,6 +151,6 @@ bool PiecesFiles::getFilePath(int polyominoSize, std::string& filePath) const {
return false; return false;
} }
filePath = dataFolderPath + std::to_string(polyominoSize) + "minos.bin"; filePath = dataFolderPath / (std::to_string(polyominoSize) + "minos.bin");
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
#include "../Pieces/Generator.h" #include "../Pieces/Generator.h"
#include "../Pieces/PiecesFiles.h" #include "../Pieces/PiecesFiles.h"
#include "TextApp.h" #include "TextApp.h"
#include "../Utils/AssetManager.h"
#include <chrono> #include <chrono>
#include <filesystem> #include <filesystem>
@@ -22,7 +23,7 @@ int main(int argc, char** argv) {
PiecesFiles pf; PiecesFiles pf;
bool warned = false; bool warned = false;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) { for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) { if (!std::filesystem::exists(AssetManager::getResourcePath("data/pieces/" + std::to_string(i) + "minos.bin"))) {
if (!warned) { if (!warned) {
std::cout << "INFO: Pieces files for size " << i << " not found, generating..." << std::endl; std::cout << "INFO: Pieces files for size " << i << " not found, generating..." << std::endl;
warned = true; warned = true;

View File

@@ -1,97 +1,12 @@
#include "./AssetManager.h" #include "AssetManager.h"
#include <map> namespace fs = std::filesystem;
static const unsigned char data_fonts_pressstart_prstart_ttf[] = { std::string AssetManager::getResourcePrefix() {
#include <data/fonts/pressstart/prstart.ttf.h> char* env = std::getenv("JMINOS_DATA");
}; return env ? env : std::string{};
static const unsigned char data_fonts_pressstart_prstartk_ttf[] = {
#include <data/fonts/pressstart/prstartk.ttf.h>
};
static const unsigned char data_images_keybinds_Rotate180_png[] = {
#include <data/images/keybinds/Rotate180.png.h>
};
static const unsigned char data_images_keybinds_Rotate0_png[] = {
#include <data/images/keybinds/Rotate0.png.h>
};
static const unsigned char data_images_keybinds_RotateCCW_png[] = {
#include <data/images/keybinds/RotateCCW.png.h>
};
static const unsigned char data_images_keybinds_Retry_png[] = {
#include <data/images/keybinds/Retry.png.h>
};
static const unsigned char data_images_keybinds_RotateCW_png[] = {
#include <data/images/keybinds/RotateCW.png.h>
};
static const unsigned char data_images_keybinds_Moveright_png[] = {
#include <data/images/keybinds/Moveright.png.h>
};
static const unsigned char data_images_keybinds_Harddrop_png[] = {
#include <data/images/keybinds/Harddrop.png.h>
};
static const unsigned char data_images_keybinds_Moveleft_png[] = {
#include <data/images/keybinds/Moveleft.png.h>
};
static const unsigned char data_images_keybinds_Hold_png[] = {
#include <data/images/keybinds/Hold.png.h>
};
static const unsigned char data_images_keybinds_Softdrop_png[] = {
#include <data/images/keybinds/Softdrop.png.h>
};
static const unsigned char data_images_keybinds_Pause_png[] = {
#include <data/images/keybinds/Pause.png.h>
};
static const Asset assets[] = {
{data_fonts_pressstart_prstart_ttf, sizeof(data_fonts_pressstart_prstart_ttf)},
{data_fonts_pressstart_prstartk_ttf, sizeof(data_fonts_pressstart_prstartk_ttf)},
{data_images_keybinds_Rotate180_png, sizeof(data_images_keybinds_Rotate180_png)},
{data_images_keybinds_Rotate0_png, sizeof(data_images_keybinds_Rotate0_png)},
{data_images_keybinds_RotateCCW_png, sizeof(data_images_keybinds_RotateCCW_png)},
{data_images_keybinds_Retry_png, sizeof(data_images_keybinds_Retry_png)},
{data_images_keybinds_RotateCW_png, sizeof(data_images_keybinds_RotateCW_png)},
{data_images_keybinds_Moveright_png, sizeof(data_images_keybinds_Moveright_png)},
{data_images_keybinds_Harddrop_png, sizeof(data_images_keybinds_Harddrop_png)},
{data_images_keybinds_Moveleft_png, sizeof(data_images_keybinds_Moveleft_png)},
{data_images_keybinds_Hold_png, sizeof(data_images_keybinds_Hold_png)},
{data_images_keybinds_Softdrop_png, sizeof(data_images_keybinds_Softdrop_png)},
{data_images_keybinds_Pause_png, sizeof(data_images_keybinds_Pause_png)},
};
static const std::map<std::string, AssetName> assetMap = {
{"data/fonts/pressstart/prstart.ttf", AssetName::data_fonts_pressstart_prstart_ttf},
{"data/fonts/pressstart/prstartk.ttf", AssetName::data_fonts_pressstart_prstartk_ttf},
{"data/images/keybinds/Rotate180.png", AssetName::data_images_keybinds_Rotate180_png},
{"data/images/keybinds/Rotate0.png", AssetName::data_images_keybinds_Rotate0_png},
{"data/images/keybinds/RotateCCW.png", AssetName::data_images_keybinds_RotateCCW_png},
{"data/images/keybinds/Retry.png", AssetName::data_images_keybinds_Retry_png},
{"data/images/keybinds/RotateCW.png", AssetName::data_images_keybinds_RotateCW_png},
{"data/images/keybinds/Moveright.png", AssetName::data_images_keybinds_Moveright_png},
{"data/images/keybinds/Harddrop.png", AssetName::data_images_keybinds_Harddrop_png},
{"data/images/keybinds/Moveleft.png", AssetName::data_images_keybinds_Moveleft_png},
{"data/images/keybinds/Hold.png", AssetName::data_images_keybinds_Hold_png},
{"data/images/keybinds/Softdrop.png", AssetName::data_images_keybinds_Softdrop_png},
{"data/images/keybinds/Pause.png", AssetName::data_images_keybinds_Pause_png},
};
const Asset& getResource(AssetName fileName) {
return assets[static_cast<std::size_t>(fileName)];
} }
const Asset& getResource(const std::string& fileName) { fs::path AssetManager::getResourcePath(const std::string& resource) {
return getResource(assetMap.at(fileName)); return fs::path{getResourcePrefix()} / resource;
} }

View File

@@ -2,29 +2,10 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <filesystem>
struct Asset { class AssetManager {
const unsigned char* data; public:
std::size_t size; static std::string getResourcePrefix();
}; static std::filesystem::path getResourcePath(const std::string& resource);
};
enum class AssetName {
data_fonts_pressstart_prstart_ttf,
data_fonts_pressstart_prstartk_ttf,
data_images_keybinds_Rotate180_png,
data_images_keybinds_Rotate0_png,
data_images_keybinds_RotateCCW_png,
data_images_keybinds_Retry_png,
data_images_keybinds_RotateCW_png,
data_images_keybinds_Moveright_png,
data_images_keybinds_Harddrop_png,
data_images_keybinds_Moveleft_png,
data_images_keybinds_Hold_png,
data_images_keybinds_Softdrop_png,
data_images_keybinds_Pause_png,
};
const Asset& getResource(AssetName fileName);
const Asset& getResource(const std::string& fileName);

View File

@@ -1,8 +1,11 @@
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
includes("xmake/bin2c.lua") set_version("1.0.0")
set_project("org.zulianc.jminos")
add_requires("sfml 3.0.0", "zlib") includes("@builtin/xpack")
add_requires("sfml 3.0.0", "zlib", {system = false})
set_languages("c++20") set_languages("c++20")
@@ -10,7 +13,7 @@ set_rundir(".")
target("core") target("core")
set_kind("$(kind)") set_kind("$(kind)")
add_files("src/Pieces/*.cpp", "src/Core/*.cpp", "src/Common/*.cpp") add_files("src/Pieces/*.cpp", "src/Core/*.cpp", "src/Common/*.cpp", "src/Utils/*.cpp")
add_packages("zlib") add_packages("zlib")
target("text") target("text")
@@ -27,16 +30,11 @@ target("bmark")
target("graph") target("graph")
set_default(true) set_default(true)
add_rules("bin2c", {
extensions = {".png", ".ttf"},
outputSource = {"src/Utils/AssetManager.cpp"},
outputHeader = {"src/Utils/AssetManager.h"}
})
set_kind("binary") set_kind("binary")
add_files("./src/GraphicalUI/**.cpp") add_files("./src/GraphicalUI/**.cpp")
add_files("data/fonts/**.ttf", "data/images/**.png")
add_deps("core") add_deps("core")
add_packages("sfml") add_packages("sfml")
add_installfiles("(data/**)")
if is_mode("debug") then if is_mode("debug") then
add_defines("DEBUG") add_defines("DEBUG")
@@ -46,6 +44,20 @@ if is_plat("mingw") then
add_ldflags("-static-libstdc++", "-static") add_ldflags("-static-libstdc++", "-static")
end end
xpack("jminos")
set_formats("flatpak")
set_extension("")
set_title("jminos")
set_author("zulianc")
set_description("A test installer.")
set_homepage("https://git.ale-pri.com/TetrisNerd/jminos")
set_company("org.zulianc")
on_package(function (package)
os.cd("flatpak")
os.exec("flatpak-builder --force-clean --user --install-deps-from=flathub --repo=repo --install builddir org.zulianc.jminos.yml")
os.exec("flatpak build-bundle repo jminos.flatpak org.zulianc.jminos --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo")
os.mv("jminos.flatpak", package:outputdir())
end)
-- --
-- If you want to known more usage about xmake, please see https://xmake.io -- If you want to known more usage about xmake, please see https://xmake.io