Skip to content

Commit 7e6db8a

Browse files
authored
Merge pull request #1523 from madsboddum/feature/crafting/schematic-group-loader
Draft schematic group loader
2 parents ae086ba + 26e83a4 commit 7e6db8a

6 files changed

Lines changed: 1793 additions & 53 deletions

File tree

serverdata/crafting/schematic_group.sdb

Lines changed: 1653 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/***********************************************************************************
2+
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
3+
* *
4+
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
5+
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6+
* Our goal is to create an emulator which will provide a server for players to *
7+
* continue playing a game similar to the one they used to play. We are basing *
8+
* it on the final publish of the game prior to end-game events. *
9+
* *
10+
* This file is part of Holocore. *
11+
* *
12+
* --------------------------------------------------------------------------------*
13+
* *
14+
* Holocore is free software: you can redistribute it and/or modify *
15+
* it under the terms of the GNU Affero General Public License as *
16+
* published by the Free Software Foundation, either version 3 of the *
17+
* License, or (at your option) any later version. *
18+
* *
19+
* Holocore is distributed in the hope that it will be useful, *
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22+
* GNU Affero General Public License for more details. *
23+
* *
24+
* You should have received a copy of the GNU Affero General Public License *
25+
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
26+
***********************************************************************************/
27+
package com.projectswg.holocore.resources.support.data.server_info.loader
28+
29+
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader
30+
import java.io.File
31+
32+
class SchematicGroupLoader : DataLoader() {
33+
34+
private val schematicGroupMap = mutableMapOf<String, MutableCollection<String>>()
35+
36+
/**
37+
* Returns a collection of all schematic names in the given group
38+
* Example: getSchematicsInGroup("craftDroidDamageRepairA") returns a collection of ["object/draft_schematic/droid/droid_damage_repair_kit_a.iff"]
39+
*/
40+
fun getSchematicsInGroup(groupId: String): Collection<String> {
41+
return schematicGroupMap.getOrElse(groupId) { emptyList() }
42+
}
43+
44+
override fun load() {
45+
val set = SdbLoader.load(File("serverdata/crafting/schematic_group.sdb"))
46+
47+
set.use {
48+
while (set.next()) {
49+
val groupid = set.getText("groupid")
50+
val schematicname = set.getText("schematicname")
51+
52+
if (groupid != "end") {
53+
ensureSchematicGroupExists(groupid)
54+
appendSchematicToGroup(groupid, schematicname)
55+
}
56+
}
57+
}
58+
}
59+
60+
private fun appendSchematicToGroup(groupid: String, schematicname: String) {
61+
schematicGroupMap[groupid]?.add(schematicname)
62+
}
63+
64+
private fun ensureSchematicGroupExists(groupid: String) {
65+
if (!schematicGroupMap.containsKey(groupid)) {
66+
schematicGroupMap[groupid] = mutableListOf()
67+
}
68+
}
69+
}

src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/ServerData.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************************************
2-
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
2+
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
33
* *
44
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
55
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -112,6 +112,7 @@ object ServerData {
112112
val planetChatRooms by SoftDataLoaderDelegate(::PlanetChatRoomLoader)
113113
val staticCityPoints by SoftDataLoaderDelegate(::StaticCityPointLoader)
114114
val npcEquipment by SoftDataLoaderDelegate(::NpcEquipmentLoader)
115+
val schematicGroups by SoftDataLoaderDelegate(::SchematicGroupLoader)
115116

116117
private class WeakDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::WeakReference, loaderCreator)
117118
private class SoftDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::SoftReference, loaderCreator)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/***********************************************************************************
2+
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
3+
* *
4+
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
5+
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6+
* Our goal is to create an emulator which will provide a server for players to *
7+
* continue playing a game similar to the one they used to play. We are basing *
8+
* it on the final publish of the game prior to end-game events. *
9+
* *
10+
* This file is part of Holocore. *
11+
* *
12+
* --------------------------------------------------------------------------------*
13+
* *
14+
* Holocore is free software: you can redistribute it and/or modify *
15+
* it under the terms of the GNU Affero General Public License as *
16+
* published by the Free Software Foundation, either version 3 of the *
17+
* License, or (at your option) any later version. *
18+
* *
19+
* Holocore is distributed in the hope that it will be useful, *
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22+
* GNU Affero General Public License for more details. *
23+
* *
24+
* You should have received a copy of the GNU Affero General Public License *
25+
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
26+
***********************************************************************************/
27+
package com.projectswg.holocore.resources.support.data.server_info.loader
28+
29+
import org.junit.jupiter.api.Assertions.*
30+
import org.junit.jupiter.api.Test
31+
32+
class SchematicGroupLoaderTest {
33+
@Test
34+
fun groupsByGroupIdCorrectly() {
35+
val groupId = "craftAdvancedCreatureGroup"
36+
val expected = setOf(
37+
"object/draft_schematic/bio_engineer/creature/creature_torton.iff",
38+
"object/draft_schematic/bio_engineer/creature/creature_kimogila.iff",
39+
"object/draft_schematic/bio_engineer/creature/creature_rancor.iff",
40+
"object/draft_schematic/bio_engineer/creature/creature_fambaa.iff",
41+
"object/draft_schematic/bio_engineer/creature/creature_veermok.iff",
42+
"object/draft_schematic/bio_engineer/creature/creature_graul.iff",
43+
"object/draft_schematic/bio_engineer/creature/creature_huf_dun.iff",
44+
"object/draft_schematic/bio_engineer/creature/creature_malkloc.iff",
45+
"object/draft_schematic/bio_engineer/creature/creature_sharnaff.iff",
46+
"object/draft_schematic/bio_engineer/creature/creature_woolamander.iff",
47+
)
48+
49+
val schematicsInGroup = ServerData.schematicGroups.getSchematicsInGroup(groupId)
50+
51+
assertEquals(expected.size, schematicsInGroup.size)
52+
assertTrue(schematicsInGroup.containsAll(expected))
53+
}
54+
55+
@Test
56+
fun unknownGroupIdGivesEmptyCollection() {
57+
val schematicsInGroup = ServerData.schematicGroups.getSchematicsInGroup("thisGroupDefinitelyDoesNotExist")
58+
assertTrue(schematicsInGroup.isEmpty())
59+
}
60+
61+
@Test
62+
fun endGroupIdIsIgnored() {
63+
// There's a group called "end" in the client info file, but it's not a real group
64+
val schematicsInGroup = ServerData.schematicGroups.getSchematicsInGroup("end")
65+
assertTrue(schematicsInGroup.isEmpty())
66+
}
67+
}
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
/***********************************************************************************
2-
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
3-
* *
4-
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
5-
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6-
* Our goal is to create an emulator which will provide a server for players to *
7-
* continue playing a game similar to the one they used to play. We are basing *
8-
* it on the final publish of the game prior to end-game events. *
9-
* *
10-
* This file is part of Holocore. *
11-
* *
12-
* --------------------------------------------------------------------------------*
13-
* *
14-
* Holocore is free software: you can redistribute it and/or modify *
15-
* it under the terms of the GNU Affero General Public License as *
16-
* published by the Free Software Foundation, either version 3 of the *
17-
* License, or (at your option) any later version. *
18-
* *
19-
* Holocore is distributed in the hope that it will be useful, *
20-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22-
* GNU Affero General Public License for more details. *
23-
* *
24-
* You should have received a copy of the GNU Affero General Public License *
25-
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
26-
***********************************************************************************/
271
package com.projectswg.utility;
282

293
import com.projectswg.utility.clientdata.Converters;
@@ -53,6 +27,7 @@ public static void main(String [] args) throws IOException {
5327
Converters.APPEARANCE_TABLE.load();
5428
Converters.QUESTLIST.load();
5529
Converters.QUESTTASK.load();
30+
Converters.SCHEMATIC_GROUP.load();
5631
}
5732

5833
}

src/utility/java/com/projectswg/utility/clientdata/Converters.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
/***********************************************************************************
2-
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
3-
* *
4-
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
5-
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6-
* Our goal is to create an emulator which will provide a server for players to *
7-
* continue playing a game similar to the one they used to play. We are basing *
8-
* it on the final publish of the game prior to end-game events. *
9-
* *
10-
* This file is part of Holocore. *
11-
* *
12-
* --------------------------------------------------------------------------------*
13-
* *
14-
* Holocore is free software: you can redistribute it and/or modify *
15-
* it under the terms of the GNU Affero General Public License as *
16-
* published by the Free Software Foundation, either version 3 of the *
17-
* License, or (at your option) any later version. *
18-
* *
19-
* Holocore is distributed in the hope that it will be useful, *
20-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
21-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22-
* GNU Affero General Public License for more details. *
23-
* *
24-
* You should have received a copy of the GNU Affero General Public License *
25-
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
26-
***********************************************************************************/
271
package com.projectswg.utility.clientdata;
282

293
import java.util.function.Supplier;
@@ -47,6 +21,7 @@ public enum Converters {
4721
APPEARANCE_TABLE (() -> new ConvertDatatable("datatables/appearance/appearance_table.iff", "serverdata/appearance/appearance_table.sdb", true)),
4822
QUESTLIST (ConvertQuestLists::new),
4923
QUESTTASK (ConvertQuestTasks::new),
24+
SCHEMATIC_GROUP (() -> new ConvertDatatable("datatables/crafting/schematic_group.iff", "serverdata/crafting/schematic_group.sdb", true)),
5025
TERRAINS (ConvertTerrain::new);
5126

5227
private final Supplier<Converter> converter;

0 commit comments

Comments
 (0)