Add directories to distingish between pixelized apps.
This commit is contained in:
parent
03df369e0b
commit
3f67e342a7
18 changed files with 178 additions and 108 deletions
|
|
@ -5,20 +5,26 @@ import com.pixelized.server.lwa.model.campaign.CampaignStore
|
|||
import com.pixelized.server.lwa.model.character.CharacterSheetService
|
||||
import com.pixelized.server.lwa.model.character.CharacterSheetStore
|
||||
import com.pixelized.server.lwa.server.Engine
|
||||
import com.pixelized.shared.lwa.utils.PathProvider
|
||||
import org.koin.core.module.dsl.createdAtStart
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.module
|
||||
|
||||
val serverModuleDependencies
|
||||
get() = listOf(
|
||||
parserDependencies,
|
||||
factoryDependencies,
|
||||
useCaseDependencies,
|
||||
toolsDependencies,
|
||||
engineDependencies,
|
||||
storeDependencies,
|
||||
serviceDependencies,
|
||||
engineDependencies,
|
||||
)
|
||||
|
||||
val toolsDependencies
|
||||
get() = module {
|
||||
single {
|
||||
PathProvider(appName = "LwaServer")
|
||||
}
|
||||
}
|
||||
|
||||
val engineDependencies
|
||||
get() = module {
|
||||
singleOf(constructor = ::Engine, options = { createdAtStart() })
|
||||
|
|
@ -37,18 +43,3 @@ val serviceDependencies
|
|||
singleOf(::CampaignService)
|
||||
singleOf(::AlterationService)
|
||||
}
|
||||
|
||||
val factoryDependencies
|
||||
get() = module {
|
||||
|
||||
}
|
||||
|
||||
val parserDependencies
|
||||
get() = module {
|
||||
|
||||
}
|
||||
|
||||
val useCaseDependencies
|
||||
get() = module {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.pixelized.server.lwa.model.alteration
|
||||
|
||||
import com.pixelized.shared.lwa.alterationsPath
|
||||
import com.pixelized.shared.lwa.model.alteration.AlterationJson
|
||||
import com.pixelized.shared.lwa.model.campaign.Campaign
|
||||
import com.pixelized.shared.lwa.model.campaign.factory.CampaignJsonFactory
|
||||
import com.pixelized.shared.lwa.utils.PathProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -14,10 +14,11 @@ import kotlinx.serialization.json.Json
|
|||
import java.io.File
|
||||
|
||||
class AlterationStore(
|
||||
private val pathProvider: PathProvider,
|
||||
private val campaignJsonFactory: CampaignJsonFactory,
|
||||
private val json: Json,
|
||||
) {
|
||||
private val directory = File(alterationsPath()).also { it.mkdirs() }
|
||||
private val directory = File(pathProvider.alterationsPath()).also { it.mkdirs() }
|
||||
private val alterationsFlow = MutableStateFlow<List<AlterationJson>>(emptyList())
|
||||
private val activeFlow = MutableStateFlow<Map<String, List<String>>>(emptyMap())
|
||||
|
||||
|
|
@ -118,13 +119,13 @@ class AlterationStore(
|
|||
}
|
||||
|
||||
private fun file(): File {
|
||||
return File("${alterationsPath()}alterations.json")
|
||||
return File("${pathProvider.alterationsPath()}alterations.json")
|
||||
}
|
||||
|
||||
private fun file(
|
||||
id: String,
|
||||
): File {
|
||||
return File("${alterationsPath()}$id.json")
|
||||
return File("${pathProvider.alterationsPath()}$id.json")
|
||||
}
|
||||
|
||||
private fun MutableList<String>.toggle(alterationId: String): MutableList<String> {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.pixelized.server.lwa.model.campaign
|
||||
|
||||
import com.pixelized.shared.lwa.campaignPath
|
||||
import com.pixelized.shared.lwa.model.campaign.Campaign
|
||||
import com.pixelized.shared.lwa.model.campaign.CampaignJson
|
||||
import com.pixelized.shared.lwa.model.campaign.factory.CampaignJsonFactory
|
||||
import com.pixelized.shared.lwa.utils.PathProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -14,6 +14,7 @@ import kotlinx.serialization.json.Json
|
|||
import java.io.File
|
||||
|
||||
class CampaignStore(
|
||||
private val pathProvider: PathProvider,
|
||||
private val factory: CampaignJsonFactory,
|
||||
private val json: Json,
|
||||
) {
|
||||
|
|
@ -21,7 +22,7 @@ class CampaignStore(
|
|||
|
||||
init {
|
||||
// create the directory if needed.
|
||||
File(campaignPath()).also { it.mkdirs() }
|
||||
File(pathProvider.campaignPath()).also { it.mkdirs() }
|
||||
// build a coroutine scope for async calls
|
||||
val scope = CoroutineScope(Dispatchers.IO + Job())
|
||||
// load the initial data
|
||||
|
|
@ -73,6 +74,6 @@ class CampaignStore(
|
|||
class FileWriteException(root: Exception) : CampaignStoreException(root)
|
||||
|
||||
private fun file(): File {
|
||||
return File("${campaignPath()}campaign.json")
|
||||
return File("${pathProvider.campaignPath()}campaign.json")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
package com.pixelized.server.lwa.model.character
|
||||
|
||||
import com.pixelized.shared.lwa.characterStorePath
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheetJson
|
||||
import com.pixelized.shared.lwa.model.characterSheet.CharacterSheetJsonFactory
|
||||
import com.pixelized.shared.lwa.utils.PathProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.text.Collator
|
||||
|
||||
class CharacterSheetStore(
|
||||
private val pathProvider: PathProvider,
|
||||
private val factory: CharacterSheetJsonFactory,
|
||||
private val json: Json,
|
||||
) {
|
||||
private val directory = File(characterStorePath()).also { it.mkdirs() }
|
||||
private val directory = File(pathProvider.characterStorePath()).also { it.mkdirs() }
|
||||
private val flow = MutableStateFlow<List<CharacterSheet>>(value = emptyList())
|
||||
|
||||
init {
|
||||
|
|
@ -112,7 +112,7 @@ class CharacterSheetStore(
|
|||
}
|
||||
|
||||
private fun characterSheetFile(id: String): File {
|
||||
return File("${characterStorePath()}${id}.json")
|
||||
return File("${pathProvider.characterStorePath()}${id}.json")
|
||||
}
|
||||
|
||||
sealed class CharacterSheetStoreException(root: Exception) : Exception(root)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue