Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Game Profile Metadata Configuration file for mutable global configurations #11

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4ef2fa8
Add game_profile.conf and Gradle settings
BenCheung0422 Jan 9, 2024
50dd972
Make Game read game_profile.conf
BenCheung0422 Jan 9, 2024
0a221ab
Merge branch 'devbackup' into loadrewrite
BenCheung0422 Jan 21, 2024
7849996
Separate HistoricLoad from LegacyLoad
BenCheung0422 Feb 1, 2024
06f14cf
Fix loading failure exception throws
BenCheung0422 Feb 1, 2024
6bf717f
Remove unmatched tailing comma check
BenCheung0422 Feb 7, 2024
84b7a0c
Resolve errors when loading old world
BenCheung0422 Feb 13, 2024
868b02d
HistoricLoad perform backups only fully loaded
BenCheung0422 Feb 13, 2024
d6cb57d
Add popup messages for each loading error
BenCheung0422 Feb 13, 2024
f0d7979
Removed extra line to backup KeyPrefs
BenCheung0422 Feb 13, 2024
d7b9965
Throw error for unknown entity
BenCheung0422 Feb 13, 2024
a974bc7
Load KeyPrefs only when exists
BenCheung0422 Feb 13, 2024
014aa06
Detailed error message in world load error popup
BenCheung0422 Feb 13, 2024
6b3df86
Use switch-case for item name in HistoricLoad
BenCheung0422 Feb 13, 2024
a70c7f5
Add handles for particle loading in HistoricLoad
BenCheung0422 Feb 13, 2024
f054eba
Complement Historic about bugs and data fixer
BenCheung0422 Feb 14, 2024
a92a8c1
Fix a word of grammar mistake
BenCheung0422 Feb 14, 2024
617f7f0
Merge branch 'main' into loadrewrite
Litorom Feb 15, 2024
0cb84e8
Update game_profile.conf and add GameVersion
BenCheung0422 May 2, 2024
f0538a0
Merge remote-tracking branch 'upstream/main' into devbuild
BenCheung0422 May 2, 2024
db23300
Update game_profile.conf
BenCheung0422 May 2, 2024
5d9985b
Merge remote-tracking branch 'upstream/main' into loadrewrite
BenCheung0422 May 2, 2024
a86902f
Merge branch 'loadrewrite' into devbuild
BenCheung0422 May 2, 2024
8df5a4b
Complement old version mappings to data versions
BenCheung0422 May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

plugins {
id 'application'
id 'maven-publish'
Expand All @@ -6,7 +12,15 @@ plugins {
allprojects {
apply plugin: "java"

version = "2.2.0"
Properties profile = new Properties()
profile.load(new FileInputStream(new File(rootDir, "game_profile.conf")))

ext.id = profile.getProperty("id")
ext.stable = Boolean.parseBoolean(profile.getProperty("stable"))
ext.branch = profile.getProperty("branch")
ext.packVersionResource = Integer.parseInt(profile.getProperty("pack_version_resource"))
ext.packVersionData = Integer.parseInt(profile.getProperty("pack_version_data"))
ext.worldVersion = Integer.parseInt(profile.getProperty("world_version"))

sourceCompatibility = 8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
Expand Down Expand Up @@ -42,6 +56,24 @@ project(":common") {
project(":client") {
archivesBaseName = "minicraft-plus"

File genDir = new File(project.buildDir, "tmp/generatedResources/")
genDir.mkdirs()
JsonBuilder json = new JsonBuilder()
json id: ext.id,
use_editor: false,
build_time: LocalDateTime.now().withNano(0).atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
stable: ext.stable,
branch: ext.branch,
world_version: ext.worldVersion,
pack_version: [ resource: ext.packVersionResource, data: ext.packVersionData ]
File metaFile = new File(genDir.toString(), "profile.meta.json")
metaFile.text = json.toString()
processResources {
from(genDir) {
include(metaFile.getName())
}
}

repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://jitpack.io" }
Expand Down Expand Up @@ -118,3 +150,12 @@ tasks.withType(Tar) {
tasks.withType(Zip) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

// Please configure this in editor run configuration manually for this to work.
// This should run before build
project(":client").tasks.register('configEditor') {
File metaFile = new File(project.buildDir, "tmp/generatedResources/profile.meta.json")
def obj = new JsonSlurper().parse(new File(project.buildDir, "tmp/generatedResources/profile.meta.json"))
obj.use_editor = true
metaFile.text = new JsonBuilder(obj).toString()
}
6 changes: 6 additions & 0 deletions game_profile.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id=2.3.0
stable=false
branch=main
pack_version_resource=1
pack_version_data=0
world_version=1000
37 changes: 33 additions & 4 deletions src/client/java/minicraft/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@
import minicraft.screen.TitleDisplay;
import minicraft.util.Logging;
import org.jetbrains.annotations.Nullable;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class Game {
protected Game() {
} // Can't instantiate the Game class.

public static final String NAME = "Minicraft Plus"; // This is the name on the application window.

public static final Version VERSION = new Version("2.2.0");
public static final GameVersion VERSION;

public static InputHandler input; // Input used in Game, Player, and just about all the *Menu classes.
public static Player player;
Expand Down Expand Up @@ -91,10 +101,29 @@ public static void quit() {
running = false;
}


public static void main(String[] args) {
static {
Thread.setDefaultUncaughtExceptionHandler(CrashHandler::crashHandle);

InputStream is = Game.class.getResourceAsStream("/profile.meta.json");
if (is == null)
throw new IllegalStateException("Malformed application setup");

JSONObject meta = new JSONObject(new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n")));
JSONObject packVersion = meta.getJSONObject("pack_version");

VERSION = new GameVersion(meta.getString("id"), meta.getInt("world_version"),
packVersion.getInt("resource"), packVersion.getInt("data"), meta.getBoolean("stable"),
meta.getBoolean("use_editor"), meta.getString("series_id"),
LocalDateTime.parse(meta.getString("build_time"), DateTimeFormatter.ISO_OFFSET_DATE_TIME));

try {
is.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static void main(String[] args) {
Initializer.parseArgs(args); // Parses the command line arguments
// Applying Game#debug first.

Expand Down
112 changes: 112 additions & 0 deletions src/client/java/minicraft/core/GameVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package minicraft.core;

import java.time.LocalDateTime;

public final class GameVersion {
public final String id;
public final int dataVersion;
public final int packResourceVersion, packDataVersion;
public final boolean stable;
public final boolean useEditor;
public final String seriesId;
public final LocalDateTime buildTime;

public GameVersion(String id, int dataVersion, int packResourceVersion, int packDataVersion, boolean stable,
boolean useEditor, String seriesId, LocalDateTime buildTime) {
this.id = id;
this.dataVersion = dataVersion;
this.packResourceVersion = packResourceVersion;
this.packDataVersion = packDataVersion;
this.stable = stable;
this.useEditor = useEditor;
this.seriesId = seriesId;
this.buildTime = buildTime;
}

public static int mapOldVersionToDataVersion(String version) { // This should be better than using a JSON file.
switch (version) {
// Versions are not saved in earlier versions, so they are ignored.
case "1.9.1": return 100;
case "1.9.2": return 101;
case "1.9.3-dev1": return 102;
case "1.9.3-dev2": return 103;
case "1.9.3": return 104;
case "1.9.4-dev1": return 105;
case "1.9.4-dev2": return 106;
case "1.9.4-dev3": return 107;
case "1.9.4-dev4": return 108;
case "1.9.4-dev5": return 109;
case "1.9.4-dev6": return 110;
case "1.9.4-dev7": return 111;
case "1.9.4": return 112;
case "2.0.0-dev1": return 113;
case "2.0.0-dev2": return 114;
case "2.0.0-dev3": return 115;
case "2.0.0": return 116;
case "2.0.1-dev1": return 117;
case "2.0.1-dev2": return 118;
case "2.0.1-dev3": return 119;
case "2.0.1-dev4": return 120;
case "2.0.1-dev5": return 121;
case "2.0.1-dev6": return 122;
case "2.0.1-dev7": return 123;
case "2.0.1-dev8": return 124;
case "2.0.1-dev9": return 125;
case "2.0.1": return 126;
case "2.0.2-dev1": return 127;
case "2.0.2-dev2": return 128;
case "2.0.2-dev3": return 129;
case "2.0.2": return 130;
case "2.0.3-dev1": return 131;
case "2.0.3-dev2": return 132;
case "2.0.3-dev3": return 133;
case "2.0.3-dev4": return 134;
case "2.0.3-dev5": return 135;
case "2.0.3-dev6": return 136;
case "2.0.3": return 137;
case "2.0.4-dev1": return 138;
case "2.0.4-dev2": return 139;
case "2.0.4-dev3": return 140;
case "2.0.4-dev4": return 141;
case "2.0.4-dev5": return 142;
case "2.0.4-dev6": return 143;
case "2.0.4-dev7": return 144;
case "2.0.4-dev8": return 145;
case "2.0.4-dev9": return 146;
case "2.0.4": return 147;
case "2.0.5-dev1": return 148;
case "2.0.5-dev2": return 149;
case "2.0.5-dev3": return 150;
case "2.0.5-dev4": return 151;
case "2.0.5-dev5": return 152;
case "2.0.5-dev6": return 153;
case "2.0.5": return 154;
case "2.0.6-dev1": return 155;
case "2.0.6-dev2": return 156;
case "2.0.6-dev3": return 157;
case "2.0.6-dev4": return 158;
case "2.0.6": return 159;
case "2.0.7-dev1": return 160;
case "2.0.7-dev2": return 161;
case "2.0.7-dev3": return 162;
case "2.0.7-dev4": return 163;
case "2.0.7": return 164;
case "2.1.0-dev1": return 165;
case "2.1.0-dev2": return 166;
case "2.1.0-dev3": return 167;
case "2.1.0": return 168;
case "2.1.1": return 169;
case "2.1.2": return 170;
case "2.1.3": return 171;
case "2.2.0-dev1": return 172;
case "2.2.0-dev2": return 173;
case "2.2.0-dev3": return 174;
case "2.2.0-dev4": return 175;
case "2.2.0-dev5": return 176;
case "2.2.0-dev6": return 177;
case "2.2.0-dev7": return 178;
case "2.2.0": return 179;
default: throw new AssertionError(String.format("Missing handle for version \"%s\"", version));
}
}
}
4 changes: 3 additions & 1 deletion src/client/java/minicraft/core/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public static void resetGame(boolean keepPlayer) {
* This method is used to create a brand new world, or to load an existing one from a file.
* For the loading screen updates to work, it it assumed that *this* is called by a thread *other* than the one rendering the current *menu*.
**/
public static void initWorld() { // This is a full reset; everything.
public static void initWorld()
throws Load.BackupCreationFailedException, Load.WorldLoadingFailedException,
Load.UserPromptCancelledException { // This is a full reset; everything.
Logging.WORLD.debug("Resetting world...");

PlayerDeathDisplay.shouldRespawn = false;
Expand Down
Loading