- 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}")
|
@GetMapping("/{buildingId}")
|
||||||
fun getById(@PathVariable buildingId: Long): BuildingFullDto {
|
fun getById(@PathVariable buildingId: Long): BuildingFullDto {
|
||||||
return buildingRepository.findById(buildingId).get().toDto()
|
return dowBuildingMappingService.mapToDto(buildingRepository.findById(buildingId).get())
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
|
|||||||
@ -18,6 +18,18 @@ class CustomModsController @Autowired constructor(
|
|||||||
return "Successfully reload mod"
|
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")
|
@PostMapping("/upload")
|
||||||
fun uploadMod(@RequestParam("file") file: MultipartFile?,
|
fun uploadMod(@RequestParam("file") file: MultipartFile?,
|
||||||
@RequestParam("name") name: String,
|
@RequestParam("name") name: String,
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
package com.dowstats.data.dto.controllers.building
|
package com.dowstats.data.dto.controllers.building
|
||||||
|
|
||||||
data class AddonRequirementDto (
|
data class AddonRequirementDto (
|
||||||
val id: Long,
|
val requirementBuildings: List<BuildingShortDto>,
|
||||||
val reference: String?,
|
val requirementBuildingsEither: List<BuildingShortDto>,
|
||||||
val replaceWhenDone: Boolean,
|
val requireAddon: BuildingAddonShortDto?,
|
||||||
val value: Double?,
|
val requirementsGlobalAddons: List<BuildingAddonShortDto>?,
|
||||||
|
val requiredTotalPop: Int?,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -12,6 +12,13 @@ data class BuildingAddonDto(
|
|||||||
val addonCostSouls: Double?,
|
val addonCostSouls: Double?,
|
||||||
val addonCostTime: Int?,
|
val addonCostTime: Int?,
|
||||||
val addonModifiers: Set<AddonModifierDto>,
|
val addonModifiers: Set<AddonModifierDto>,
|
||||||
val addonRequirements: Set<AddonRequirementDto>,
|
val addonRequirement: AddonRequirementDto?,
|
||||||
val icon: String?,
|
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 addon: BuildingAddon? = null
|
||||||
var reference: String? = null
|
var reference: String? = null
|
||||||
var replaceWhenDone: Boolean = false
|
var replaceWhenDone: Boolean = false
|
||||||
var value: Double? = null
|
var value: String? = null
|
||||||
|
|
||||||
fun toDto(): AddonRequirementDto {
|
companion object {
|
||||||
return AddonRequirementDto(
|
val REFERENCE_REQUIREMENT_POP = "requirements\\required_total_pop.lua"
|
||||||
id = id!!,
|
val REFERENCE_REQUIREMENT_ADDON = "requirements\\local_required_addon.lua"
|
||||||
reference = reference,
|
val REFERENCE_GLOBAL_REQUIREMENT_ADDON = "requirements\\global_required_addon.lua"
|
||||||
replaceWhenDone = replaceWhenDone,
|
val REFERENCE_REQUIREMENT_STRUCTURE_EITHER = "requirements\\required_structure_either.lua"
|
||||||
value = value
|
val REFERENCE_REQUIREMENT_STRUCTURE = "requirements\\required_structure.lua"
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.dowstats.data.entities
|
package com.dowstats.data.entities
|
||||||
|
|
||||||
|
import com.dowstats.data.dto.controllers.building.BuildingAddonDto
|
||||||
import com.dowstats.data.dto.controllers.building.BuildingFullDto
|
import com.dowstats.data.dto.controllers.building.BuildingFullDto
|
||||||
import jakarta.persistence.*
|
import jakarta.persistence.*
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ class Building {
|
|||||||
@OneToMany(mappedBy = "building", cascade = [CascadeType.ALL])
|
@OneToMany(mappedBy = "building", cascade = [CascadeType.ALL])
|
||||||
var weapons: MutableSet<BuildingWeapon>? = null
|
var weapons: MutableSet<BuildingWeapon>? = null
|
||||||
|
|
||||||
fun toDto(): BuildingFullDto =
|
fun toDto(buildingAddons: Set<BuildingAddonDto>?): BuildingFullDto =
|
||||||
BuildingFullDto(
|
BuildingFullDto(
|
||||||
id!!,
|
id!!,
|
||||||
race?.toDto(),
|
race?.toDto(),
|
||||||
@ -69,7 +70,7 @@ class Building {
|
|||||||
repairMax,
|
repairMax,
|
||||||
icon,
|
icon,
|
||||||
modId!!,
|
modId!!,
|
||||||
addons?.map { it.toDto() }?.toSet(),
|
buildingAddons,
|
||||||
weapons?.map { it.toWeaponSlotDto() }?.toSet(),
|
weapons?.map { it.toWeaponSlotDto() }?.toSet(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.dowstats.data.entities
|
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.BuildingAddonDto
|
||||||
|
import com.dowstats.data.dto.controllers.building.BuildingAddonShortDto
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import jakarta.persistence.*
|
import jakarta.persistence.*
|
||||||
|
|
||||||
@ -35,8 +37,9 @@ class BuildingAddon {
|
|||||||
var addonRequirements: MutableSet<AddonRequirements>? = null
|
var addonRequirements: MutableSet<AddonRequirements>? = null
|
||||||
|
|
||||||
var icon: String? = null
|
var icon: String? = null
|
||||||
|
var modId: Long? = null
|
||||||
|
|
||||||
fun toDto(): BuildingAddonDto = BuildingAddonDto(
|
fun toDto(addonRequirementDto: AddonRequirementDto?): BuildingAddonDto = BuildingAddonDto(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
description = description,
|
description = description,
|
||||||
@ -48,7 +51,14 @@ class BuildingAddon {
|
|||||||
addonCostSouls = addonCostSouls,
|
addonCostSouls = addonCostSouls,
|
||||||
addonCostTime = addonCostTime,
|
addonCostTime = addonCostTime,
|
||||||
addonModifiers = addonModifiers?.map { it.toDto() }?.toSet() ?: emptySet(),
|
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
|
icon = icon
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -7,4 +7,6 @@ import com.dowstats.data.entities.Race
|
|||||||
import org.springframework.data.jpa.repository.Query
|
import org.springframework.data.jpa.repository.Query
|
||||||
import org.springframework.data.repository.CrudRepository
|
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
|
order by b.race.id desc
|
||||||
""")
|
""")
|
||||||
fun findByModIdAndRace(modId: Long, race: Race?): List<Building>
|
fun findByModIdAndRace(modId: Long, race: Race?): List<Building>
|
||||||
|
|
||||||
|
fun findByModIdAndFilename(modId: Long, fileName: String): Building?
|
||||||
}
|
}
|
||||||
@ -1,8 +1,12 @@
|
|||||||
package com.dowstats.service.datamaps
|
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.BuildingShortDto
|
||||||
import com.dowstats.data.dto.controllers.building.RaceBuildings
|
import com.dowstats.data.dto.controllers.building.RaceBuildings
|
||||||
|
import com.dowstats.data.entities.AddonRequirements
|
||||||
import com.dowstats.data.entities.Building
|
import com.dowstats.data.entities.Building
|
||||||
|
import com.dowstats.data.repositories.AddonRepository
|
||||||
import com.dowstats.data.repositories.BuildingRepository
|
import com.dowstats.data.repositories.BuildingRepository
|
||||||
import com.dowstats.data.repositories.RaceRepository
|
import com.dowstats.data.repositories.RaceRepository
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
@ -11,34 +15,103 @@ import org.springframework.stereotype.Service
|
|||||||
@Service
|
@Service
|
||||||
class DowBuildingMappingService @Autowired constructor(
|
class DowBuildingMappingService @Autowired constructor(
|
||||||
val buildingRepository: BuildingRepository,
|
val buildingRepository: BuildingRepository,
|
||||||
|
val addonRepository: AddonRepository,
|
||||||
val raceRepository: RaceRepository
|
val raceRepository: RaceRepository
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun findBuildingsByMod(modId: Long): List<RaceBuildings> {
|
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())
|
RaceBuildings(raceUnits.key?.toDto() ?: throw Exception("Race is null"), raceUnits.value.toBuildingDto())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findBuildingsByModAndRace(modId: Long, race: String): RaceBuildings {
|
fun findBuildingsByModAndRace(modId: Long, race: String): RaceBuildings {
|
||||||
val buildings = getAllBuildings(modId, race)
|
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())
|
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> =
|
private fun List<Building>.toBuildingDto(): List<BuildingShortDto> =
|
||||||
this.mapNotNull {
|
this.mapNotNull {
|
||||||
val name = it.name ?: it.filename
|
val name = it.name ?: it.filename
|
||||||
val icon = it.icon
|
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.armorType?.name!!,
|
||||||
(it.detectRadius ?: 0) > 0)
|
(it.detectRadius ?: 0) > 0
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getAllBuildings(modId: Long, race: String? = null): List<Building> {
|
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))
|
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
|
@Transactional
|
||||||
fun reloadMod(modId: Long) {
|
fun reloadMod(modId: Long) {
|
||||||
val mod = modRepository.findById(modId).orElseThrow { IllegalArgumentException("Mod not found") }
|
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)
|
val addonIcon = convertIconAndReturnPath(addonRgdData, modFolderData, mod.name)
|
||||||
addon.icon = addonIcon
|
addon.icon = addonIcon
|
||||||
|
addon.modId = mod.id
|
||||||
|
|
||||||
return addon
|
return addon
|
||||||
}
|
}
|
||||||
@ -87,9 +88,14 @@ class BuildingAddonRgdExtractService @Autowired constructor(
|
|||||||
it.addon = addon
|
it.addon = addon
|
||||||
it.reference = rTable.getStringByName("\$REF")
|
it.reference = rTable.getStringByName("\$REF")
|
||||||
it.replaceWhenDone = rTable.getBooleanByName("replace_when_done") == true
|
it.replaceWhenDone = rTable.getBooleanByName("replace_when_done") == true
|
||||||
// TODO - что-то придумать с этим
|
it.value = when(it.reference){
|
||||||
it.value =
|
AddonRequirements.REFERENCE_REQUIREMENT_POP -> rTable.getDoubleByName("population_required").toString()
|
||||||
if (it.reference == "requirements\\required_total_pop.lua") rTable.getDoubleByName("population_required") else null
|
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
|
} 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