Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Fix fresh game or save initialization issue (#107)
Browse files Browse the repository at this point in the history
- Correctly initialize Stelnet on a fresh game or save. Stelnet would fail to initialize when starting a New Game or Loading a Game from Main Menu.
  • Loading branch information
jaghaimo authored Jun 8, 2023
1 parent 649e67c commit 69ba8aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion assets/mod_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Stellar Networks",
"author": "Jaghaimo",
"utility": true,
"version": "3.1.0",
"version": "3.1.1",
"description": "A collection of intel boards for Starsector",
"gameVersion": "0.96a-RC10",
"modPlugin": "stelnet.StelnetMod",
Expand Down
6 changes: 3 additions & 3 deletions assets/stelnet.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"modVersion": {
"major": 3,
"minor": 1,
"patch": 0
"patch": 1
},
"directDownloadURL": "https://github.com/jaghaimo/stelnet/releases/download/3.1.0/stelnet-3.1.0.zip",
"changelogURL": "https://raw.githubusercontent.com/jaghaimo/stelnet/3.1.0/changelog.txt"
"directDownloadURL": "https://github.com/jaghaimo/stelnet/releases/download/3.1.1/stelnet-3.1.1.zip",
"changelogURL": "https://raw.githubusercontent.com/jaghaimo/stelnet/3.1.1/changelog.txt"
}
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 3.1.1 (2023.06.08)
- Correctly initialize Stelnet on a fresh game or save. Stelnet would fail to initialize when starting a New Game or Loading a Game from Main Menu.


Version 3.1.0 (2023.06.08)
New features:
- Move setting handling from `stelnet.json` file to LunaLib. Requires LunaLib.
Expand Down
31 changes: 17 additions & 14 deletions src/stelnet/SettingsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ public static void register() {
LunaSettings.addSettingsListener(new SettingsListener());
}

@Override
public void settingsChanged(String modId) {
if (!ModConstants.STELNET_ID.equals(modId)) {
return;
}
if (Global.getCurrentState().equals(GameState.TITLE)) {
return;
}
public static void apply() {
resetCache();
initCommodity(Modules.COMMODITIES.has());
initContacts(Modules.CONTACTS.has());
Expand All @@ -70,14 +63,24 @@ public static void resetCache() {
ShipQueryProvider.resetCache();
}

private void purgeIntel(Class<?>... classNames) {
@Override
public void settingsChanged(String modId) {
if (!ModConstants.STELNET_ID.equals(modId)) {
return;
}
if (Global.getCurrentState().equals(GameState.CAMPAIGN)) {
apply();
}
}

private static void purgeIntel(Class<?>... classNames) {
for (Class<?> className : classNames) {
log.debug("Removing intel " + className);
StelnetHelper.removeIntel(className);
}
}

private void initContacts(boolean hasContacts) {
private static void initContacts(boolean hasContacts) {
if (hasContacts) {
StelnetHelper.getInstance(ContactsBoard.class);
SebestyenContactMaker.register();
Expand All @@ -88,7 +91,7 @@ private void initContacts(boolean hasContacts) {
}
}

private void initCommodity(boolean hasCommodities) {
private static void initCommodity(boolean hasCommodities) {
if (hasCommodities) {
StelnetHelper.getInstance(CommodityBoard.class).restore();
// TradeBoard.getInstance(TradeBoard.class);
Expand All @@ -102,7 +105,7 @@ private void initCommodity(boolean hasCommodities) {
}
}

private void initExploration(boolean hasExploration) {
private static void initExploration(boolean hasExploration) {
if (hasExploration) {
StelnetHelper.getInstance(ExplorationBoard.class);
log.info("Enabled Exploration module");
Expand All @@ -112,7 +115,7 @@ private void initExploration(boolean hasExploration) {
}
}

private void initMarket(boolean hasMarket) {
private static void initMarket(boolean hasMarket) {
if (hasMarket) {
StelnetHelper.getInstance(QueryBoard.class);
StelnetHelper.getInstance(ViewerBoard.class);
Expand All @@ -128,7 +131,7 @@ private void initMarket(boolean hasMarket) {
}
}

private void initStorage(boolean hasStorage) {
private static void initStorage(boolean hasStorage) {
if (hasStorage) {
StelnetHelper.getInstance(StorageBoard.class);
log.info("Enabled Storage module");
Expand Down
2 changes: 1 addition & 1 deletion src/stelnet/StelnetMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onApplicationLoad() throws Exception {

@Override
public void onGameLoad(boolean newGame) {
LunaSettings.reportSettingsChanged(ModConstants.STELNET_ID);
SettingsListener.apply();
}

@Override
Expand Down

0 comments on commit 69ba8aa

Please sign in to comment.