Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/LMH01/MGT2_Mod_Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
LMH01 committed Feb 13, 2022
2 parents fca45f8 + 0391cac commit 2d488de
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 51 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To update the initial backup go to `Backup -> Create backup -> Create new initia
#### WHEN THE GAME IS UPDATED IT MIGHT BE POSSIBLE THAT YOUR MODIFICATIONS TO THE GAME FILES ARE LOST

#### TO COUNTERACT THIS YOU CAN CREATE A MOD RESTORE POINT IN THE BACKUP MENU
## Download: [v3.0.2](https://github.com/LMH01/MGT2_Mod_Tool/releases/download/v3.0.2/MGT2_Mod_Tool_3.0.2.zip)
## Download: [v3.0.3](https://github.com/LMH01/MGT2_Mod_Tool/releases/download/v3.0.3/MGT2_Mod_Tool_3.0.3.zip)
#### Getting started:
- Install Java 8 (if not already installed)
- Download and extract the `.zip` file
Expand Down Expand Up @@ -83,7 +83,7 @@ To update the initial backup go to `Backup -> Create backup -> Create new initia
- Backups of your saved games will be created but not automatically restored. To restore a save game backup go into the **Backup** menu, click **Restore Backup** and then **Restore Save Game Backup**.
- **Create a mod restore point**: When a restore point is set you will be able to restore all your currently installed mods later.<br>Useful when the game has been updated and the mods are lost.
- **Even though backups are created I will not take any responsibility if you loose or damage you saved games!**
### Uitilities
### Utilities
- **Update Checker**
- When started the tool will look for updates. If an update is available the user will be notified.
- **Tool tips**
Expand Down Expand Up @@ -156,4 +156,4 @@ To update the initial backup go to `Backup -> Create backup -> Create new initia
![img](https://i.imgur.com/RvDoupc.png "The import window")

#### This is what the mods menu looks like
![img](https://i.imgur.com/fSs3Fn5.png "The mods window")
![img](https://i.imgur.com/fSs3Fn5.png "The mods window")
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {

sourceCompatibility = 1.8
targetCompatibility = 1.8
project.version = "3.0.2" //remember to change version in main class
project.version = "3.0.3" //remember to change version in main class
archivesBaseName = "MGT2_Mod_Tool"

group = "com.github.lmh01"
Expand Down
16 changes: 15 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog
## [v3.0.2](https://github.com/LMH01/MGT2_Mod_Tool/releases/tag/v3.0.1) (Latest Version)

## [v3.0.3](https://github.com/LMH01/MGT2_Mod_Tool/releases/tag/v3.0.3) (Latest Version)
### Other
- Added button to utilities menu with which the settings.toml file can be opened
- Updated default content files
- It is now checked if the initial backup is up-to-date when the tool is started
- This feature can be disabled in the settings.toml file

### Bug fixes
- Button `Restore mod restore point` is no longer disabled when the safety feature are off
- Import no longer fails when gameplay features are imported that are missing bad / good genres
- Theme export no longer replaces genre names falsely
- Program will no longer fail to load when the settings.toml file does not contain valid toml

## [v3.0.2](https://github.com/LMH01/MGT2_Mod_Tool/releases/tag/v3.0.2)
### Other
- Import
- When an image file already exists it is now replaced and the import of the mod is not canceled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public class MadGamesTycoon2ModTool {
public static final OSType OS_TYPE;
private static final Logger LOGGER = LoggerFactory.getLogger(MadGamesTycoon2ModTool.class);
public static final String VERSION = "3.0.2";//Version numbers that include "dev" are not checked for updates / tool will notify if update is available
public static final String CURRENT_RELEASE_VERSION = "3.0.2";//When this version number has been detected as the newest release version the update available message is held back
public static final String VERSION = "3.0.3";//Version numbers that include "dev" are not checked for updates / tool will notify if update is available
public static final String CURRENT_RELEASE_VERSION = "3.0.3";//When this version number has been detected as the newest release version the update available message is held back

static {
if (System.getProperty("os.name").contains("Linux")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.lmh01.mgt2mt.data_stream;

import com.github.lmh01.mgt2mt.util.ModManagerPaths;
import com.github.lmh01.mgt2mt.util.Settings;
import com.github.lmh01.mgt2mt.util.UpdateBranch;
import com.moandjiezana.toml.Toml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ImportSettings {
Expand Down Expand Up @@ -36,8 +38,8 @@ public static boolean Import(File file) {
Settings.enableExportStorage = toml.getBoolean("enableExportStorage");
Settings.enableInitialBackupCheck = toml.getBoolean("enableInitialBackupCheck");
return true;
} catch (IllegalStateException | NullPointerException e) {
LOGGER.info("Unable to import settings!");
} catch (RuntimeException e) {
LOGGER.info("Unable to import settings!:");
e.printStackTrace();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected Charset getCharset() {

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down Expand Up @@ -372,9 +372,12 @@ public <T> Map<String, Object> getDependencyMap(T t) throws ModProcessingExcepti

@Override
public Map<String, String> getChangedImportMap(Map<String, String> map) throws ModProcessingException, NullPointerException, NumberFormatException {
map.replace("GOOD", getGenreIds(map.get("GOOD")));
map.replace("BAD", getGenreIds(map.get("BAD")));
map.put("PIC", "");
if (map.containsKey("GOOD")) {
map.replace("GOOD", getGenreIds(map.get("GOOD")));
}
if (map.containsKey("BAD")) {
map.replace("BAD", getGenreIds(map.get("BAD")));
}
return map;
}

Expand Down Expand Up @@ -489,6 +492,8 @@ private void editGenreIdAllocation(Set<Integer> gameplayFeaturesIdsToEdit, int g
}

/**
* This function uses {@link AbstractAdvancedMod#getModIdByNameFromImportHelperMap(String)} so the import map
* has to be initialized when thin function is called. This means that the genre ids will be set correctly.
* @param genreNamesRaw The string containing the genre ids that should be transformed.
* @return A list of genre names
* @throws ModProcessingException If import helper throws an exception
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/mod/GenreMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/mod/HardwareMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/mod/LicenceMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class LicenceMod extends AbstractSimpleMod {

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/mod/NpcGamesMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NpcGamesMod extends AbstractSimpleDependentMod {

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/mod/PlatformMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void printValues(Map<String, String> map, BufferedWriter bw) throws IO

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/github/lmh01/mgt2mt/mod/ThemeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ThemeMod extends AbstractSimpleDependentMod {

@Override
public String[] getCompatibleModToolVersions() {
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", MadGamesTycoon2ModTool.VERSION};
return new String[]{"3.0.0-alpha-1", "3.0.0", "3.0.1", "3.0.2", "3.0.3", MadGamesTycoon2ModTool.VERSION};
}

@Override
Expand Down Expand Up @@ -231,7 +231,7 @@ public <T> void addModToFile(T t) throws ModProcessingException {
@SuppressWarnings("unchecked")
public Map<String, Object> getExportMap(String name) throws ModProcessingException {
Map<String, Object> map = new HashMap<>();
String line = getModifiedExportLine(getLine(name)).replace(name, getThemeTranslations(name).get("NAME GE"));
String line = getModifiedExportLine(getLine(name));
Map<String, Object> dependencyMap = getDependencyMap(line);
for (AbstractBaseMod mod : ModManager.mods) {
try {
Expand All @@ -255,7 +255,7 @@ public Map<String, Object> getExportMap(String name) throws ModProcessingExcepti
public String getModifiedExportLine(String exportLine) throws ModProcessingException {
ArrayList<String> strings = Utils.getEntriesFromString(exportLine);
StringBuilder output = new StringBuilder();
output.append(getReplacedLine(exportLine)).append(" ");
output.append(getThemeTranslation(getReplacedLine(exportLine), "GE")).append(" ");
for (String string : strings) {
output.append("<");
try {
Expand Down Expand Up @@ -526,16 +526,28 @@ public int getPositionOfThemeInFile(String themeNameEn) throws ModProcessingExce
*/
public boolean doesThemeExist(String name) throws ModProcessingException {
ArrayList<String> arrayList = new ArrayList<>(Arrays.asList(getContentByAlphabet()));
if (arrayList.contains(name)) {
return true;
} else {
return false;
return arrayList.contains(name);
}

/**
* Translates the theme name.
* @param nameEn The theme name that should be translated
* @param translationKey The translation key for the translation
* @return The german translation for the english theme name.
*/
public String getThemeTranslation(String nameEn, String translationKey) throws ModProcessingException {
String translation = getThemeTranslations(nameEn).get("NAME " + translationKey);
if (translation.equals("null")) {
throw new ModProcessingException("Unable to return translation for theme " + nameEn + ": Translation key " + translation + " is invalid.");
}
return translation;
}

/**
* @param name The english theme name for which the translations should be returned
* @return A map that contains all translations for the theme
* @throws ModProcessingException If theme translation could not be returned.
* If file translation file charset can not be determined.
*/
public Map<String, String> getThemeTranslations(String name) throws ModProcessingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,18 @@ public <T> Map<String, String> transformGenericToMap(T t) throws ModProcessingEx
}

/**
* Use this function to simply transform the map entry from the mod name to the mod id.
* This function uses {@link AbstractBaseMod#getModIdByNameFromImportHelperMap(String)} to retrieve the mod id.
* If the entry is not found a warning message is printed into the text area
* Use this function to replace the value behind the key with the id specific for that mod-name.
* If the key does not exist or the id is not found a warning message is printed into the text area
* and a random replacement id will be chosen.
* Does only work if the value is a single name for which an id has been set.
* Example replacement: Horror -> 18
*
* @param map The map that contains the value that should be replaced
* @param mapKey The map key for which the value should be replaced
* @param mod The mod for which the name should be replaced with the id
*/
* @see AbstractBaseMod#getModIdByNameFromImportHelperMap(String) Function that is used to get the id by the name
* @see AbstractBaseMod#addEntryToImportHelperMap(String) Function that adds an entry to the import helper map
* */
protected void replaceImportMapEntry(Map<String, String> map, String mapKey, AbstractBaseMod mod) {
try {
map.replace(mapKey, Integer.toString(mod.getModIdByNameFromImportHelperMap(map.get(mapKey))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ public class InitialBackupChecker {
public static boolean checkIfUpToDate() throws IOException {
if (Files.exists(initialBackupVersion)) {
Toml toml = new Toml().read(initialBackupVersion.toFile());
if (toml.getLong("initialBackupVersion") < (long) getLastUpdatedInt()) {
return false;
}
return toml.getLong("initialBackupVersion") == (long) getLastUpdatedInt();
} else {
setInitialBackupVersion(getLastUpdatedInt());
return true;
}
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/lmh01/mgt2mt/util/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class Settings {
public static boolean enableGenreNameTranslationInfo = true;
public static boolean enableGenreDescriptionTranslationInfo = true;
public static boolean enableExportStorage = true; //If true each new export will be saved in a new folder.
public static boolean enableInitialBackupCheck = false; //If true the user will be notified if the initial backup is outdated
public static boolean enableInitialBackupCheck = true; //If true the user will be notified if the initial backup is outdated
public static String language = "English";
public static UpdateBranch updateBranch = UpdateBranch.RELEASE;

public static void resetSettings() {
setMGT2Folder(false);
setSettings(false, true, false, false, mgt2Path, true, true, true, "English", UpdateBranch.RELEASE, true, false);
setSettings(false, true, false, false, mgt2Path, true, true, true, "English", UpdateBranch.RELEASE, true, true);
LOGGER.info("Settings have been reset.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/lmh01/mgt2mt/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static boolean checkForMutualEntries(ArrayList<?> arrayList1, ArrayList<?
}

/**
* Opens the given folder
* Opens the given folder/file
*/
public static void open(Path path) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DefaultContentManager {
* This is the version in which the default content files are initially saved.
* It indicates to what game update the default files correspond that ship with this tool.
*/
private static final String DEFAULT_CONTENT_VERSION = "BUILD 2021.09.09A";
private static final String DEFAULT_CONTENT_VERSION = "BUILD 2021.10.11B";
private static final String NEWEST_DEFAULT_CONTENT_VERSION_DOWNLOAD_URL = "https://www.dropbox.com/s/hd7f7c2b9ybr5gt/newest_default_content_version.txt?dl=1";
private static final String NEWEST_DEFAULT_CONTENT_DOWNLOAD_URL = "https://www.dropbox.com/s/7l89pg9x4venqje/newest_default_content.toml?dl=1";
public static final File DEFAULT_CONTENT_FILE = ModManagerPaths.MAIN.getPath().resolve("default_content.toml").toFile();
Expand Down
Loading

0 comments on commit 2d488de

Please sign in to comment.