Skip to content

Commit 4db2f3e

Browse files
authored
feat: LunaLib integration, overlay options, and docs (#1)
- Add LunaLib/LazyLib dependency; settings via LunaSettings (Mod Settings F2) - Config: max factions, text size (Small/Medium/Large), overlay keybind (Toggle/Hold), hostile-only filter - FactionRelationshipsKeybindScript for overlay toggle/hold; fix EveryFrameScript import - Build: optional LUNALIB/LAZYLIB in compile.local.bat for versioned mod folders - Bump font sizes (Large uses ORBITRON_20AA, 24px line) - Update README, COMPILATION.md, compile.local.example.bat
1 parent 2049faf commit 4db2f3e

9 files changed

Lines changed: 273 additions & 38 deletions

File tree

FactionRelationships/COMPILATION.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
- **Mod ID**: `factionrelationships`
88
- **Game Version**: `0.98a-RC8`
99
- **Mod Plugin**: `com.factionrelationships.FactionRelationshipsPlugin`
10+
- **Dependencies**: LazyLib and LunaLib (required at runtime and for compilation).
1011

1112
## Prerequisites
1213

1314
1. **JDK 17** – Starsector 0.98a uses Java 17. Install JDK 17 and run `javac -version`.
1415
2. **Starsector** – JARs are taken from your game install (the folder that contains `starsector-core`).
16+
3. **LunaLib and LazyLib** – Install both mods in your Starsector `mods` folder. The compile script looks for `mods/LunaLib/jars/LunaLib.jar` and `mods/LazyLib/jars/LazyLib.jar` by default. If your mod folders use versioned names (e.g. `LunaLib-2.0.5`, `LazyLib-3.0.0`), set `LUNALIB` and `LAZYLIB` in `compile.local.bat` to point at those JARs (see Developer config below). Required for compilation and at runtime.
1517

1618
## Developer config (optional)
1719

1820
To avoid editing `compile.bat` and to keep your local paths out of the repo:
1921

2022
1. Copy `FactionRelationships/compile.local.example.bat` to `FactionRelationships/compile.local.bat`.
2123
2. Edit `compile.local.bat` and set `GAME_DIR` to your Starsector install directory.
24+
3. If LunaLib or LazyLib use versioned folder names (e.g. `LunaLib-2.0.5`), set `LUNALIB` and `LAZYLIB` to the full paths to their JARs so the build can find them.
2225

2326
`compile.local.bat` is gitignored; only the example file is committed. The main `compile.bat` loads it automatically when present.
2427

@@ -28,16 +31,20 @@ To avoid editing `compile.bat` and to keep your local paths out of the repo:
2831
FactionRelationships/
2932
├── mod_info.json
3033
├── config/
31-
│ └── faction_relationships_config.json # optional: maxFactions (default 15, clamped 1–50)
34+
│ └── faction_relationships_config.json # deprecated; settings via LunaLib (see data/config)
35+
├── data/
36+
│ └── config/
37+
│ └── LunaSettings.csv # LunaLib settings (max factions, text size, overlay keybind)
3238
├── src/
3339
│ └── com/factionrelationships/
3440
│ ├── FactionRelationshipsPlugin.java
35-
│ └── FactionRelationshipsUIRenderer.java
41+
│ ├── FactionRelationshipsUIRenderer.java
42+
│ └── FactionRelationshipsKeybindScript.java
3643
├── compile.local.example.bat # copy to compile.local.bat (gitignored) to set GAME_DIR
3744
└── COMPILATION.md
3845
```
3946

40-
Output: `FactionRelationships-<version>/` (folder and zip), where `<version>` comes from `mod_info.json` (e.g. `FactionRelationships-1.0.0/`, `FactionRelationships-1.0.0.zip`). Contains `classes/`, `jars/FactionRelationships.jar`, and `config/`.
47+
Output: `FactionRelationships-<version>/` (folder and zip), where `<version>` comes from `mod_info.json`. Contains `classes/`, `jars/FactionRelationships.jar`, `config/`, and `data/`. In-game settings and keybind are configured via **Mod Settings** (F2 in campaign) under this mod's section.
4148

4249
## Compile
4350

@@ -47,17 +54,19 @@ From the repo root, run the build script:
4754
FactionRelationships\compile.bat
4855
```
4956

50-
Or manually:
57+
Or manually (set `LUNALIB` and `LAZYLIB` if using versioned mod folders):
5158

5259
```batch
5360
set GAME_DIR=YOUR_STARSECTOR_PATH
61+
set LUNALIB=%GAME_DIR%\mods\LunaLib\jars\LunaLib.jar
62+
set LAZYLIB=%GAME_DIR%\mods\LazyLib\jars\LazyLib.jar
5463
set CORE=%GAME_DIR%\starsector-core
55-
set VERSION=1.0.0
56-
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar" -d FactionRelationships-%VERSION%\classes FactionRelationships\src\com\factionrelationships\*.java
64+
set VERSION=1.3.0
65+
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d FactionRelationships-%VERSION%\classes FactionRelationships\src\com\factionrelationships\FactionRelationshipsPlugin.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsUIRenderer.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsKeybindScript.java
5766
jar cvf FactionRelationships-%VERSION%\jars\FactionRelationships.jar -C FactionRelationships-%VERSION%\classes .
5867
```
5968

60-
Set `GAME_DIR` before running (e.g. via `compile.local.bat` as above, or in the batch session).
69+
Set `GAME_DIR` (and optionally `LUNALIB`, `LAZYLIB`) before running (e.g. via `compile.local.bat` as above, or in the batch session).
6170

6271
## Package and Install
6372

@@ -76,14 +85,17 @@ Set `GAME_DIR` before running (e.g. via `compile.local.bat` as above, or in the
7685
├── mod_info.json
7786
├── config\
7887
│ └── faction_relationships_config.json
88+
├── data\
89+
│ └── config\
90+
│ └── LunaSettings.csv
7991
└── jars\
8092
└── FactionRelationships.jar
8193
```
8294

83-
To change how many factions are shown, edit `config/faction_relationships_config.json` and set `maxFactions` (1–50). Default is 15.
95+
Configure max factions, text size, overlay keybind (toggle or hold), and hostile-only filter in **Mod Settings** (F2 in campaign).
8496

8597
## Quick Reference
8698

87-
- **Game directory**: Set `GAME_DIR` in `compile.local.bat` (recommended) or in `compile.bat` / manual commands.
99+
- **Game directory**: Set `GAME_DIR` in `compile.local.bat` (recommended) or in `compile.bat` / manual commands. Optionally set `LUNALIB` and `LAZYLIB` in `compile.local.bat` if you use versioned LunaLib/LazyLib folders.
88100
- **Source**: `FactionRelationships/src/com/factionrelationships/`
89101
- **Output**: `FactionRelationships-<version>/` and `FactionRelationships-<version>.zip` (version from `mod_info.json`); JAR at `jars/FactionRelationships.jar` inside the package.

FactionRelationships/compile.bat

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ if exist "%~dp0compile.local.bat" call "%~dp0compile.local.bat"
44
if not defined GAME_DIR set GAME_DIR=YOUR_STARSECTOR_PATH
55

66
set CORE=%GAME_DIR%\starsector-core
7+
if not defined LUNALIB set LUNALIB=%GAME_DIR%\mods\LunaLib\jars\LunaLib.jar
8+
if not defined LAZYLIB set LAZYLIB=%GAME_DIR%\mods\LazyLib\jars\LazyLib.jar
79
if not exist "%CORE%\starfarer.api.jar" (
810
echo Error: Starsector path not found.
911
echo Copy FactionRelationships\compile.local.example.bat to compile.local.bat and set GAME_DIR to your Starsector install directory.
1012
exit /b 1
1113
)
14+
if not exist "%LUNALIB%" (
15+
echo Error: LunaLib not found at %LUNALIB%
16+
echo Install LunaLib in your Starsector mods folder to compile.
17+
exit /b 1
18+
)
19+
if not exist "%LAZYLIB%" (
20+
echo Error: LazyLib not found at %LAZYLIB%
21+
echo Install LazyLib in your Starsector mods folder to compile.
22+
exit /b 1
23+
)
1224

1325
REM Read version from mod_info.json for package and zip names
1426
for /f "delims=" %%v in ('powershell -NoProfile -Command "(Get-Content '%~dp0mod_info.json' -Raw | ConvertFrom-Json).version"') do set VERSION=%%v
@@ -22,7 +34,7 @@ if not exist "%OUT%" mkdir "%OUT%"
2234
if not exist "..\%PKG%\jars" mkdir "..\%PKG%\jars"
2335

2436
echo Compiling...
25-
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar" -d "%OUT%" "%SRC%\FactionRelationshipsPlugin.java" "%SRC%\FactionRelationshipsUIRenderer.java"
37+
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d "%OUT%" "%SRC%\FactionRelationshipsPlugin.java" "%SRC%\FactionRelationshipsUIRenderer.java" "%SRC%\FactionRelationshipsKeybindScript.java"
2638
if errorlevel 1 (
2739
echo Compilation failed.
2840
exit /b 1
@@ -35,9 +47,10 @@ if errorlevel 1 (
3547
exit /b 1
3648
)
3749

38-
echo Copying mod_info.json and config to package...
50+
echo Copying mod_info.json, config, and data to package...
3951
copy /Y "mod_info.json" "..\%PKG%\mod_info.json" >nul
4052
if exist "config" xcopy /E /I /Y "config" "..\%PKG%\config" >nul
53+
if exist "data" xcopy /E /I /Y "data" "..\%PKG%\data" >nul
4154

4255
echo Creating %PKG%.zip...
4356
powershell -NoProfile -Command "Compress-Archive -Path '..\%PKG%' -DestinationPath '..\%PKG%.zip' -Force"

FactionRelationships/compile.local.example.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ REM Copy this file to compile.local.bat and set your paths.
33
REM compile.local.bat is gitignored and will be used by compile.bat when present.
44

55
set GAME_DIR=YOUR_STARSECTOR_PATH
6+
7+
REM Optional: if LunaLib/LazyLib use versioned folder names (e.g. LunaLib-2.0.5), set these so the build finds the JARs:
8+
REM set LUNALIB=%GAME_DIR%\mods\LunaLib-2.0.5\jars\LunaLib.jar
9+
REM set LAZYLIB=%GAME_DIR%\mods\LazyLib-3.0.0\jars\LazyLib.jar
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fieldID,fieldName,fieldType,defaultValue,secondaryValue,fieldDescription,minValue,maxValue,tab
2+
factionRelationshipsHeader,Faction Relationships,Header,Faction Relationships,,,,,General
3+
maxFactions,Max Factions Shown,Int,15,,Maximum number of factions to display in the overlay (sorted by relationship).,1,50,General
4+
showOnlyHostile,Show Only Hostile Factions,Boolean,false,,Only display factions with reputation -50 or worse (Hostile/Inhospitable). Helps focus on immediate threats.,,,General
5+
textSize,Text Size,Radio,Medium,"Small,Medium,Large",Text size for the overlay. Use [Large] for 4K or high-DPI displays.,,,General
6+
overlayKeybindMode,Overlay Keybind Mode,Radio,Toggle,"Toggle,Hold",[Toggle]: Press key to show or hide overlay. [Hold]: Overlay only visible while key is held.,,,General
7+
toggleOverlayKeybind,Toggle Overlay Keybind,Keycode,0,,Key to show or hide the faction relationship overlay on the campaign map. Set in Mod Settings (F2). Keycode 0 = unbound.,,,General

FactionRelationships/mod_info.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"id": "factionrelationships",
33
"name": "Faction Relationships",
44
"author": "boop",
5-
"version": "1.0.0",
5+
"version": "1.3.1",
66
"description": "Shows a list of factions and their relationship with the player on the main navigation screen.",
77
"gameVersion": "0.98a-RC8",
88
"jars": ["jars/FactionRelationships.jar"],
9-
"modPlugin": "com.factionrelationships.FactionRelationshipsPlugin"
9+
"modPlugin": "com.factionrelationships.FactionRelationshipsPlugin",
10+
"dependencies": [
11+
{"id": "lw_lazylib", "name": "LazyLib"},
12+
{"id": "lunalib", "name": "LunaLib"}
13+
]
1014
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.factionrelationships;
2+
3+
import com.fs.starfarer.api.Global;
4+
import com.fs.starfarer.api.EveryFrameScript;
5+
import lunalib.lunaSettings.LunaSettings;
6+
import org.lwjgl.input.Keyboard;
7+
8+
/**
9+
* Polls the LunaLib keybind. In Toggle mode: press to show/hide overlay (edge detection).
10+
* In Hold mode: overlay visible only while key is held.
11+
*/
12+
public class FactionRelationshipsKeybindScript implements EveryFrameScript {
13+
14+
private boolean keyWasDown;
15+
16+
@Override
17+
public boolean isDone() {
18+
return false;
19+
}
20+
21+
@Override
22+
public boolean runWhilePaused() {
23+
return false;
24+
}
25+
26+
@Override
27+
public void advance(float amount) {
28+
if (!Global.getSettings().getModManager().isModEnabled("lunalib")) {
29+
return;
30+
}
31+
Integer keycodeObj = LunaSettings.getInt("factionrelationships", "toggleOverlayKeybind");
32+
if (keycodeObj == null || keycodeObj.intValue() == 0) {
33+
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
34+
return;
35+
}
36+
int keycode = keycodeObj.intValue();
37+
boolean keyDown = Keyboard.isKeyDown(keycode);
38+
String mode = FactionRelationshipsPlugin.getOverlayKeybindMode();
39+
if ("Hold".equals(mode)) {
40+
FactionRelationshipsPlugin.setOverlayKeyHeld(keyDown);
41+
} else {
42+
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
43+
if (!keyWasDown && keyDown) {
44+
FactionRelationshipsPlugin.setOverlayVisible(!FactionRelationshipsPlugin.isOverlayVisible());
45+
}
46+
}
47+
keyWasDown = keyDown;
48+
}
49+
}

FactionRelationships/src/com/factionrelationships/FactionRelationshipsPlugin.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,85 @@
22

33
import com.fs.starfarer.api.BaseModPlugin;
44
import com.fs.starfarer.api.Global;
5+
import lunalib.lunaSettings.LunaSettings;
6+
import lunalib.lunaSettings.LunaSettingsListener;
57
import org.apache.log4j.Logger;
68

79
public class FactionRelationshipsPlugin extends BaseModPlugin {
810

911
private static Logger log;
1012

13+
/** Overlay visibility toggle; read by renderer, written by keybind script (Toggle mode). Default true. */
14+
private static volatile boolean overlayVisible = true;
15+
16+
/** Key currently held; used in Hold mode so overlay shows only while key is down. */
17+
private static volatile boolean overlayKeyHeld = false;
18+
19+
/** Cached overlay keybind mode (Toggle vs Hold); invalidated when LunaSettings change. */
20+
private static volatile String cachedOverlayKeybindMode = null;
21+
22+
public static boolean isOverlayVisible() {
23+
return overlayVisible;
24+
}
25+
26+
public static void setOverlayVisible(boolean visible) {
27+
overlayVisible = visible;
28+
}
29+
30+
public static boolean isOverlayKeyHeld() {
31+
return overlayKeyHeld;
32+
}
33+
34+
public static void setOverlayKeyHeld(boolean held) {
35+
overlayKeyHeld = held;
36+
}
37+
38+
/** Returns "Toggle" or "Hold"; default "Toggle" if unset or LunaLib disabled. */
39+
public static String getOverlayKeybindMode() {
40+
if (cachedOverlayKeybindMode != null) {
41+
return cachedOverlayKeybindMode;
42+
}
43+
String mode = "Toggle";
44+
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
45+
String s = LunaSettings.getString("factionrelationships", "overlayKeybindMode");
46+
if (s != null && ("Hold".equalsIgnoreCase(s) || "Toggle".equalsIgnoreCase(s))) {
47+
mode = "Hold".equalsIgnoreCase(s) ? "Hold" : "Toggle";
48+
}
49+
}
50+
cachedOverlayKeybindMode = mode;
51+
return mode;
52+
}
53+
54+
/** Called when LunaSettings change so mode and other caches are re-read. */
55+
public static void invalidateSettingsCache() {
56+
cachedOverlayKeybindMode = null;
57+
}
58+
1159
@Override
1260
public void onApplicationLoad() throws Exception {
1361
log = Global.getLogger(FactionRelationshipsPlugin.class);
1462
log.info("Faction Relationships mod loaded.");
63+
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
64+
LunaSettings.addSettingsListener(new LunaSettingsListener() {
65+
@Override
66+
public void settingsChanged(String modID) {
67+
if ("factionrelationships".equals(modID)) {
68+
FactionRelationshipsPlugin.invalidateSettingsCache();
69+
FactionRelationshipsUIRenderer.invalidateSettingsCache();
70+
}
71+
}
72+
});
73+
}
1574
}
1675

1776
@Override
1877
public void onGameLoad(boolean newGame) {
1978
Global.getSector().getListenerManager().addListener(new FactionRelationshipsUIRenderer(), true);
79+
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
80+
Global.getSector().addScript(new FactionRelationshipsKeybindScript());
81+
}
2082
if (log != null) {
21-
log.info("Faction Relationships UI renderer registered.");
83+
log.info("Faction Relationships UI renderer and keybind script registered.");
2284
}
2385
}
2486
}

0 commit comments

Comments
 (0)