Added dataloader for dynamic_lairs.sdb

This commit is contained in:
Ziggy
2023-03-25 13:19:09 +01:00
parent 784d35bfc5
commit 3bf76cda67
3 changed files with 100 additions and 1 deletions
@@ -0,0 +1,59 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.server_info.loader
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader
import com.projectswg.holocore.resources.support.data.server_info.SdbLoader.SdbResultSet
import java.io.File
class DynamicLairLoader : DataLoader() {
private val lairIdToDynamicLair = mutableMapOf<String, DynamicLairInfo>()
fun getDynamicLairInfo(lairId: String): DynamicLairInfo? {
return lairIdToDynamicLair[lairId]
}
override fun load() {
val set = SdbLoader.load(File("serverdata/spawn/dynamic/dynamic_lairs.sdb"))
set.use {
while (set.next()) {
val lairId = set.getText("lair_id")
val dynamicLairInfo = DynamicLairInfo(set)
lairIdToDynamicLair[lairId] = dynamicLairInfo
}
}
}
class DynamicLairInfo(set: SdbResultSet) {
val iffTemplate = set.getText("iff_template")
val npcSpawnRadius = set.getInt("npc_spawn_radius")
val gcw = set.getBoolean("gcw")
}
}
@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2019 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -101,6 +101,7 @@ object ServerData {
val badges by SoftDataLoaderDelegate(::BadgeLoader)
val mappingTemplates by SoftDataLoaderDelegate(::MappingTemplateLoader)
val speciesRestrictions by SoftDataLoaderDelegate(::SpeciesRestrictionLoader)
val dynamicLairs by SoftDataLoaderDelegate(::DynamicLairLoader)
private class WeakDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::WeakReference, loaderCreator)
private class SoftDataLoaderDelegate<T: DataLoader>(loaderCreator: () -> T): DataLoaderDelegate<T>(::SoftReference, loaderCreator)
@@ -0,0 +1,39 @@
/***********************************************************************************
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* --------------------------------------------------------------------------------*
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.holocore.resources.support.data.server_info.loader
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class DynamicLairLoaderTest {
@Test
fun `can load dynamic lair`() {
val dynamicLairInfo = ServerData.dynamicLairs.getDynamicLairInfo("lair_bearded_jax")
assertNotNull(dynamicLairInfo)
}
}