mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-04 22:58:29 +08:00
Updated all code that used deprecated Kotlin APIs.
This commit is contained in:
parent
89b88a0a2d
commit
fab1f90975
@ -316,20 +316,20 @@ class LineTokenizer {
|
|||||||
val ident = slice()
|
val ident = slice()
|
||||||
value = ident
|
value = ident
|
||||||
|
|
||||||
if (ident.getCodePointAt(0) !in ('a'.toInt())..('z'.toInt())) {
|
if (ident.getCodePointAt(0) !in 'a'.code..'z'.code) {
|
||||||
type = Token.InvalidIdent
|
type = Token.InvalidIdent
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i in 1 until ident.length) {
|
for (i in 1 until ident.length) {
|
||||||
when (ident.getCodePointAt(i)) {
|
when (ident.getCodePointAt(i)) {
|
||||||
in ('0'.toInt())..('9'.toInt()),
|
in '0'.code..'9'.code,
|
||||||
in ('a'.toInt())..('z'.toInt()),
|
in 'a'.code..'z'.code,
|
||||||
('_').toInt(),
|
'_'.code,
|
||||||
('=').toInt(),
|
'='.code,
|
||||||
('<').toInt(),
|
'<'.code,
|
||||||
('>').toInt(),
|
'>'.code,
|
||||||
('!').toInt(),
|
'!'.code,
|
||||||
-> {
|
-> {
|
||||||
// Valid character.
|
// Valid character.
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ fun assemble(
|
|||||||
val warnings = result.problems.count { it.severity == Severity.Warning }
|
val warnings = result.problems.count { it.severity == Severity.Warning }
|
||||||
val errors = result.problems.count { it.severity == Severity.Error }
|
val errors = result.problems.count { it.severity == Severity.Error }
|
||||||
|
|
||||||
"Assembly finished in ${time.inMilliseconds}ms with $warnings warnings and $errors errors."
|
"Assembly finished in ${time.inWholeMilliseconds}ms with $warnings warnings and $errors errors."
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -43,7 +43,7 @@ class InstructionSegment(
|
|||||||
srcLoc: SegmentSrcLoc = SegmentSrcLoc(mutableListOf()),
|
srcLoc: SegmentSrcLoc = SegmentSrcLoc(mutableListOf()),
|
||||||
) : Segment(SegmentType.Instructions, labels, srcLoc) {
|
) : Segment(SegmentType.Instructions, labels, srcLoc) {
|
||||||
override fun size(dcGcFormat: Boolean): Int =
|
override fun size(dcGcFormat: Boolean): Int =
|
||||||
instructions.sumBy { it.getSize(dcGcFormat) }
|
instructions.sumOf { it.getSize(dcGcFormat) }
|
||||||
|
|
||||||
override fun copy(): InstructionSegment =
|
override fun copy(): InstructionSegment =
|
||||||
InstructionSegment(
|
InstructionSegment(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package world.phantasmal.lib.cursor
|
package world.phantasmal.lib.cursor
|
||||||
|
|
||||||
import kotlin.experimental.and
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
abstract class AbstractWritableCursor
|
abstract class AbstractWritableCursor
|
||||||
@ -42,7 +41,7 @@ protected constructor(protected val offset: Int) : WritableCursor {
|
|||||||
buildString {
|
buildString {
|
||||||
for (i in 0 until maxByteLength) {
|
for (i in 0 until maxByteLength) {
|
||||||
// Use Byte instead of UByte for better KJS perf.
|
// Use Byte instead of UByte for better KJS perf.
|
||||||
val codePoint = (byte().toShort() and 0xFF).toChar()
|
val codePoint = (byte().toInt() and 0xFF).toChar()
|
||||||
|
|
||||||
if (nullTerminated && codePoint == '\u0000') {
|
if (nullTerminated && codePoint == '\u0000') {
|
||||||
if (dropRemaining) {
|
if (dropRemaining) {
|
||||||
@ -65,7 +64,7 @@ protected constructor(protected val offset: Int) : WritableCursor {
|
|||||||
val len = maxByteLength / 2
|
val len = maxByteLength / 2
|
||||||
|
|
||||||
for (i in 0 until len) {
|
for (i in 0 until len) {
|
||||||
val codePoint = short().toChar()
|
val codePoint = short().toInt().toChar()
|
||||||
|
|
||||||
if (nullTerminated && codePoint == '\u0000') {
|
if (nullTerminated && codePoint == '\u0000') {
|
||||||
if (dropRemaining) {
|
if (dropRemaining) {
|
||||||
@ -151,7 +150,7 @@ protected constructor(protected val offset: Int) : WritableCursor {
|
|||||||
val len = min(byteLength, str.length)
|
val len = min(byteLength, str.length)
|
||||||
|
|
||||||
for (i in 0 until len) {
|
for (i in 0 until len) {
|
||||||
writeByte(str[i].toByte())
|
writeByte(str[i].code.toByte())
|
||||||
}
|
}
|
||||||
|
|
||||||
val padLen = byteLength - len
|
val padLen = byteLength - len
|
||||||
@ -170,7 +169,7 @@ protected constructor(protected val offset: Int) : WritableCursor {
|
|||||||
val len = min(maxLen, str.length)
|
val len = min(maxLen, str.length)
|
||||||
|
|
||||||
for (i in 0 until len) {
|
for (i in 0 until len) {
|
||||||
writeShort(str[i].toShort())
|
writeShort(str[i].code.toShort())
|
||||||
}
|
}
|
||||||
|
|
||||||
val padLen = maxLen - len
|
val padLen = maxLen - len
|
||||||
|
@ -94,13 +94,15 @@ fun parseDat(cursor: Cursor): DatFile {
|
|||||||
3 -> parseEvents(entitiesCursor, areaId, events)
|
3 -> parseEvents(entitiesCursor, areaId, events)
|
||||||
else -> {
|
else -> {
|
||||||
// Unknown entity types 4 and 5 (challenge mode).
|
// Unknown entity types 4 and 5 (challenge mode).
|
||||||
unknowns.add(DatUnknown(
|
unknowns.add(
|
||||||
entityType,
|
DatUnknown(
|
||||||
totalSize,
|
entityType,
|
||||||
areaId,
|
totalSize,
|
||||||
entitiesSize,
|
areaId,
|
||||||
data = cursor.byteArray(entitiesSize),
|
entitiesSize,
|
||||||
))
|
data = cursor.byteArray(entitiesSize),
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,10 +131,12 @@ private fun parseEntities(
|
|||||||
val entityCount = cursor.size / entitySize
|
val entityCount = cursor.size / entitySize
|
||||||
|
|
||||||
repeat(entityCount) {
|
repeat(entityCount) {
|
||||||
entities.add(DatEntity(
|
entities.add(
|
||||||
areaId,
|
DatEntity(
|
||||||
data = cursor.buffer(entitySize),
|
areaId,
|
||||||
))
|
data = cursor.buffer(entitySize),
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,15 +173,17 @@ private fun parseEvents(cursor: Cursor, areaId: Int, events: MutableList<DatEven
|
|||||||
mutableListOf()
|
mutableListOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
events.add(DatEvent(
|
events.add(
|
||||||
id,
|
DatEvent(
|
||||||
sectionId,
|
id,
|
||||||
wave,
|
sectionId,
|
||||||
delay,
|
wave,
|
||||||
actions,
|
delay,
|
||||||
areaId,
|
actions,
|
||||||
unknown,
|
areaId,
|
||||||
))
|
unknown,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor.position != actionsOffset) {
|
if (cursor.position != actionsOffset) {
|
||||||
@ -212,25 +218,33 @@ private fun parseEventActions(cursor: Cursor): MutableList<DatEventAction> {
|
|||||||
(1).toByte() -> break@outer
|
(1).toByte() -> break@outer
|
||||||
|
|
||||||
EVENT_ACTION_SPAWN_NPCS ->
|
EVENT_ACTION_SPAWN_NPCS ->
|
||||||
actions.add(DatEventAction.SpawnNpcs(
|
actions.add(
|
||||||
sectionId = cursor.short(),
|
DatEventAction.SpawnNpcs(
|
||||||
appearFlag = cursor.short(),
|
sectionId = cursor.short(),
|
||||||
))
|
appearFlag = cursor.short(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
EVENT_ACTION_UNLOCK ->
|
EVENT_ACTION_UNLOCK ->
|
||||||
actions.add(DatEventAction.Unlock(
|
actions.add(
|
||||||
doorId = cursor.short(),
|
DatEventAction.Unlock(
|
||||||
))
|
doorId = cursor.short(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
EVENT_ACTION_LOCK ->
|
EVENT_ACTION_LOCK ->
|
||||||
actions.add(DatEventAction.Lock(
|
actions.add(
|
||||||
doorId = cursor.short(),
|
DatEventAction.Lock(
|
||||||
))
|
doorId = cursor.short(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
EVENT_ACTION_TRIGGER_EVENT ->
|
EVENT_ACTION_TRIGGER_EVENT ->
|
||||||
actions.add(DatEventAction.TriggerEvent(
|
actions.add(
|
||||||
eventId = cursor.int(),
|
DatEventAction.TriggerEvent(
|
||||||
))
|
eventId = cursor.int(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
logger.warn { "Unexpected event action type ${type}." }
|
logger.warn { "Unexpected event action type ${type}." }
|
||||||
@ -246,7 +260,7 @@ fun writeDat(dat: DatFile): Buffer {
|
|||||||
val buffer = Buffer.withCapacity(
|
val buffer = Buffer.withCapacity(
|
||||||
dat.objs.size * (16 + OBJECT_BYTE_SIZE) +
|
dat.objs.size * (16 + OBJECT_BYTE_SIZE) +
|
||||||
dat.npcs.size * (16 + NPC_BYTE_SIZE) +
|
dat.npcs.size * (16 + NPC_BYTE_SIZE) +
|
||||||
dat.unknowns.sumBy { it.totalSize },
|
dat.unknowns.sumOf { it.totalSize },
|
||||||
endianness = Endianness.Little,
|
endianness = Endianness.Little,
|
||||||
)
|
)
|
||||||
val cursor = buffer.cursor()
|
val cursor = buffer.cursor()
|
||||||
|
@ -159,7 +159,7 @@ fun parseQstToQuest(cursor: Cursor, lenient: Boolean = false): PwResult<QuestDat
|
|||||||
var binFile: QstContainedFile? = null
|
var binFile: QstContainedFile? = null
|
||||||
|
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val fileName = file.filename.trim().toLowerCase()
|
val fileName = file.filename.trim().lowercase()
|
||||||
|
|
||||||
if (fileName.endsWith(".dat")) {
|
if (fileName.endsWith(".dat")) {
|
||||||
datFile = file
|
datFile = file
|
||||||
|
@ -79,7 +79,7 @@ actual class Buffer private constructor(
|
|||||||
val len = maxByteLength / 2
|
val len = maxByteLength / 2
|
||||||
|
|
||||||
for (i in 0 until len) {
|
for (i in 0 until len) {
|
||||||
val codePoint = getShort(offset + i * 2).toChar()
|
val codePoint = getShort(offset + i * 2).toInt().toChar()
|
||||||
|
|
||||||
if (nullTerminated && codePoint == '0') {
|
if (nullTerminated && codePoint == '0') {
|
||||||
break
|
break
|
||||||
@ -211,7 +211,7 @@ actual class Buffer private constructor(
|
|||||||
val buf = withSize(str.length, endianness)
|
val buf = withSize(str.length, endianness)
|
||||||
|
|
||||||
for (i in 0 until buf.size) {
|
for (i in 0 until buf.size) {
|
||||||
buf.setByte(i, str[i].toByte())
|
buf.setByte(i, str[i].code.toByte())
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package world.phantasmal.testUtils
|
package world.phantasmal.testUtils
|
||||||
|
|
||||||
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
|
|
||||||
internal actual fun testAsync(block: suspend () -> Unit): dynamic =
|
internal actual fun testAsync(block: suspend () -> Unit): dynamic =
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
GlobalScope.promise { block() }
|
GlobalScope.promise { block() }
|
||||||
|
|
||||||
internal actual fun canExecuteSlowTests(): Boolean = false
|
internal actual fun canExecuteSlowTests(): Boolean = false
|
||||||
|
@ -171,7 +171,7 @@ class AsmAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCompletions(requestId: Int, lineNo: Int, col: Int): Response.GetCompletions {
|
fun getCompletions(requestId: Int, lineNo: Int, col: Int): Response.GetCompletions {
|
||||||
val text = getLine(lineNo)?.take(col)?.trim()?.toLowerCase() ?: ""
|
val text = getLine(lineNo)?.take(col)?.trim()?.lowercase() ?: ""
|
||||||
|
|
||||||
val completions: List<CompletionItem> = when {
|
val completions: List<CompletionItem> = when {
|
||||||
KEYWORD_REGEX.matches(text) -> KEYWORD_SUGGESTIONS
|
KEYWORD_REGEX.matches(text) -> KEYWORD_SUGGESTIONS
|
||||||
|
@ -80,7 +80,7 @@ class AsmServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.trace {
|
logger.trace {
|
||||||
"Processed ${messages.size} assembly changes in ${time.inMilliseconds}ms."
|
"Processed ${messages.size} assembly changes in ${time.inWholeMilliseconds}ms."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ class AsmServer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace { "Processed ${message::class.simpleName} in ${time.inMilliseconds}ms." }
|
logger.trace { "Processed ${message::class.simpleName} in ${time.inWholeMilliseconds}ms." }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processRequest(message: Request) {
|
private fun processRequest(message: Request) {
|
||||||
|
@ -28,10 +28,10 @@ dependencies {
|
|||||||
implementation(project(":webui"))
|
implementation(project(":webui"))
|
||||||
implementation(project(":web:shared"))
|
implementation(project(":web:shared"))
|
||||||
|
|
||||||
implementation("io.ktor:ktor-client-core-js:$ktorVersion")
|
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
||||||
implementation("io.ktor:ktor-client-serialization-js:$ktorVersion")
|
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1")
|
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.0")
|
||||||
implementation(npm("golden-layout", "^1.5.9"))
|
implementation(npm("golden-layout", "^1.5.9"))
|
||||||
// Can't upgrade monaco-editor until https://github.com/microsoft/monaco-editor/issues/2466 is
|
// Can't upgrade monaco-editor until https://github.com/microsoft/monaco-editor/issues/2466 is
|
||||||
// fixed.
|
// fixed.
|
||||||
|
@ -65,7 +65,7 @@ class Application(
|
|||||||
{
|
{
|
||||||
MainContentWidget(
|
MainContentWidget(
|
||||||
mainContentController,
|
mainContentController,
|
||||||
tools.map { it.toolType to it::initialize }.toMap()
|
tools.associate { it.toolType to it::initialize },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -83,7 +83,7 @@ class Application(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun keydown(e: KeyboardEvent) {
|
private fun keydown(e: KeyboardEvent) {
|
||||||
if (e.ctrlKey && !e.altKey && e.key.toUpperCase() == "Z") {
|
if (e.ctrlKey && !e.altKey && e.key.uppercase() == "Z") {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ class PwToolButton(
|
|||||||
private val toggled: Observable<Boolean>,
|
private val toggled: Observable<Boolean>,
|
||||||
private val onMouseDown: () -> Unit,
|
private val onMouseDown: () -> Unit,
|
||||||
) : Control(visible = trueCell(), enabled = trueCell(), tooltip = nullCell()) {
|
) : Control(visible = trueCell(), enabled = trueCell(), tooltip = nullCell()) {
|
||||||
private val inputId = "pw-application-pw-tool-button-${tool.name.toLowerCase()}"
|
private val inputId = "pw-application-pw-tool-button-${tool.name.lowercase()}"
|
||||||
|
|
||||||
override fun Node.createElement() =
|
override fun Node.createElement() =
|
||||||
span {
|
span {
|
||||||
|
@ -239,7 +239,7 @@ class UiStore(private val applicationUrl: ApplicationUrl) : Store() {
|
|||||||
if (e.ctrlKey) bindingParts.add("Ctrl")
|
if (e.ctrlKey) bindingParts.add("Ctrl")
|
||||||
if (e.altKey) bindingParts.add("Alt")
|
if (e.altKey) bindingParts.add("Alt")
|
||||||
if (e.shiftKey) bindingParts.add("Shift")
|
if (e.shiftKey) bindingParts.add("Shift")
|
||||||
bindingParts.add(e.key.toUpperCase())
|
bindingParts.add(e.key.uppercase())
|
||||||
|
|
||||||
val binding = bindingParts.joinToString("-")
|
val binding = bindingParts.joinToString("-")
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import world.phantasmal.webui.controllers.Column
|
|||||||
import world.phantasmal.webui.controllers.TableController
|
import world.phantasmal.webui.controllers.TableController
|
||||||
import world.phantasmal.webui.toRoundedString
|
import world.phantasmal.webui.toRoundedString
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
|
import kotlin.time.DurationUnit.HOURS
|
||||||
|
|
||||||
class OptimizationResultController(
|
class OptimizationResultController(
|
||||||
huntOptimizerStore: HuntOptimizerStore,
|
huntOptimizerStore: HuntOptimizerStore,
|
||||||
@ -28,7 +29,7 @@ class OptimizationResultController(
|
|||||||
totalTime += optimalMethod.totalTime
|
totalTime += optimalMethod.totalTime
|
||||||
}
|
}
|
||||||
|
|
||||||
listOf<Column<OptimalMethodModel>>(
|
listOf(
|
||||||
Column(
|
Column(
|
||||||
key = DIFF_COL,
|
key = DIFF_COL,
|
||||||
title = "Difficulty",
|
title = "Difficulty",
|
||||||
@ -70,13 +71,13 @@ class OptimizationResultController(
|
|||||||
title = "Total Hours",
|
title = "Total Hours",
|
||||||
width = 60,
|
width = 60,
|
||||||
textAlign = "right",
|
textAlign = "right",
|
||||||
tooltip = { it.totalTime.inHours.toString() },
|
tooltip = { it.totalTime.toDouble(HOURS).toString() },
|
||||||
footer = cell(totalTime.inHours.toRoundedString(1)),
|
footer = cell(totalTime.toDouble(HOURS).toRoundedString(1)),
|
||||||
footerTooltip = cell(totalTime.inHours.toString()),
|
footerTooltip = cell(totalTime.toDouble(HOURS).toString()),
|
||||||
),
|
),
|
||||||
*Array(result.wantedItems.size) { index ->
|
*Array(result.wantedItems.size) { index ->
|
||||||
val wanted = result.wantedItems[index]
|
val wanted = result.wantedItems[index]
|
||||||
val totalCount = result.optimalMethods.sumByDouble {
|
val totalCount = result.optimalMethods.sumOf {
|
||||||
it.itemTypeIdToCount[wanted.id] ?: .0
|
it.itemTypeIdToCount[wanted.id] ?: .0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@ package world.phantasmal.web.huntOptimizer.persistence
|
|||||||
import world.phantasmal.web.core.models.Server
|
import world.phantasmal.web.core.models.Server
|
||||||
import world.phantasmal.web.core.persistence.Persister
|
import world.phantasmal.web.core.persistence.Persister
|
||||||
import world.phantasmal.web.huntOptimizer.models.HuntMethodModel
|
import world.phantasmal.web.huntOptimizer.models.HuntMethodModel
|
||||||
import kotlin.time.hours
|
import kotlin.time.Duration
|
||||||
|
import kotlin.time.DurationUnit.HOURS
|
||||||
|
|
||||||
class HuntMethodPersister : Persister() {
|
class HuntMethodPersister : Persister() {
|
||||||
suspend fun persistMethodUserTimes(huntMethods: List<HuntMethodModel>, server: Server) {
|
suspend fun persistMethodUserTimes(huntMethods: List<HuntMethodModel>, server: Server) {
|
||||||
@ -11,7 +12,7 @@ class HuntMethodPersister : Persister() {
|
|||||||
|
|
||||||
for (method in huntMethods) {
|
for (method in huntMethods) {
|
||||||
method.userTime.value?.let { userTime ->
|
method.userTime.value?.let { userTime ->
|
||||||
userTimes[method.id] = userTime.inHours
|
userTimes[method.id] = userTime.toDouble(HOURS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ class HuntMethodPersister : Persister() {
|
|||||||
loadForServer<Map<String, Double>>(server, METHOD_USER_TIMES_KEY)?.let { userTimes ->
|
loadForServer<Map<String, Double>>(server, METHOD_USER_TIMES_KEY)?.let { userTimes ->
|
||||||
for (method in huntMethods) {
|
for (method in huntMethods) {
|
||||||
userTimes[method.id]?.let { userTime ->
|
userTimes[method.id]?.let { userTime ->
|
||||||
method.setUserTime(userTime.hours)
|
method.setUserTime(Duration.hours(userTime))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import kotlin.collections.component1
|
|||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.minutes
|
|
||||||
|
|
||||||
class HuntMethodStore(
|
class HuntMethodStore(
|
||||||
private val uiStore: UiStore,
|
private val uiStore: UiStore,
|
||||||
@ -109,8 +108,8 @@ class HuntMethodStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DEFAULT_DURATION = 30.minutes
|
private val DEFAULT_DURATION = Duration.minutes(30)
|
||||||
private val DEFAULT_GOVERNMENT_TEST_DURATION = 45.minutes
|
private val DEFAULT_GOVERNMENT_TEST_DURATION = Duration.minutes(45)
|
||||||
private val DEFAULT_LARGE_ENEMY_COUNT_DURATION = 45.minutes
|
private val DEFAULT_LARGE_ENEMY_COUNT_DURATION = Duration.minutes(45)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import world.phantasmal.web.shared.dto.ItemType
|
|||||||
import world.phantasmal.web.shared.dto.SectionId
|
import world.phantasmal.web.shared.dto.SectionId
|
||||||
import world.phantasmal.webui.obj
|
import world.phantasmal.webui.obj
|
||||||
import world.phantasmal.webui.stores.Store
|
import world.phantasmal.webui.stores.Store
|
||||||
|
import kotlin.time.DurationUnit.HOURS
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
@ -233,9 +234,8 @@ class HuntOptimizerStore(
|
|||||||
for (sectionId in SectionId.VALUES) {
|
for (sectionId in SectionId.VALUES) {
|
||||||
// Will contain an entry per wanted item dropped by enemies in this method/
|
// Will contain an entry per wanted item dropped by enemies in this method/
|
||||||
// difficulty/section ID combo.
|
// difficulty/section ID combo.
|
||||||
val variable: dynamic = obj {
|
val time = method.time.value.toDouble(HOURS)
|
||||||
time = method.time.value.inHours
|
val variable: dynamic = obj { this.time = time }
|
||||||
}
|
|
||||||
// Only add the variable if the method provides at least 1 item we want.
|
// Only add the variable if the method provides at least 1 item we want.
|
||||||
var addVariable = false
|
var addVariable = false
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import world.phantasmal.webui.formatAsHoursAndMinutes
|
|||||||
import world.phantasmal.webui.toRoundedString
|
import world.phantasmal.webui.toRoundedString
|
||||||
import world.phantasmal.webui.widgets.Table
|
import world.phantasmal.webui.widgets.Table
|
||||||
import world.phantasmal.webui.widgets.Widget
|
import world.phantasmal.webui.widgets.Widget
|
||||||
|
import kotlin.time.DurationUnit.HOURS
|
||||||
|
|
||||||
class OptimizationResultWidget(private val ctrl: OptimizationResultController) : Widget() {
|
class OptimizationResultWidget(private val ctrl: OptimizationResultController) : Widget() {
|
||||||
override fun Node.createElement() =
|
override fun Node.createElement() =
|
||||||
@ -26,41 +27,45 @@ class OptimizationResultWidget(private val ctrl: OptimizationResultController) :
|
|||||||
|
|
||||||
h2 { textContent = "Ideal Combination of Methods" }
|
h2 { textContent = "Ideal Combination of Methods" }
|
||||||
|
|
||||||
addWidget(Table(
|
addWidget(
|
||||||
ctrl = ctrl,
|
Table(
|
||||||
className = "pw-hunt-optimizer-optimization-result-table",
|
ctrl = ctrl,
|
||||||
renderCell = { optimalMethod, column ->
|
className = "pw-hunt-optimizer-optimization-result-table",
|
||||||
when (column.key) {
|
renderCell = { optimalMethod, column ->
|
||||||
DIFF_COL -> optimalMethod.difficulty
|
when (column.key) {
|
||||||
METHOD_COL -> optimalMethod.name
|
DIFF_COL -> optimalMethod.difficulty
|
||||||
EPISODE_COL -> optimalMethod.episode
|
METHOD_COL -> optimalMethod.name
|
||||||
SECTION_ID_COL -> dom {
|
EPISODE_COL -> optimalMethod.episode
|
||||||
span {
|
SECTION_ID_COL -> dom {
|
||||||
style.display = "flex"
|
span {
|
||||||
|
style.display = "flex"
|
||||||
|
|
||||||
for (sectionId in optimalMethod.sectionIds) {
|
for (sectionId in optimalMethod.sectionIds) {
|
||||||
sectionIdIcon(sectionId, size = 17)
|
sectionIdIcon(sectionId, size = 17)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TIME_PER_RUN_COL -> optimalMethod.methodTime.formatAsHoursAndMinutes()
|
||||||
|
RUNS_COL -> optimalMethod.runs.toRoundedString(1)
|
||||||
|
TOTAL_TIME_COL ->
|
||||||
|
optimalMethod.totalTime.toDouble(HOURS).toRoundedString(1)
|
||||||
|
else -> {
|
||||||
|
optimalMethod.itemTypeIdToCount[column.key.toInt()]
|
||||||
|
?.toRoundedString(2)
|
||||||
|
?: ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TIME_PER_RUN_COL -> optimalMethod.methodTime.formatAsHoursAndMinutes()
|
},
|
||||||
RUNS_COL -> optimalMethod.runs.toRoundedString(1)
|
)
|
||||||
TOTAL_TIME_COL -> optimalMethod.totalTime.inHours.toRoundedString(1)
|
)
|
||||||
else -> {
|
|
||||||
optimalMethod.itemTypeIdToCount[column.key.toInt()]
|
|
||||||
?.toRoundedString(2)
|
|
||||||
?: ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
init {
|
init {
|
||||||
@Suppress("CssUnusedSymbol", "CssUnresolvedCustomProperty")
|
@Suppress("CssUnusedSymbol", "CssUnresolvedCustomProperty")
|
||||||
// language=css
|
// language=css
|
||||||
style("""
|
style(
|
||||||
|
"""
|
||||||
.pw-hunt-optimizer-optimization-result {
|
.pw-hunt-optimizer-optimization-result {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -74,7 +79,8 @@ class OptimizationResultWidget(private val ctrl: OptimizationResultController) :
|
|||||||
border-top: var(--pw-border);
|
border-top: var(--pw-border);
|
||||||
border-left: var(--pw-border);
|
border-left: var(--pw-border);
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.*
|
import world.phantasmal.web.externals.monacoEditor.*
|
||||||
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
||||||
@ -8,14 +7,15 @@ import world.phantasmal.web.shared.messages.CompletionItemType
|
|||||||
import world.phantasmal.webui.obj
|
import world.phantasmal.webui.obj
|
||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
|
|
||||||
class AsmCompletionItemProvider(private val analyser: AsmAnalyser) : CompletionItemProvider {
|
class AsmCompletionItemProvider(private val analyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), CompletionItemProvider {
|
||||||
override fun provideCompletionItems(
|
override fun provideCompletionItems(
|
||||||
model: ITextModel,
|
model: ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
context: CompletionContext,
|
context: CompletionContext,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<CompletionList> =
|
): Promise<CompletionList> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
val completions = analyser.getCompletions(
|
val completions = analyser.getCompletions(
|
||||||
position.lineNumber,
|
position.lineNumber,
|
||||||
position.column,
|
position.column,
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.*
|
import world.phantasmal.web.externals.monacoEditor.*
|
||||||
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
||||||
import world.phantasmal.webui.obj
|
import world.phantasmal.webui.obj
|
||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
|
|
||||||
class AsmDefinitionProvider(private val analyser: AsmAnalyser) : DefinitionProvider {
|
class AsmDefinitionProvider(private val analyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), DefinitionProvider {
|
||||||
override fun provideDefinition(
|
override fun provideDefinition(
|
||||||
model: ITextModel,
|
model: ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<Array<LocationLink>?> =
|
): Promise<Array<LocationLink>?> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
val defs = analyser.getDefinition(position.lineNumber, position.column)
|
val defs = analyser.getDefinition(position.lineNumber, position.column)
|
||||||
|
|
||||||
Array(defs.size) {
|
Array(defs.size) {
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.*
|
import world.phantasmal.web.externals.monacoEditor.*
|
||||||
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
||||||
import world.phantasmal.webui.obj
|
import world.phantasmal.webui.obj
|
||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
|
|
||||||
class AsmDocumentHighlightProvider(private val analyser: AsmAnalyser) : DocumentHighlightProvider {
|
class AsmDocumentHighlightProvider(private val analyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), DocumentHighlightProvider {
|
||||||
override fun provideDocumentHighlights(
|
override fun provideDocumentHighlights(
|
||||||
model: ITextModel,
|
model: ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<Array<DocumentHighlight>> =
|
): Promise<Array<DocumentHighlight>> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
val highlights = analyser.getHighlights(position.lineNumber, position.column)
|
val highlights = analyser.getHighlights(position.lineNumber, position.column)
|
||||||
|
|
||||||
Array(highlights.size) {
|
Array(highlights.size) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.CancellationToken
|
import world.phantasmal.web.externals.monacoEditor.CancellationToken
|
||||||
import world.phantasmal.web.externals.monacoEditor.DocumentSymbol
|
import world.phantasmal.web.externals.monacoEditor.DocumentSymbol
|
||||||
@ -10,14 +9,15 @@ import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
|||||||
import world.phantasmal.webui.obj
|
import world.phantasmal.webui.obj
|
||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
|
|
||||||
class AsmDocumentSymbolProvider(private val asmAnalyser: AsmAnalyser) : DocumentSymbolProvider {
|
class AsmDocumentSymbolProvider(private val asmAnalyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), DocumentSymbolProvider {
|
||||||
override val displayName: String? = null
|
override val displayName: String? = null
|
||||||
|
|
||||||
override fun provideDocumentSymbols(
|
override fun provideDocumentSymbols(
|
||||||
model: ITextModel,
|
model: ITextModel,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<Array<DocumentSymbol>> =
|
): Promise<Array<DocumentSymbol>> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
val labels = asmAnalyser.getLabels()
|
val labels = asmAnalyser.getLabels()
|
||||||
|
|
||||||
Array(labels.size) { index ->
|
Array(labels.size) { index ->
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.CancellationToken
|
import world.phantasmal.web.externals.monacoEditor.CancellationToken
|
||||||
import world.phantasmal.web.externals.monacoEditor.HoverProvider
|
import world.phantasmal.web.externals.monacoEditor.HoverProvider
|
||||||
@ -11,13 +10,14 @@ import world.phantasmal.webui.obj
|
|||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.Hover as MonacoHover
|
import world.phantasmal.web.externals.monacoEditor.Hover as MonacoHover
|
||||||
|
|
||||||
class AsmHoverProvider(private val analyser: AsmAnalyser) : HoverProvider {
|
class AsmHoverProvider(private val analyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), HoverProvider {
|
||||||
override fun provideHover(
|
override fun provideHover(
|
||||||
model: ITextModel,
|
model: ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
): Promise<MonacoHover?> =
|
): Promise<MonacoHover?> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
analyser.getHover(position.lineNumber, position.column)?.let { hover ->
|
analyser.getHover(position.lineNumber, position.column)?.let { hover ->
|
||||||
obj<MonacoHover> {
|
obj<MonacoHover> {
|
||||||
contents = Array(hover.contents.size) { i ->
|
contents = Array(hover.contents.size) { i ->
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package world.phantasmal.web.questEditor.asm.monaco
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.promise
|
import kotlinx.coroutines.promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.*
|
import world.phantasmal.web.externals.monacoEditor.*
|
||||||
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
import world.phantasmal.web.questEditor.asm.AsmAnalyser
|
||||||
@ -8,7 +7,8 @@ import world.phantasmal.webui.obj
|
|||||||
import kotlin.js.Promise
|
import kotlin.js.Promise
|
||||||
import world.phantasmal.web.externals.monacoEditor.SignatureHelp as MonacoSigHelp
|
import world.phantasmal.web.externals.monacoEditor.SignatureHelp as MonacoSigHelp
|
||||||
|
|
||||||
class AsmSignatureHelpProvider(private val analyser: AsmAnalyser) : SignatureHelpProvider {
|
class AsmSignatureHelpProvider(private val analyser: AsmAnalyser) :
|
||||||
|
MonacoProvider(), SignatureHelpProvider {
|
||||||
override val signatureHelpTriggerCharacters: Array<String> =
|
override val signatureHelpTriggerCharacters: Array<String> =
|
||||||
arrayOf(" ", ",")
|
arrayOf(" ", ",")
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class AsmSignatureHelpProvider(private val analyser: AsmAnalyser) : SignatureHel
|
|||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
context: SignatureHelpContext,
|
context: SignatureHelpContext,
|
||||||
): Promise<SignatureHelpResult?> =
|
): Promise<SignatureHelpResult?> =
|
||||||
GlobalScope.promise {
|
scope.promise {
|
||||||
analyser.getSignatureHelp(position.lineNumber, position.column)
|
analyser.getSignatureHelp(position.lineNumber, position.column)
|
||||||
?.let { sigHelp ->
|
?.let { sigHelp ->
|
||||||
val monacoSigHelp = obj<MonacoSigHelp> {
|
val monacoSigHelp = obj<MonacoSigHelp> {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package world.phantasmal.web.questEditor.asm.monaco
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
|
||||||
|
abstract class MonacoProvider {
|
||||||
|
protected val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||||
|
}
|
@ -82,7 +82,7 @@ class ViewerToolbarController(private val store: ViewerStore) : Controller() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val extension = file.extension()?.toLowerCase()
|
val extension = file.extension()?.lowercase()
|
||||||
|
|
||||||
val cursor = file.cursor(Endianness.Little)
|
val cursor = file.cursor(Endianness.Little)
|
||||||
var fileResult: PwResult<*>
|
var fileResult: PwResult<*>
|
||||||
|
@ -6,7 +6,6 @@ import world.phantasmal.observable.cell.nullCell
|
|||||||
import world.phantasmal.observable.cell.trueCell
|
import world.phantasmal.observable.cell.trueCell
|
||||||
import world.phantasmal.webui.formatAsHoursAndMinutes
|
import world.phantasmal.webui.formatAsHoursAndMinutes
|
||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlin.time.minutes
|
|
||||||
|
|
||||||
class DurationInput(
|
class DurationInput(
|
||||||
visible: Cell<Boolean> = trueCell(),
|
visible: Cell<Boolean> = trueCell(),
|
||||||
@ -43,11 +42,11 @@ class DurationInput(
|
|||||||
val minutes = minutesStr.toIntOrNull()
|
val minutes = minutesStr.toIntOrNull()
|
||||||
|
|
||||||
if (hours != null && minutes != null) {
|
if (hours != null && minutes != null) {
|
||||||
return (hours * 60 + minutes).minutes
|
return Duration.minutes(hours * 60 + minutes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.value.toIntOrNull()?.minutes ?: Duration.ZERO
|
return input.value.toIntOrNull()?.let(Duration::minutes) ?: Duration.ZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setInputValue(input: HTMLInputElement, value: Duration) {
|
override fun setInputValue(input: HTMLInputElement, value: Duration) {
|
||||||
@ -58,11 +57,13 @@ class DurationInput(
|
|||||||
init {
|
init {
|
||||||
@Suppress("CssUnusedSymbol")
|
@Suppress("CssUnusedSymbol")
|
||||||
// language=css
|
// language=css
|
||||||
style("""
|
style(
|
||||||
|
"""
|
||||||
.pw-duration-input-inner {
|
.pw-duration-input-inner {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user