feat: API調整
This commit is contained in:
parent
d27057dc89
commit
0f432b0e89
|
|
@ -100,5 +100,5 @@ interface LandsAPI {
|
|||
* @param modifier A function that modifies the land's data
|
||||
* @return true if the land was modified successfully, false if the land doesn't exist
|
||||
*/
|
||||
fun modifyLand(name: String, modifier: (LandData) -> Unit): Boolean
|
||||
fun modifyLand(name: String, modifier: (LandData) -> LandData): Boolean
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class LandsAPIImpl(private val landService: LandService) : LandsAPI {
|
|||
return landService.deleteLand(land.id)
|
||||
}
|
||||
|
||||
override fun modifyLand(name: String, modifier: (LandData) -> Unit): Boolean {
|
||||
override fun modifyLand(name: String, modifier: (LandData) -> LandData): Boolean {
|
||||
val land = landService.findLandsByName(name).firstOrNull() ?: return false
|
||||
return landService.modifyLand(land.id, modifier)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -454,8 +454,9 @@ class LandsCommand(
|
|||
}
|
||||
|
||||
service.modifyLand(land.id) { data ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
action(data.parts as MutableList<Shape>)
|
||||
val mutableParts = data.parts.toMutableList()
|
||||
action(mutableParts)
|
||||
data.copy(parts = mutableParts)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,12 +81,10 @@ class LandService(private val database: Database) {
|
|||
}
|
||||
}
|
||||
|
||||
fun modifyLand(id: Int, modifier: (LandData) -> Unit): Boolean {
|
||||
fun modifyLand(id: Int, modifier: (LandData) -> LandData): Boolean {
|
||||
val land = cache[id] ?: return false
|
||||
val newParts = ArrayList(land.data.parts)
|
||||
val newData = land.data.copy(parts = newParts)
|
||||
|
||||
modifier(newData)
|
||||
val newData = modifier(land.data)
|
||||
|
||||
transaction(database) {
|
||||
LandsTable.update({ LandsTable.id eq id }) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user