Skip to content

Commit

Permalink
Add a repository field to the mod class (#150)
Browse files Browse the repository at this point in the history
* Add fields for the URL of a mod

* Add a test for reading `mod_info.lua`

* Similar nil-like check as used in `extractIconPath`

* Clean up imports

* Create the directory used in the test

* Remove the assert as it is not required

* Do not use `var`
  • Loading branch information
Garanas authored Jun 2, 2024
1 parent 31b0945 commit 9c1978d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ public class Mod {
private String icon;
private String description;
private String author;

/** Used to reference the forums or Github-like URLs */
private String url;
private boolean selectable;
private boolean uiOnly;

/** Used by featured mods */
private final List<MountInfo> mountInfos = new ArrayList<>();

/** Used by featured mods */
private final List<String> hookDirectories = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public Mod readModInfo(InputStream inputStream, Path mountBaseDir) {
mod.setUiOnly(luaValue.get("ui_only").toboolean());
mod.setIcon(extractIconPath(luaValue));

// not all mods have and/or need this value
String url = luaValue.get("url").toString();
if (!("nil".equals(url) || Strings.isNullOrEmpty(url))) {
mod.setUrl(url);
}

ArrayList<MountInfo> mountInfos = new ArrayList<>();
LuaTable mountpoints = luaValue.get("mountpoints").opttable(LuaValue.tableOf());
for (LuaValue key : mountpoints.keys()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;

class ModReaderTest {

Expand All @@ -28,6 +28,18 @@ public void setUp() {
instance = new ModReader();
}

@Test
public void testModReadInfo() throws IOException {
Path modPath = temporaryFolder.resolve("mod-with-url");
Path modInfoPath = temporaryFolder.resolve("mod-with-url/mod_info.lua");
Files.createDirectory(modPath);
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/mod/mod-with-url.lua")), modInfoPath);

Mod mod = instance.readDirectory(modPath);

assertEquals("https://github.com/JeroenDeDauw/NoAirCrashDamage", mod.getUrl());
}

@Test
public void testRegularMod() throws Exception {
assertEquals("good", instance.readZip(prepareRegularMod()).getName());
Expand Down
11 changes: 11 additions & 0 deletions faf-commons-data/src/test/resources/mod/mod-with-url.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "50% Air Crash Damage"
uid = "daeafcc2-0bcc-463a-962e-a33e703eacd1"
version = 1
copyright = "EntropyWins"
description = "Reduces Air Crash damage to 50% of normal. Other versions reduce/increase to 150%, 75%, or 25%. Original mod 'No Air Crash Damage' by EntropyWins, modified by Rama."
author = "EntropyWins + Rama"
selectable = true
ui_only = false
enabled = true
url = "https://github.com/JeroenDeDauw/NoAirCrashDamage"
icon = "/mods/AirCrashDamage50/icon.jpg"

0 comments on commit 9c1978d

Please sign in to comment.