Skip to content

Commit

Permalink
ModStore should be operational
Browse files Browse the repository at this point in the history
  • Loading branch information
zpiddock committed Sep 3, 2020
1 parent bb07628 commit e280015
Show file tree
Hide file tree
Showing 20 changed files with 364 additions and 246 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ res/
bintray.properties
/module/
run/
src/test/
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repositories {

dependencies {

implementation 'me.shadowchild.cybernize:cybernize:1.1.1'
implementation 'uk.co.innoxium.cybernize:cybernize:1.1.3'
implementation 'com.electronwill.night-config:toml:3.6.3'
implementation 'com.miglayout:miglayout:3.7.4'
implementation 'com.google.code.gson:gson:2.8.6'
Expand All @@ -55,6 +55,8 @@ dependencies {
implementation "commons-io:commons-io:2.7"
implementation "org.apache.commons:commons-math3:3.6.1"

implementation "net.harawata:appdirs:1.2.0"

// Flat LAF
implementation 'com.formdev:flatlaf:0.38'

Expand Down Expand Up @@ -176,7 +178,7 @@ publishing {
artifact javadocJar
groupId 'uk.co.innoxium.candor'
artifactId 'candor-full'
version '0.1.4'
version '0.1.5'
}
}
}
Expand All @@ -202,7 +204,7 @@ bintray {
licenses = ['MIT']
version {

name = '0.1.4'
name = '0.1.5'
desc = ' Initial Test Release For Candor'
released = new Date()
}
Expand Down
8 changes: 4 additions & 4 deletions genericmodule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ dependencies {

// implementation project(":core")

implementation 'me.shadowchild.candor:candor-full:0.1.4'
implementation 'uk.co.innoxium.candor:candor-full:0.1.5'

implementation 'me.shadowchild.cybernize:cybernize:1.1.1'
implementation 'uk.co.innoxium.cybernize:cybernize:1.1.3'
implementation 'com.electronwill.night-config:toml:3.6.3'

implementation 'com.google.code.gson:gson:2.8.6'
Expand Down Expand Up @@ -92,7 +92,7 @@ publishing {
artifact javadocJar
groupId 'uk.co.innoxium.candor'
artifactId 'candor-genericmodule'
version '0.1.4'
version '0.1.5'
}
}
}
Expand All @@ -118,7 +118,7 @@ bintray {
licenses = ['MIT']
version {

name = '0.1.4'
name = '0.1.5'
desc = ' Initial Test Release For Candor'
released = new Date()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package uk.co.innoxium.candor.generic;

import me.shadowchild.candor.Settings;
import me.shadowchild.candor.mod.Mod;
import me.shadowchild.candor.module.AbstractModInstaller;
import me.shadowchild.candor.module.AbstractModule;
import me.shadowchild.cybernize.archive.Archive;
import me.shadowchild.cybernize.archive.ArchiveBuilder;
import org.apache.commons.io.FileUtils;
import uk.co.innoxium.candor.Settings;
import uk.co.innoxium.candor.mod.Mod;
import uk.co.innoxium.candor.module.AbstractModInstaller;
import uk.co.innoxium.candor.module.AbstractModule;
import uk.co.innoxium.cybernize.archive.Archive;
import uk.co.innoxium.cybernize.archive.ArchiveBuilder;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package uk.co.innoxium.candor.generic;

import me.shadowchild.candor.Settings;
import me.shadowchild.candor.module.AbstractModInstaller;
import me.shadowchild.candor.module.AbstractModule;
import me.shadowchild.candor.module.RunConfig;
import uk.co.innoxium.candor.Settings;
import uk.co.innoxium.candor.module.AbstractModInstaller;
import uk.co.innoxium.candor.module.AbstractModule;
import uk.co.innoxium.candor.module.RunConfig;

import java.io.File;

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/uk/co/innoxium/candor/CandorLauncher.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package uk.co.innoxium.candor;

import com.formdev.flatlaf.FlatDarculaLaf;
import org.lwjgl.system.Platform;
import uk.co.innoxium.candor.mod.store.ModStore;
import uk.co.innoxium.candor.module.AbstractModule;
import uk.co.innoxium.candor.module.ModuleSelector;
import me.shadowchild.cybernize.util.ClassLoadUtil;
import org.lwjgl.system.Platform;
import uk.co.innoxium.candor.util.Dialogs;
import uk.co.innoxium.candor.util.Resources;
import uk.co.innoxium.candor.window.GameSelectScene;
import uk.co.innoxium.candor.window.ModScene;
import uk.co.innoxium.cybernize.util.ClassLoadUtil;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -66,6 +67,7 @@ public static void main(String[] args) {
AbstractModule module = ModuleSelector.getModuleForGame(game);
module.setGame(game);
module.setModsFolder(new File(Settings.modsFolder));
ModStore.initialise();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/uk/co/innoxium/candor/ConfigHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package uk.co.innoxium.candor;

import me.shadowchild.cybernize.setting.SettingsHandler;

import java.io.File;
import uk.co.innoxium.candor.util.Resources;
import uk.co.innoxium.cybernize.setting.SettingsHandler;

public class ConfigHandler {

private static File configFolder = new File("./config");

public static void handleCore() {

SettingsHandler.CONFIG_DIR = Resources.CONFIG_PATH;
SettingsHandler.addHolder(Settings.class);
try {

Expand All @@ -18,7 +17,5 @@ public static void handleCore() {

e.printStackTrace();
}
// CoreSettings.init();
// coreConfig.loadConfig(configFolder);
}
}
9 changes: 5 additions & 4 deletions src/main/java/uk/co/innoxium/candor/Settings.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package uk.co.innoxium.candor;

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import me.shadowchild.cybernize.setting.Config;
import me.shadowchild.cybernize.setting.Setting;
import me.shadowchild.cybernize.setting.SettingsHolder;
import uk.co.innoxium.candor.util.Resources;
import uk.co.innoxium.cybernize.setting.Config;
import uk.co.innoxium.cybernize.setting.Setting;
import uk.co.innoxium.cybernize.setting.SettingsHolder;

import java.io.File;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class Settings {
public static CommentedFileConfig getConfig() {

return CommentedFileConfig
.builder(new File("./config", "core.toml"))
.builder(new File(Resources.CONFIG_PATH, "core.toml"))
.autosave()
.autoreload()
.charset(StandardCharsets.UTF_8)
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/uk/co/innoxium/candor/mod/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import uk.co.innoxium.candor.util.Utils;
import me.shadowchild.cybernize.archive.Archive;
import me.shadowchild.cybernize.archive.ArchiveBuilder;
import uk.co.innoxium.cybernize.archive.Archive;
import uk.co.innoxium.cybernize.archive.ArchiveBuilder;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -62,7 +62,7 @@ public JsonArray getAssociatedFiles() {
return associatedFiles;
}

public static Mod of(File file) {
public static Mod fromFile(File file) {

String name = file.getName().substring(0, file.getName().lastIndexOf("."));
State state = State.DISABLED;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Mod of(File file) {
return new Mod(file, name, state, name, array);
}

public static Mod of(JsonObject obj) {
public static Mod fromJson(JsonObject obj) {

File file = new File(obj.get("file").getAsString());
String name = obj.get("name").getAsString();
Expand All @@ -103,7 +103,7 @@ public static Mod of(JsonObject obj) {
return new Mod(file, name, state, readableName, array);
}

public static JsonObject from(Mod mod) throws IOException {
public static JsonObject toJson(Mod mod) throws IOException {

JsonObject obj = new JsonObject();
obj.addProperty("file", mod.getFile().getCanonicalPath());
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/uk/co/innoxium/candor/mod/ModList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package uk.co.innoxium.candor.mod;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;

public class ModList<Mod> {

private ArrayList<Mod> MODS_LIST = Lists.newArrayList();
private ArrayList<ListChangeListener> listeners = Lists.newArrayList();

public boolean add(Mod mod) {

boolean result = MODS_LIST.add(mod);

fireChangeToListeners("add", mod, result);

return result;
}

public boolean remove(Mod mod) {

boolean result = MODS_LIST.remove(mod);

fireChangeToListeners("remove", mod, result);

return result;
}

public boolean addAll(Collection<? extends Mod> c) {

boolean result = MODS_LIST.addAll(c);

fireChangeToListeners("add-all", c, result);

return result;
}

public void fireChangeToListeners(String identifier, Mod mod, boolean result) {

listeners.forEach(listener -> listener.handleChange(identifier, mod, result));
}

public void fireChangeToListeners(String identifier, Collection<? extends Mod> c, boolean result) {

listeners.forEach(listener -> listener.handleChange(identifier, c, result));
}

public Mod[] toArray() {

return (Mod[]) MODS_LIST.toArray();
}

public void addListener(ListChangeListener<Mod> listener) {

if(!listeners.contains(listener)) listeners.add(listener);
}

public void forEach(Consumer action) {

MODS_LIST.forEach(action);
}

public void clear() {

MODS_LIST.clear();
}

public interface ListChangeListener<T> {

void handleChange(String identifier, T mod, boolean result);
void handleChange(String identifier, Collection<? extends T> c, boolean result);
}
}
6 changes: 4 additions & 2 deletions src/main/java/uk/co/innoxium/candor/mod/ModUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.co.innoxium.candor.mod;

import uk.co.innoxium.candor.mod.store.ModStore;

import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -9,9 +11,9 @@ public static boolean checkAlreadyInstalled(File mod) {

AtomicBoolean ret = new AtomicBoolean(false);

ModsHandler.MODS.forEach(o -> {
ModStore.MODS.forEach(o -> {

if(Mod.of(mod).equals(o)) {
if(Mod.fromFile(mod).equals(o)) {

ret.set(true);
}
Expand Down
72 changes: 1 addition & 71 deletions src/main/java/uk/co/innoxium/candor/mod/ModsHandler.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,6 @@
package uk.co.innoxium.candor.mod;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;

public class ModsHandler {

public static final ModList MODS = new ModList<Mod>();

public static class ModList<Mod> {

private ArrayList<Mod> MODS_LIST = Lists.newArrayList();
private ArrayList<ListChangeListener> listeners = Lists.newArrayList();

public boolean add(Mod mod) {

boolean result = MODS_LIST.add(mod);

fireChangeToListeners("add", mod, result);

return result;
}

public boolean remove(Mod mod) {

boolean result = MODS_LIST.remove(mod);

fireChangeToListeners("remove", mod, result);

return result;
}

public boolean addAll(Collection<? extends Mod> c) {

boolean result = MODS_LIST.addAll(c);

fireChangeToListeners("add-all", c, result);

return result;
}

public void fireChangeToListeners(String identifier, Mod mod, boolean result) {

listeners.forEach(listener -> listener.handleChange(identifier, mod, result));
}

public void fireChangeToListeners(String identifier, Collection<? extends Mod> c, boolean result) {

listeners.forEach(listener -> listener.handleChange(identifier, c, result));
}

public Mod[] toArray() {

return (Mod[]) MODS_LIST.toArray();
}

public void addListener(ListChangeListener<Mod> listener) {

if(!listeners.contains(listener)) listeners.add(listener);
}

public void forEach(Consumer action) {

MODS_LIST.forEach(action);
}
}

public interface ListChangeListener<T> {

void handleChange(String identifier, T mod, boolean result);
void handleChange(String identifier, Collection<? extends T> c, boolean result);
}
// public static final ModList MODS = new ModList<Mod>();
}
Loading

0 comments on commit e280015

Please sign in to comment.