mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
assets: Migrate minosoft to assets manager
This commit is contained in:
parent
fb8e29cbcf
commit
f2b12c0f1c
@ -1,6 +1,6 @@
|
||||
# Minecraft Versions
|
||||
|
||||
Once mojang releases a new minecraft version, you need to add the version to the [versions.json](/src/main/resources/assets/mapping/versions.json).
|
||||
Once mojang releases a new minecraft version, you need to add the version to the [versions.json](/src/main/resources/assets/minosoft/mapping/versions.json).
|
||||
|
||||
The file is a huge json object, see below:
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -118,7 +118,7 @@
|
||||
<prefix>git</prefix>
|
||||
<verbose>false</verbose>
|
||||
<generateGitPropertiesFile>true</generateGitPropertiesFile>
|
||||
<generateGitPropertiesFilename>${project.build.outputDirectory}/assets/git.json</generateGitPropertiesFilename>
|
||||
<generateGitPropertiesFilename>${project.build.outputDirectory}/assets/minosoft/git.json</generateGitPropertiesFilename>
|
||||
<format>json</format>
|
||||
<gitDescribe>
|
||||
<skip>false</skip>
|
||||
|
@ -19,8 +19,10 @@ import com.jfoenix.controls.JFXDialogLayout;
|
||||
import de.bixilon.minosoft.config.Configuration;
|
||||
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||
import de.bixilon.minosoft.data.accounts.Account;
|
||||
import de.bixilon.minosoft.data.assets.JarAssetsManager;
|
||||
import de.bixilon.minosoft.data.assets.Resources;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.gui.main.GUITools;
|
||||
import de.bixilon.minosoft.gui.main.Launcher;
|
||||
@ -32,6 +34,7 @@ import de.bixilon.minosoft.modding.loading.ModLoader;
|
||||
import de.bixilon.minosoft.modding.loading.Priorities;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.protocol.LANServerListener;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.terminal.CLI;
|
||||
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
||||
import de.bixilon.minosoft.util.GitInfo;
|
||||
@ -49,6 +52,7 @@ import javafx.stage.Stage;
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class Minosoft {
|
||||
public static final JarAssetsManager MINOSOFT_ASSETS_MANAGER = new JarAssetsManager(Minosoft.class);
|
||||
public static final HashSet<EventManager> EVENT_MANAGERS = new HashSet<>();
|
||||
public static final HashBiMap<Integer, Connection> CONNECTIONS = HashBiMap.create();
|
||||
private static final CountUpAndDownLatch START_STATUS_LATCH = new CountUpAndDownLatch(1);
|
||||
@ -125,7 +129,7 @@ public final class Minosoft {
|
||||
taskWorker.addTask(new Task(progress -> {
|
||||
Log.info("Loading versions.json...");
|
||||
long mappingStartLoadingTime = System.currentTimeMillis();
|
||||
Versions.loadAvailableVersions(Util.readJsonAssetResource("mapping/versions.json"));
|
||||
Versions.loadAvailableVersions(MINOSOFT_ASSETS_MANAGER.readJsonAsset(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "mapping/versions.json")));
|
||||
Log.info(String.format("Loaded %d versions in %dms", Versions.getVersionIdMap().size(), (System.currentTimeMillis() - mappingStartLoadingTime)));
|
||||
Resources.load();
|
||||
Log.info("Loaded all resources!");
|
||||
|
@ -23,9 +23,12 @@ import org.lwjgl.BufferUtils
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
|
||||
interface AssetsManager {
|
||||
|
||||
fun getAssetURL(resourceLocation: ResourceLocation): URL
|
||||
|
||||
fun getAssetSize(resourceLocation: ResourceLocation): Long
|
||||
|
||||
fun readAssetAsStream(resourceLocation: ResourceLocation): InputStream
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program.If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.assets
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
|
||||
class JarAssetsManager(
|
||||
private val clazz: Class<*>,
|
||||
) : AssetsManager {
|
||||
override fun getAssetURL(resourceLocation: ResourceLocation): URL {
|
||||
return clazz.getResource("/assets/${resourceLocation.namespace}/${resourceLocation.path}")
|
||||
}
|
||||
|
||||
override fun getAssetSize(resourceLocation: ResourceLocation): Long {
|
||||
val inputStream = readAssetAsStream(resourceLocation)
|
||||
val size = inputStream.available()
|
||||
inputStream.close()
|
||||
return size.toLong()
|
||||
}
|
||||
|
||||
override fun readAssetAsStream(resourceLocation: ResourceLocation): InputStream {
|
||||
return clazz.getResourceAsStream("/assets/${resourceLocation.namespace}/${resourceLocation.path}") ?: throw FileNotFoundException("Can not find jar asset $resourceLocation in ${clazz.simpleName}")
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.ZipEntry
|
||||
@ -183,6 +184,10 @@ class MinecraftAssetsManager(
|
||||
return getAssetSize(getAssetHash(resourceLocation))
|
||||
}
|
||||
|
||||
override fun getAssetURL(resourceLocation: ResourceLocation): URL {
|
||||
TODO()
|
||||
}
|
||||
|
||||
override fun readAssetAsStream(resourceLocation: ResourceLocation): InputStream {
|
||||
return readAssetAsStream(getAssetHash(resourceLocation))
|
||||
}
|
||||
|
@ -16,9 +16,11 @@ package de.bixilon.minosoft.data.assets;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -29,7 +31,7 @@ public class Resources {
|
||||
private static final HashMap<Version, String> PIXLYZER_VERSIONS = new HashMap<>();
|
||||
|
||||
public static void load() throws IOException {
|
||||
JsonObject json = Util.readJsonAssetResource("mapping/resources.json");
|
||||
JsonObject json = Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "mapping/resources.json"));
|
||||
|
||||
JsonObject versions = json.getAsJsonObject("versions");
|
||||
for (Map.Entry<String, JsonElement> versionEntry : versions.entrySet()) {
|
||||
@ -42,7 +44,7 @@ public class Resources {
|
||||
}
|
||||
|
||||
// PixLyzer
|
||||
JsonObject pixlyzerIndex = Util.readJsonAssetResource("mapping/pixlyzer_index.json");
|
||||
JsonObject pixlyzerIndex = Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "mapping/pixlyzer_index.json"));
|
||||
|
||||
for (Map.Entry<String, JsonElement> versionEntry : pixlyzerIndex.entrySet()) {
|
||||
|
||||
|
@ -15,12 +15,11 @@ package de.bixilon.minosoft.data.locale;
|
||||
|
||||
import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.ShutdownReasons;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.util.Util;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LocaleManager {
|
||||
private static Language fallbackLanguage; // en_US
|
||||
private static Language language;
|
||||
@ -47,8 +46,8 @@ public class LocaleManager {
|
||||
return fallbackLanguage.translate(key, data);
|
||||
}
|
||||
|
||||
private static Language loadLanguage(String language) throws IOException {
|
||||
return new Language(language, Util.readJsonAssetResource(String.format("locale/%s.json", language)));
|
||||
private static Language loadLanguage(String language) {
|
||||
return new Language(language, Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, String.format("locale/%s.json", language))));
|
||||
}
|
||||
|
||||
public static void load(String language) {
|
||||
|
@ -32,7 +32,7 @@ public class ResourceLocation implements Comparable<ResourceLocation> {
|
||||
public ResourceLocation(String full) {
|
||||
String[] split = full.split(":");
|
||||
if (split.length == 1) {
|
||||
this.namespace = ProtocolDefinition.DEFAULT_MOD;
|
||||
this.namespace = ProtocolDefinition.DEFAULT_NAMESPACE;
|
||||
this.path = full;
|
||||
} else {
|
||||
this.namespace = split[0];
|
||||
|
@ -18,7 +18,9 @@ import de.bixilon.minosoft.ShutdownReasons;
|
||||
import de.bixilon.minosoft.data.accounts.Account;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.gui.main.cells.AccountListCell;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.Initializable;
|
||||
@ -51,7 +53,7 @@ public class AccountWindow implements Initializable {
|
||||
|
||||
public void addMicrosoftAccount() {
|
||||
try {
|
||||
GUITools.showPane("/layout/dialogs/login/microsoft.fxml", Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_MICROSOFT_DIALOG_TITLE));
|
||||
GUITools.showPane(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/dialogs/login/microsoft.fxml"), Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_MICROSOFT_DIALOG_TITLE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Minosoft.shutdown(e.getMessage(), ShutdownReasons.LAUNCHER_FXML_LOAD_ERROR);
|
||||
@ -60,7 +62,7 @@ public class AccountWindow implements Initializable {
|
||||
|
||||
public void addMojangAccount() {
|
||||
try {
|
||||
GUITools.showPane("/layout/dialogs/login/mojang.fxml", Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_MOJANG_DIALOG_TITLE));
|
||||
GUITools.showPane(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/dialogs/login/mojang.fxml"), Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_MOJANG_DIALOG_TITLE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Minosoft.shutdown(e.getMessage(), ShutdownReasons.LAUNCHER_FXML_LOAD_ERROR);
|
||||
@ -69,7 +71,7 @@ public class AccountWindow implements Initializable {
|
||||
|
||||
public void addOfflineAccount() {
|
||||
try {
|
||||
GUITools.showPane("/layout/dialogs/login/offline.fxml", Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_OFFLINE_DIALOG_TITLE));
|
||||
GUITools.showPane(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/dialogs/login/offline.fxml"), Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.LOGIN_OFFLINE_DIALOG_TITLE));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Minosoft.shutdown(e.getMessage(), ShutdownReasons.LAUNCHER_FXML_LOAD_ERROR);
|
||||
|
@ -14,6 +14,8 @@
|
||||
package de.bixilon.minosoft.gui.main;
|
||||
|
||||
import com.jfoenix.controls.JFXComboBox;
|
||||
import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.util.logging.LogLevels;
|
||||
@ -33,7 +35,7 @@ import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
public class GUITools {
|
||||
public static final Image MINOSOFT_LOGO = new Image(GUITools.class.getResourceAsStream("/icons/windowIcon.png"));
|
||||
public static final Image MINOSOFT_LOGO = new Image(GUITools.class.getResourceAsStream("/assets/minosoft/textures/icons/windowIcon.png"));
|
||||
public static final ObservableList<Version> VERSIONS = FXCollections.observableArrayList();
|
||||
public static final JFXComboBox<Version> VERSION_COMBO_BOX = new JFXComboBox<>(VERSIONS);
|
||||
public static final ObservableList<LogLevels> LOG_LEVELS = FXCollections.observableList(Arrays.asList(LogLevels.values().clone()));
|
||||
@ -75,7 +77,7 @@ public class GUITools {
|
||||
}
|
||||
|
||||
public static Scene initializeScene(Scene scene) {
|
||||
scene.getStylesheets().add("/layout/style.css");
|
||||
scene.getStylesheets().add("/assets/minosoft/layout/style.css"); // ToDo: Migrate to minosoft assets manager
|
||||
if (scene.getWindow() instanceof Stage stage) {
|
||||
stage.getIcons().add(MINOSOFT_LOGO);
|
||||
}
|
||||
@ -87,8 +89,8 @@ public class GUITools {
|
||||
return pane;
|
||||
}
|
||||
|
||||
public static <T> T showPane(String fxmlPath, Modality modality, String title) throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader(GUITools.class.getResource(fxmlPath));
|
||||
public static <T> T showPane(ResourceLocation fxmlResourceLocation, Modality modality, String title) throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(fxmlResourceLocation));
|
||||
Parent root = loader.load();
|
||||
Stage stage = new Stage();
|
||||
stage.initModality(modality);
|
||||
|
@ -17,8 +17,10 @@ import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.ShutdownReasons;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||
import de.bixilon.minosoft.protocol.protocol.LANServerListener;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
@ -68,7 +70,7 @@ public class Launcher {
|
||||
ServerListCell.SERVER_LIST_VIEW.setItems(servers);
|
||||
LANServerListener.removeAll(); // remove all LAN Servers
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(Launcher.class.getResource("/layout/main.fxml"));
|
||||
FXMLLoader loader = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/main.fxml")));
|
||||
VBox root;
|
||||
try {
|
||||
root = loader.load();
|
||||
|
@ -23,9 +23,11 @@ import de.bixilon.minosoft.ShutdownReasons;
|
||||
import de.bixilon.minosoft.data.accounts.Account;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.data.text.ChatComponent;
|
||||
import de.bixilon.minosoft.protocol.protocol.LANServerListener;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.DNSUtil;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
import javafx.application.Platform;
|
||||
@ -63,7 +65,7 @@ public class MainWindow implements Initializable {
|
||||
|
||||
public static void manageAccounts() {
|
||||
try {
|
||||
Parent parent = new FXMLLoader(MainWindow.class.getResource("/layout/accounts.fxml")).load();
|
||||
Parent parent = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/accounts.fxml"))).load();
|
||||
Stage stage = new Stage();
|
||||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
stage.setTitle(LocaleManager.translate(Strings.MANAGE_ACCOUNTS_NO_ACCOUNT_ERROR_TITLE));
|
||||
@ -284,7 +286,7 @@ public class MainWindow implements Initializable {
|
||||
|
||||
public void openSettings() {
|
||||
try {
|
||||
Parent parent = new FXMLLoader(MainWindow.class.getResource("/layout/settings.fxml")).load();
|
||||
Parent parent = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/settings.fxml"))).load();
|
||||
Stage stage = new Stage();
|
||||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
stage.setTitle(LocaleManager.translate(Strings.SETTINGS_TITLE));
|
||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.data.Player;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Version;
|
||||
import de.bixilon.minosoft.data.mappings.versions.Versions;
|
||||
import de.bixilon.minosoft.data.player.PingBars;
|
||||
@ -80,7 +81,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
private Server server;
|
||||
|
||||
public static ServerListCell newInstance() {
|
||||
FXMLLoader loader = new FXMLLoader(ServerListCell.class.getResource("/layout/cells/server.fxml"));
|
||||
FXMLLoader loader = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/cells/server.fxml")));
|
||||
try {
|
||||
loader.load();
|
||||
return loader.getController();
|
||||
@ -442,7 +443,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
|
||||
public void manageSessions() {
|
||||
try {
|
||||
SessionsWindow sessionsWindow = GUITools.showPane("/layout/sessions.fxml", Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.SESSIONS_DIALOG_TITLE, this.server.getName().getMessage()));
|
||||
SessionsWindow sessionsWindow = GUITools.showPane(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/sessions.fxml"), Modality.APPLICATION_MODAL, LocaleManager.translate(Strings.SESSIONS_DIALOG_TITLE, this.server.getName().getMessage()));
|
||||
sessionsWindow.setServer(this.server);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -13,11 +13,14 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.main;
|
||||
|
||||
import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.modding.event.EventInvokerCallback;
|
||||
import de.bixilon.minosoft.modding.event.events.ConnectionStateChangeEvent;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
@ -43,7 +46,7 @@ public class SessionListCell extends ListCell<Connection> implements Initializab
|
||||
private Connection connection;
|
||||
|
||||
public static SessionListCell newInstance() {
|
||||
FXMLLoader loader = new FXMLLoader(SessionListCell.class.getResource("/layout/cells/session.fxml"));
|
||||
FXMLLoader loader = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/cells/session.fxml")));
|
||||
try {
|
||||
loader.load();
|
||||
return loader.getController();
|
||||
|
@ -18,7 +18,9 @@ import de.bixilon.minosoft.Minosoft;
|
||||
import de.bixilon.minosoft.data.accounts.Account;
|
||||
import de.bixilon.minosoft.data.locale.LocaleManager;
|
||||
import de.bixilon.minosoft.data.locale.Strings;
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation;
|
||||
import de.bixilon.minosoft.gui.main.GUITools;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
@ -49,7 +51,7 @@ public class AccountListCell extends ListCell<Account> implements Initializable
|
||||
private Account account;
|
||||
|
||||
public static AccountListCell newInstance() {
|
||||
FXMLLoader loader = new FXMLLoader(AccountListCell.class.getResource("/layout/cells/account.fxml"));
|
||||
FXMLLoader loader = new FXMLLoader(Minosoft.MINOSOFT_ASSETS_MANAGER.getAssetURL(new ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "layout/cells/account.fxml")));
|
||||
try {
|
||||
loader.load();
|
||||
return loader.getController();
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.StaticConfiguration
|
||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||
import de.bixilon.minosoft.data.Directions
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.data.world.*
|
||||
@ -92,7 +93,7 @@ class WorldRenderer(
|
||||
blockTextureArray.load()
|
||||
|
||||
|
||||
chunkShader = Shader("chunk_vertex.glsl", "chunk_fragment.glsl")
|
||||
chunkShader = Shader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "rendering/shader/chunk_vertex.glsl"), ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "rendering/shader/chunk_fragment.glsl"))
|
||||
chunkShader.load()
|
||||
|
||||
// register keybindings
|
||||
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.gui.rendering.hud.elements.HUDElement
|
||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||
import de.bixilon.minosoft.gui.rendering.textures.TextureArray
|
||||
import de.bixilon.minosoft.protocol.network.Connection
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import glm_.glm
|
||||
import glm_.mat4x4.Mat4
|
||||
import glm_.vec2.Vec2
|
||||
@ -133,7 +134,7 @@ class HUDTextElement(val connection: Connection, val hudRenderer: HUDRenderer, v
|
||||
hudMeshHUD = HUDFontMesh()
|
||||
hudMeshHUD.load()
|
||||
|
||||
fontShader = Shader("font_vertex.glsl", "font_fragment.glsl")
|
||||
fontShader = Shader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "rendering/shader/font_vertex.glsl"), ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "rendering/shader/font_fragment.glsl"))
|
||||
fontShader.load()
|
||||
|
||||
|
||||
|
@ -13,6 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.shader
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.assets.AssetsManager
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.exceptions.ShaderLoadingException
|
||||
import de.bixilon.minosoft.gui.rendering.textures.TextureArray
|
||||
import de.bixilon.minosoft.gui.rendering.util.OpenGLUtil
|
||||
@ -28,12 +31,15 @@ import org.lwjgl.opengl.GL11.GL_FALSE
|
||||
import org.lwjgl.opengl.GL20.*
|
||||
import org.lwjgl.system.MemoryUtil
|
||||
|
||||
class Shader(private val vertexPath: String, private val fragmentPath: String) {
|
||||
class Shader(
|
||||
private val vertexPath: ResourceLocation,
|
||||
private val fragmentPath: ResourceLocation,
|
||||
) {
|
||||
private var programId = 0
|
||||
|
||||
fun load(): Int {
|
||||
val vertexShader = ShaderUtil.createShader(vertexPath, GL_VERTEX_SHADER_ARB)
|
||||
val fragmentShader = ShaderUtil.createShader(fragmentPath, GL_FRAGMENT_SHADER_ARB)
|
||||
fun load(assetsManager: AssetsManager = Minosoft.MINOSOFT_ASSETS_MANAGER): Int {
|
||||
val vertexShader = ShaderUtil.createShader(assetsManager, vertexPath, GL_VERTEX_SHADER_ARB)
|
||||
val fragmentShader = ShaderUtil.createShader(assetsManager, fragmentPath, GL_FRAGMENT_SHADER_ARB)
|
||||
programId = glCreateProgramObjectARB()
|
||||
|
||||
if (programId.toLong() == MemoryUtil.NULL) {
|
||||
|
@ -13,21 +13,23 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.shader
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.assets.AssetsManager
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.exceptions.ShaderLoadingException
|
||||
import de.bixilon.minosoft.gui.rendering.util.OpenGLUtil
|
||||
import de.bixilon.minosoft.util.Util
|
||||
import org.lwjgl.opengl.ARBShaderObjects.*
|
||||
import org.lwjgl.opengl.GL11.GL_FALSE
|
||||
import org.lwjgl.system.MemoryUtil
|
||||
|
||||
object ShaderUtil {
|
||||
fun createShader(shaderPath: String, shaderType: Int): Int {
|
||||
fun createShader(assetsManager: AssetsManager = Minosoft.MINOSOFT_ASSETS_MANAGER, resourceLocation: ResourceLocation, shaderType: Int): Int {
|
||||
val shaderId = glCreateShaderObjectARB(shaderType)
|
||||
if (shaderId.toLong() == MemoryUtil.NULL) {
|
||||
throw ShaderLoadingException()
|
||||
}
|
||||
|
||||
glShaderSourceARB(shaderId, Util.readAssetResource("rendering/shader/$shaderPath"))
|
||||
glShaderSourceARB(shaderId, assetsManager.readStringAsset(resourceLocation))
|
||||
glCompileShaderARB(shaderId)
|
||||
|
||||
if (glGetObjectParameteriARB(shaderId, GL_OBJECT_COMPILE_STATUS_ARB) == GL_FALSE) {
|
||||
|
@ -68,7 +68,7 @@ class Texture(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getResourceTextureIdentifier(namespace: String = ProtocolDefinition.DEFAULT_MOD, textureName: String): ResourceLocation {
|
||||
fun getResourceTextureIdentifier(namespace: String = ProtocolDefinition.DEFAULT_NAMESPACE, textureName: String): ResourceLocation {
|
||||
var texturePath = textureName
|
||||
texturePath = texturePath.removePrefix("/")
|
||||
|
||||
|
@ -42,7 +42,8 @@ public final class ProtocolDefinition {
|
||||
public static final InetAddress LAN_SERVER_BROADCAST_INET_ADDRESS;
|
||||
public static final int LAN_SERVER_MAXIMUM_SERVERS = 100; // maximum number of lan servers, set because otherwise dos attacks would be easy
|
||||
|
||||
public static final String DEFAULT_MOD = "minecraft";
|
||||
public static final String DEFAULT_NAMESPACE = "minecraft";
|
||||
public static final String MINOSOFT_NAMESPACE = "minosoft";
|
||||
public static final char TEXT_COMPONENT_SPECIAL_PREFIX_CHAR = '§';
|
||||
|
||||
public static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||
|
@ -13,6 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.util
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import java.text.DateFormat
|
||||
@ -68,7 +71,7 @@ object GitInfo {
|
||||
fun load() {
|
||||
try {
|
||||
val dateFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
|
||||
val json = Util.readJsonAssetResource("git.json")
|
||||
val json = Minosoft.MINOSOFT_ASSETS_MANAGER.readJsonAsset(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "git.json"))
|
||||
GIT_BRANCH = json["git.branch"].asString
|
||||
GIT_BUILD_HOST_BRANCH = json["git.build.host"].asString
|
||||
GIT_BUILD_TIME = dateFormat.parse(json["git.build.time"].asString).time
|
||||
|
@ -23,8 +23,6 @@ import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
import de.bixilon.minosoft.util.microsoft.MicrosoftOAuthUtils;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
@ -172,23 +170,6 @@ public final class Util {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String sha1(String string) {
|
||||
return sha1(string.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static HashMap<String, String> readTarGzFile(String fileName) throws IOException {
|
||||
File inputFile = new File(fileName);
|
||||
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(inputFile)));
|
||||
HashMap<String, String> ret = new HashMap<>();
|
||||
TarArchiveEntry entry;
|
||||
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
||||
ret.put(entry.getName(), readReader(new BufferedReader(new InputStreamReader(tarArchiveInputStream)), false));
|
||||
}
|
||||
tarArchiveInputStream.close();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String readReader(BufferedReader reader, boolean closeStream) throws IOException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String line;
|
||||
@ -203,33 +184,6 @@ public final class Util {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static HashMap<String, JsonObject> readJsonTarStream(InputStream inputStream) throws IOException {
|
||||
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(inputStream);
|
||||
HashMap<String, JsonObject> ret = new HashMap<>();
|
||||
TarArchiveEntry entry;
|
||||
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
||||
ret.put(entry.getName(), JsonParser.parseReader(new InputStreamReader(tarArchiveInputStream)).getAsJsonObject());
|
||||
}
|
||||
tarArchiveInputStream.close();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static JsonObject readJsonAssetResource(String path) throws IOException {
|
||||
return readJsonAssetResource(path, Util.class);
|
||||
}
|
||||
|
||||
public static JsonObject readJsonAssetResource(String path, Class<?> clazz) throws IOException {
|
||||
InputStreamReader reader = readAssetResource(path, clazz);
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
reader.close();
|
||||
return json;
|
||||
}
|
||||
|
||||
public static InputStreamReader readAssetResource(String path, Class<?> clazz) {
|
||||
return new InputStreamReader(clazz.getResourceAsStream("/assets/" + path));
|
||||
}
|
||||
|
||||
public static JsonObject readJsonFromZip(String fileName, ZipFile zipFile) throws IOException {
|
||||
InputStreamReader reader = getInputSteamFromZip(fileName, zipFile);
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
@ -241,13 +195,6 @@ public final class Util {
|
||||
return new InputStreamReader(zipFile.getInputStream(zipFile.getEntry(fileName)));
|
||||
}
|
||||
|
||||
public static JsonObject readJsonFromFile(String fileName) throws IOException {
|
||||
FileReader reader = new FileReader(fileName);
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
reader.close();
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String readFile(String fileName) throws IOException {
|
||||
FileReader reader = new FileReader(fileName);
|
||||
return readReader(new BufferedReader(reader), true);
|
||||
@ -275,7 +222,6 @@ public final class Util {
|
||||
|
||||
public static InputStream getInputStreamByURL(String url) throws IOException {
|
||||
return new URL(url).openConnection().getInputStream();
|
||||
// return new BufferedInputStream(new URL(url).openStream());
|
||||
}
|
||||
|
||||
public static ThreadFactory getThreadFactory(String threadName) {
|
||||
@ -311,10 +257,6 @@ public final class Util {
|
||||
return result.substring(0, result.indexOf(second));
|
||||
}
|
||||
|
||||
public static String readAssetResource(String path) throws IOException {
|
||||
return readReader(new BufferedReader(readAssetResource(path, Util.class)), true);
|
||||
}
|
||||
|
||||
public static boolean doesStringContainsUppercaseLetters(String string) {
|
||||
return !string.toLowerCase().equals(string);
|
||||
}
|
||||
|
@ -1,9 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.MenuButton?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<!--
|
||||
~ Minosoft
|
||||
~ Copyright (C) 2020 Moritz Zwerger
|
||||
@ -16,6 +11,11 @@
|
||||
~
|
||||
~ This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
-->
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.MenuButton?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<AnchorPane xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:id="root" maxHeight="-Infinity" maxWidth="500.0" minHeight="-Infinity" minWidth="500.0" prefWidth="500.0" fx:controller="de.bixilon.minosoft.gui.main.SessionListCell">
|
||||
<Label fx:id="connectionId" layoutX="111.0" layoutY="14.0" maxWidth="200.0" minWidth="10.0" text="#1" underline="true" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0">
|
||||
<font>
|
@ -1,9 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.control.Menu?>
|
||||
<?import javafx.scene.control.MenuBar?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<!--
|
||||
~ Minosoft
|
||||
~ Copyright (C) 2020 Moritz Zwerger
|
||||
@ -16,6 +11,11 @@
|
||||
~
|
||||
~ This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
-->
|
||||
<?import javafx.scene.control.Menu?>
|
||||
<?import javafx.scene.control.MenuBar?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<VBox xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" prefHeight="400.0" prefWidth="640.0" fx:controller="de.bixilon.minosoft.gui.main.SessionsWindow">
|
||||
<MenuBar VBox.vgrow="NEVER">
|
||||
<Menu fx:id="menuDisconnect" mnemonicParsing="false" text="-_Disconnect-">
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Loading…
x
Reference in New Issue
Block a user