- Add addon requirements
- Add config to reload mods
This commit is contained in:
parent
07ce631871
commit
47a01f17cd
@ -33,7 +33,7 @@ class BuildingsController @Autowired constructor(
|
||||
|
||||
@GetMapping("/{buildingId}")
|
||||
fun getById(@PathVariable buildingId: Long): BuildingFullDto {
|
||||
return buildingRepository.findById(buildingId).get().toDto()
|
||||
return dowBuildingMappingService.mapToDto(buildingRepository.findById(buildingId).get())
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
|
||||
@ -18,6 +18,18 @@ class CustomModsController @Autowired constructor(
|
||||
return "Successfully reload mod"
|
||||
}
|
||||
|
||||
@DeleteMapping("/data")
|
||||
fun deleteAllModData(): String {
|
||||
modStorageIntegrationService.deleteMods()
|
||||
return "Successfully delete all mods data"
|
||||
}
|
||||
|
||||
@DeleteMapping("/data/{modId}")
|
||||
fun deleteModData(@PathVariable modId: Long): String {
|
||||
modStorageIntegrationService.deleteMod(modId)
|
||||
return "Successfully delete mod data"
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
fun uploadMod(@RequestParam("file") file: MultipartFile?,
|
||||
@RequestParam("name") name: String,
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package com.dowstats.data.dto.controllers.building
|
||||
|
||||
data class AddonRequirementDto (
|
||||
val id: Long,
|
||||
val reference: String?,
|
||||
val replaceWhenDone: Boolean,
|
||||
val value: Double?,
|
||||
val requirementBuildings: List<BuildingShortDto>,
|
||||
val requirementBuildingsEither: List<BuildingShortDto>,
|
||||
val requireAddon: BuildingAddonShortDto?,
|
||||
val requirementsGlobalAddons: List<BuildingAddonShortDto>?,
|
||||
val requiredTotalPop: Int?,
|
||||
)
|
||||
|
||||
@ -12,6 +12,13 @@ data class BuildingAddonDto(
|
||||
val addonCostSouls: Double?,
|
||||
val addonCostTime: Int?,
|
||||
val addonModifiers: Set<AddonModifierDto>,
|
||||
val addonRequirements: Set<AddonRequirementDto>,
|
||||
val addonRequirement: AddonRequirementDto?,
|
||||
val icon: String?,
|
||||
)
|
||||
|
||||
data class BuildingAddonShortDto(
|
||||
val id: Long?,
|
||||
val buildingId: Long?,
|
||||
val name: String?,
|
||||
val icon: String?,
|
||||
)
|
||||
@ -19,14 +19,14 @@ class AddonRequirements {
|
||||
var addon: BuildingAddon? = null
|
||||
var reference: String? = null
|
||||
var replaceWhenDone: Boolean = false
|
||||
var value: Double? = null
|
||||
|
||||
fun toDto(): AddonRequirementDto {
|
||||
return AddonRequirementDto(
|
||||
id = id!!,
|
||||
reference = reference,
|
||||
replaceWhenDone = replaceWhenDone,
|
||||
value = value
|
||||
)
|
||||
var value: String? = null
|
||||
|
||||
companion object {
|
||||
val REFERENCE_REQUIREMENT_POP = "requirements\\required_total_pop.lua"
|
||||
val REFERENCE_REQUIREMENT_ADDON = "requirements\\local_required_addon.lua"
|
||||
val REFERENCE_GLOBAL_REQUIREMENT_ADDON = "requirements\\global_required_addon.lua"
|
||||
val REFERENCE_REQUIREMENT_STRUCTURE_EITHER = "requirements\\required_structure_either.lua"
|
||||
val REFERENCE_REQUIREMENT_STRUCTURE = "requirements\\required_structure.lua"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.dowstats.data.entities
|
||||
|
||||
import com.dowstats.data.dto.controllers.building.BuildingAddonDto
|
||||
import com.dowstats.data.dto.controllers.building.BuildingFullDto
|
||||
import jakarta.persistence.*
|
||||
|
||||
@ -47,7 +48,7 @@ class Building {
|
||||
@OneToMany(mappedBy = "building", cascade = [CascadeType.ALL])
|
||||
var weapons: MutableSet<BuildingWeapon>? = null
|
||||
|
||||
fun toDto(): BuildingFullDto =
|
||||
fun toDto(buildingAddons: Set<BuildingAddonDto>?): BuildingFullDto =
|
||||
BuildingFullDto(
|
||||
id!!,
|
||||
race?.toDto(),
|
||||
@ -69,7 +70,7 @@ class Building {
|
||||
repairMax,
|
||||
icon,
|
||||
modId!!,
|
||||
addons?.map { it.toDto() }?.toSet(),
|
||||
buildingAddons,
|
||||
weapons?.map { it.toWeaponSlotDto() }?.toSet(),
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.dowstats.data.entities
|
||||
|
||||
import com.dowstats.data.dto.controllers.building.AddonRequirementDto
|
||||
import com.dowstats.data.dto.controllers.building.BuildingAddonDto
|
||||
import com.dowstats.data.dto.controllers.building.BuildingAddonShortDto
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import jakarta.persistence.*
|
||||
|
||||
@ -35,8 +37,9 @@ class BuildingAddon {
|
||||
var addonRequirements: MutableSet<AddonRequirements>? = null
|
||||
|
||||
var icon: String? = null
|
||||
var modId: Long? = null
|
||||
|
||||
fun toDto(): BuildingAddonDto = BuildingAddonDto(
|
||||
fun toDto(addonRequirementDto: AddonRequirementDto?): BuildingAddonDto = BuildingAddonDto(
|
||||
id = id,
|
||||
name = name,
|
||||
description = description,
|
||||
@ -48,7 +51,14 @@ class BuildingAddon {
|
||||
addonCostSouls = addonCostSouls,
|
||||
addonCostTime = addonCostTime,
|
||||
addonModifiers = addonModifiers?.map { it.toDto() }?.toSet() ?: emptySet(),
|
||||
addonRequirements = addonRequirements?.map { it.toDto() }?.toSet() ?: emptySet(),
|
||||
addonRequirement = addonRequirementDto,
|
||||
icon = icon
|
||||
)
|
||||
|
||||
fun toShortDto(): BuildingAddonShortDto = BuildingAddonShortDto(
|
||||
id = id,
|
||||
buildingId = building?.id,
|
||||
name = name,
|
||||
icon = icon
|
||||
)
|
||||
|
||||
|
||||
@ -7,4 +7,6 @@ import com.dowstats.data.entities.Race
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
|
||||
interface AddonRepository : CrudRepository<BuildingAddon, Long>
|
||||
interface AddonRepository : CrudRepository<BuildingAddon, Long>{
|
||||
fun findFirstByModIdAndFilename(modId: Long, fileName: String): BuildingAddon?
|
||||
}
|
||||
@ -17,4 +17,6 @@ interface BuildingRepository : CrudRepository<Building, Long>{
|
||||
order by b.race.id desc
|
||||
""")
|
||||
fun findByModIdAndRace(modId: Long, race: Race?): List<Building>
|
||||
|
||||
fun findByModIdAndFilename(modId: Long, fileName: String): Building?
|
||||
}
|
||||
@ -1,8 +1,12 @@
|
||||
package com.dowstats.service.datamaps
|
||||
|
||||
import com.dowstats.data.dto.controllers.building.AddonRequirementDto
|
||||
import com.dowstats.data.dto.controllers.building.BuildingFullDto
|
||||
import com.dowstats.data.dto.controllers.building.BuildingShortDto
|
||||
import com.dowstats.data.dto.controllers.building.RaceBuildings
|
||||
import com.dowstats.data.entities.AddonRequirements
|
||||
import com.dowstats.data.entities.Building
|
||||
import com.dowstats.data.repositories.AddonRepository
|
||||
import com.dowstats.data.repositories.BuildingRepository
|
||||
import com.dowstats.data.repositories.RaceRepository
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
@ -11,34 +15,103 @@ import org.springframework.stereotype.Service
|
||||
@Service
|
||||
class DowBuildingMappingService @Autowired constructor(
|
||||
val buildingRepository: BuildingRepository,
|
||||
val addonRepository: AddonRepository,
|
||||
val raceRepository: RaceRepository
|
||||
) {
|
||||
|
||||
fun findBuildingsByMod(modId: Long): List<RaceBuildings> {
|
||||
return getAllBuildings(modId).groupBy { it.race }.mapNotNull {raceUnits ->
|
||||
return getAllBuildings(modId).groupBy { it.race }.mapNotNull { raceUnits ->
|
||||
RaceBuildings(raceUnits.key?.toDto() ?: throw Exception("Race is null"), raceUnits.value.toBuildingDto())
|
||||
}
|
||||
}
|
||||
|
||||
fun findBuildingsByModAndRace(modId: Long, race: String): RaceBuildings {
|
||||
val buildings = getAllBuildings(modId, race)
|
||||
val raceEntity = race.let{ raceRepository.findById(race) ?: throw Exception("Race $race not found") }
|
||||
val raceEntity = race.let { raceRepository.findById(race) ?: throw Exception("Race $race not found") }
|
||||
return RaceBuildings(raceEntity.toDto(), buildings.toBuildingDto())
|
||||
}
|
||||
|
||||
fun mapToDto(building: Building): BuildingFullDto {
|
||||
|
||||
val buildingAddons = building.addons?.map { addon ->
|
||||
|
||||
val requirements = addon.addonRequirements
|
||||
|
||||
val requireCap =
|
||||
requirements?.find { it.reference == AddonRequirements.REFERENCE_REQUIREMENT_POP }?.value?.toDouble()
|
||||
?.toInt()
|
||||
|
||||
val requirementAddon =
|
||||
requirements?.find { it.reference == AddonRequirements.REFERENCE_REQUIREMENT_ADDON }?.value?.let {
|
||||
building.addons?.find { addon -> addon.filename == it.split("\\").last().replace(".lua", ".rgd") }
|
||||
}
|
||||
|
||||
val requirementAddonGlobal =
|
||||
requirements?.filter { it.reference == AddonRequirements.REFERENCE_GLOBAL_REQUIREMENT_ADDON }
|
||||
?.mapNotNull { rgra ->
|
||||
val addonFileName = rgra.value?.split("\\")?.last()?.replace(".lua", ".rgd")
|
||||
addonFileName?.let {
|
||||
addonRepository.findFirstByModIdAndFilename(
|
||||
building.modId!!,
|
||||
it.split("\\").last().replace(".lua", ".rgd")
|
||||
)?.toShortDto()
|
||||
}
|
||||
}
|
||||
|
||||
val requirementBuildings =
|
||||
requirements?.filter { it.reference == AddonRequirements.REFERENCE_REQUIREMENT_STRUCTURE }?.mapNotNull {
|
||||
val buildingFileName = it.value?.split("\\")?.last()?.replace(".lua", ".rgd")
|
||||
buildingFileName?.let {
|
||||
buildingRepository.findByModIdAndFilename(building.modId!!, buildingFileName)
|
||||
}
|
||||
}?.filter { it.id != building.id }?.distinct()?.toBuildingDto()
|
||||
|
||||
val requirementBuildingsEither =
|
||||
requirements?.find { it.reference == AddonRequirements.REFERENCE_REQUIREMENT_STRUCTURE_EITHER }?.let {
|
||||
it.value?.split(";")?.mapNotNull { bPath ->
|
||||
buildingRepository.findByModIdAndFilename(
|
||||
building.modId!!,
|
||||
bPath.split("\\").last().replace(".lua", ".rgd")
|
||||
)
|
||||
}
|
||||
}?.toBuildingDto()
|
||||
|
||||
val addonRequirement = if (requireCap != null ||
|
||||
requirementAddon != null ||
|
||||
(requirementBuildings?.size ?: 0) > 0 ||
|
||||
(requirementBuildingsEither?.size ?: 0) > 0 ||
|
||||
(requirementAddonGlobal?.size ?: 0) > 0
|
||||
) {
|
||||
AddonRequirementDto(
|
||||
requirementBuildings ?: emptyList(),
|
||||
requirementBuildingsEither ?: emptyList(),
|
||||
requirementAddon?.toShortDto(),
|
||||
requirementAddonGlobal,
|
||||
requireCap
|
||||
)
|
||||
} else null
|
||||
|
||||
addon.toDto(addonRequirement)
|
||||
}?.sortedBy { it.id }?.toSet()
|
||||
|
||||
return building.toDto(buildingAddons)
|
||||
}
|
||||
|
||||
|
||||
private fun List<Building>.toBuildingDto(): List<BuildingShortDto> =
|
||||
this.mapNotNull {
|
||||
val name = it.name ?: it.filename
|
||||
val icon = it.icon
|
||||
if (name == null || icon == null) null else BuildingShortDto(name, icon, it.id!!,
|
||||
if (name == null || icon == null) null else BuildingShortDto(
|
||||
name, icon, it.id!!,
|
||||
it.armorType?.name!!,
|
||||
(it.detectRadius ?: 0) > 0)
|
||||
(it.detectRadius ?: 0) > 0
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun getAllBuildings(modId: Long, race: String? = null): List<Building> {
|
||||
val raceEntity = race?.let{ raceRepository.findById(race) ?: throw Exception("Race $race not found") }
|
||||
val raceEntity = race?.let { raceRepository.findById(race) ?: throw Exception("Race $race not found") }
|
||||
return filterCompanyUnits(buildingRepository.findByModIdAndRace(modId, raceEntity))
|
||||
}
|
||||
|
||||
|
||||
@ -77,6 +77,18 @@ class ModStorageIntegrationService(
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun deleteMod(modId: Long) {
|
||||
modRepository.clearModData(modId)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun deleteMods() {
|
||||
modRepository.findAll().forEach{
|
||||
modRepository.clearModData(it.id!!)
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun reloadMod(modId: Long) {
|
||||
val mod = modRepository.findById(modId).orElseThrow { IllegalArgumentException("Mod not found") }
|
||||
|
||||
@ -56,6 +56,7 @@ class BuildingAddonRgdExtractService @Autowired constructor(
|
||||
|
||||
val addonIcon = convertIconAndReturnPath(addonRgdData, modFolderData, mod.name)
|
||||
addon.icon = addonIcon
|
||||
addon.modId = mod.id
|
||||
|
||||
return addon
|
||||
}
|
||||
@ -87,9 +88,14 @@ class BuildingAddonRgdExtractService @Autowired constructor(
|
||||
it.addon = addon
|
||||
it.reference = rTable.getStringByName("\$REF")
|
||||
it.replaceWhenDone = rTable.getBooleanByName("replace_when_done") == true
|
||||
// TODO - что-то придумать с этим
|
||||
it.value =
|
||||
if (it.reference == "requirements\\required_total_pop.lua") rTable.getDoubleByName("population_required") else null
|
||||
it.value = when(it.reference){
|
||||
AddonRequirements.REFERENCE_REQUIREMENT_POP -> rTable.getDoubleByName("population_required").toString()
|
||||
AddonRequirements.REFERENCE_REQUIREMENT_ADDON -> rTable.getStringByName("addon_name")
|
||||
AddonRequirements.REFERENCE_GLOBAL_REQUIREMENT_ADDON -> rTable.getStringByName("global_addon_name")
|
||||
AddonRequirements.REFERENCE_REQUIREMENT_STRUCTURE_EITHER -> rTable.getStringByName("structure_name_or") + ";" + rTable.getStringByName("structure_name_either")
|
||||
AddonRequirements.REFERENCE_REQUIREMENT_STRUCTURE -> rTable.getStringByName("structure_name")
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
} else null
|
||||
|
||||
@ -67,6 +67,48 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"changeSet": {
|
||||
"id": "Change addon_requirements value type (2)",
|
||||
"author": "anibus",
|
||||
"changes": [
|
||||
{
|
||||
"dropColumn": {
|
||||
"columns": [
|
||||
{
|
||||
"column": {
|
||||
"name": "value"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tableName": "addon_requirements"
|
||||
}
|
||||
},
|
||||
{
|
||||
"addColumn": {
|
||||
"columns": [
|
||||
{
|
||||
"column": {
|
||||
"name": "value",
|
||||
"type": "varchar(256)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"column": {
|
||||
"name": "mod_id",
|
||||
"type": "int",
|
||||
"constraints": {
|
||||
"nullable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"tableName": "addon_requirements"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user