-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
643 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
app/src/main/java/com/aliernfrog/lactool/impl/laclib/MapEditorState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.aliernfrog.lactool.impl.laclib | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.aliernfrog.laclib.data.LACMapDownloadableMaterial | ||
import com.aliernfrog.laclib.data.LACMapObject | ||
import com.aliernfrog.laclib.enum.LACMapType | ||
import com.aliernfrog.laclib.map.LACMapEditor | ||
|
||
class MapEditorState( | ||
val editor: LACMapEditor | ||
) { | ||
private var _serverName by mutableStateOf(editor.serverName) | ||
var serverName: String? | ||
get() = _serverName | ||
set(value) { | ||
_serverName = value | ||
editor.serverName = value | ||
} | ||
|
||
private var _mapType by mutableStateOf(editor.mapType) | ||
var mapType: LACMapType? | ||
get() = _mapType | ||
set(value) { | ||
_mapType = value | ||
editor.mapType = value | ||
} | ||
|
||
private var _mapRoles by mutableStateOf(editor.mapRoles?.toList()) | ||
var mapRoles: List<String>? | ||
get() = _mapRoles | ||
set(value) { | ||
_mapRoles = value | ||
editor.mapRoles = value?.toMutableList() | ||
} | ||
|
||
private var _mapOptions by mutableStateOf(editor.mapOptions.map { MutableMapOption(it) }) | ||
var mapOptions: List<MutableMapOption> | ||
get() = _mapOptions | ||
set(value) { | ||
_mapOptions = value | ||
editor.mapOptions = value.map { it.toImmutable() }.toMutableList() | ||
} | ||
|
||
fun pushMapOptionsState() { | ||
editor.mapOptions = mapOptions.map { it.toImmutable() }.toMutableList() | ||
} | ||
|
||
private var _replaceableObjects by mutableStateOf(editor.replaceableObjects.toList()) | ||
var replaceableObjects: List<LACMapObject> | ||
get() = _replaceableObjects | ||
set(value) { | ||
_replaceableObjects = value | ||
editor.replaceableObjects = value.toMutableList() | ||
} | ||
|
||
private var _downloadableMaterials by mutableStateOf(editor.downloadableMaterials.toList()) | ||
var downloadableMaterials: List<LACMapDownloadableMaterial> | ||
get() = _downloadableMaterials | ||
set(value) { | ||
_downloadableMaterials = value | ||
editor.downloadableMaterials = value.toMutableList() | ||
} | ||
|
||
fun replaceOldObjects(): Int { | ||
val replaced = editor.replaceOldObjects() | ||
_replaceableObjects = editor.replaceableObjects.toList() | ||
return replaced | ||
} | ||
|
||
fun addRole( | ||
role: String, | ||
onIllegalChar: (String) -> Unit, | ||
onSuccess: () -> Unit | ||
) { | ||
editor.addRole( | ||
role = role, | ||
onIllegalChar = onIllegalChar, | ||
onSuccess = onSuccess | ||
) | ||
_mapRoles = editor.mapRoles?.toList() | ||
} | ||
|
||
fun deleteRole(role: String) { | ||
editor.deleteRole(role) | ||
_mapRoles = editor.mapRoles?.toList() | ||
} | ||
|
||
fun removeDownloadableMaterial(url: String): Int? { | ||
val removed = editor.removeDownloadableMaterial(url) | ||
_downloadableMaterials = editor.downloadableMaterials.toList() | ||
return removed | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/aliernfrog/lactool/impl/laclib/MapMergerState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.aliernfrog.lactool.impl.laclib | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.aliernfrog.laclib.map.LACMapMerger | ||
|
||
class MapMergerState( | ||
private val merger: LACMapMerger | ||
) { | ||
var mapsToMerge by mutableStateOf(merger.mapsToMerge.map { MutableMapToMerge(it) }) | ||
private set | ||
|
||
private fun pullMapsState() { | ||
mapsToMerge = merger.mapsToMerge.map { MutableMapToMerge(it) } | ||
} | ||
|
||
fun pushMapsState() { | ||
merger.mapsToMerge = mapsToMerge.map { it.toImmutable() }.toMutableList() | ||
} | ||
|
||
fun addMap(mapName: String, content: String) { | ||
merger.addMap(mapName, content) | ||
pullMapsState() | ||
} | ||
|
||
fun removeMap(index: Int) { | ||
merger.mapsToMerge.removeAt(index) | ||
pullMapsState() | ||
} | ||
|
||
fun clearMaps() { | ||
merger.mapsToMerge.clear() | ||
pullMapsState() | ||
} | ||
|
||
fun makeMapBase(index: Int) { | ||
merger.makeMapBase(index) | ||
pullMapsState() | ||
} | ||
|
||
fun mergeMaps(onNoEnoughMaps: () -> Unit) = merger.mergeMaps( | ||
onNoEnoughMaps = onNoEnoughMaps | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/aliernfrog/lactool/impl/laclib/MutableMapOption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.aliernfrog.lactool.impl.laclib | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.aliernfrog.laclib.data.LACMapOption | ||
|
||
class MutableMapOption(option: LACMapOption) { | ||
val type = option.type | ||
val label = option.label | ||
var value by mutableStateOf(option.value) | ||
val line = option.line | ||
|
||
fun toImmutable() = LACMapOption( | ||
type = type, | ||
label = label, | ||
value = value, | ||
line = line | ||
) | ||
} |
Oops, something went wrong.