Ray Rahke
02/21/2024, 9:15 PMval x = 7
fn(object { val x = x })
to
val x = 7
fn(object { x })
hfhbd
02/22/2024, 6:31 AMRay Rahke
02/22/2024, 7:16 AMRay Rahke
02/22/2024, 7:17 AMRay Rahke
02/22/2024, 7:17 AMSzymon Jeziorski
02/22/2024, 8:08 AMhfhbd
02/22/2024, 8:24 AMRay Rahke
02/23/2024, 3:55 PMsomewhere:...
publisher.publish("update", { fps: 60, entities: List<Entity> } )
publisher.publish("input", { mousex: 0, mousey: 0 })
then later...
if (event.label == "update) {
fps = event.content.fps
} else if (event.label == "input") {
mousex = event.content.mousex
}
Ray Rahke
02/23/2024, 4:00 PMRay Rahke
02/23/2024, 4:00 PMhfhbd
02/23/2024, 4:00 PMRay Rahke
02/23/2024, 4:02 PMRay Rahke
02/23/2024, 4:02 PMRay Rahke
02/23/2024, 4:02 PMhfhbd
02/23/2024, 4:02 PMsealed interface Event<Context> {
data class Update<Context>(val context: Context): Event<Context>
data class Input<Context>(val context: Context): Event<Context>
}
data class FPS(val fps: Int, val entities: List<Entity>)
data class Mouse(val x: Int, val y: Int)
publisher.publish(Event.Update(context = FPS(fps = 60, entities = listOf<Entity>()))
publisher.publish(Event.Input(Mouse(x = 0, y = 0))
then later...
when (val event: Event<*>) {
is Event.Update -> {
val context = event.context
if (context is FPS) {
val fps = context.fps
}
}
is Event.Input -> {
val context = event.context
if (context is Mouse) {
val mouseX = context.x
}
}
}
Ray Rahke
02/23/2024, 4:03 PMRay Rahke
02/23/2024, 4:03 PMRay Rahke
02/23/2024, 4:04 PMRay Rahke
02/23/2024, 4:04 PMRay Rahke
02/23/2024, 4:05 PMhfhbd
02/23/2024, 4:05 PMRay Rahke
02/23/2024, 4:05 PMhfhbd
02/23/2024, 4:06 PMRay Rahke
02/23/2024, 4:06 PMRay Rahke
02/23/2024, 4:06 PMRay Rahke
02/23/2024, 4:06 PMRay Rahke
02/23/2024, 4:06 PMhfhbd
02/23/2024, 4:07 PMopen class Custom<Context>(val context: Context): Event<Context>
Ray Rahke
02/23/2024, 4:07 PMRay Rahke
02/23/2024, 4:08 PMclass SomeSubscriber : Subscriber {
fun foo() {
for (event in this.events) {
if (event.update)
}
Ray Rahke
02/23/2024, 4:08 PMRay Rahke
02/23/2024, 4:08 PMhfhbd
02/23/2024, 4:08 PMRay Rahke
02/23/2024, 4:09 PMEvent
, then if Event.Custom ->
will be red errorRay Rahke
02/23/2024, 4:09 PMRay Rahke
02/23/2024, 4:10 PMopen class PhysicsEvent
open class RenderEvent
Ray Rahke
02/23/2024, 4:11 PMRay Rahke
02/23/2024, 4:11 PMRay Rahke
02/23/2024, 4:11 PMhfhbd
02/23/2024, 4:12 PMRay Rahke
02/23/2024, 4:13 PMRay Rahke
02/23/2024, 4:13 PMRay Rahke
02/23/2024, 4:13 PMRay Rahke
02/23/2024, 4:15 PMRay Rahke
02/23/2024, 4:15 PMhfhbd
02/23/2024, 4:15 PMRay Rahke
02/23/2024, 4:15 PMRay Rahke
02/23/2024, 4:16 PMRay Rahke
02/23/2024, 4:17 PMRay Rahke
02/23/2024, 4:17 PMany
Ray Rahke
02/23/2024, 4:19 PMhfhbd
02/23/2024, 4:24 PMpublisher.publish
? And did you enable noPropertyAccessFromIndexSignature
?Ray Rahke
02/23/2024, 4:25 PMpublish(label: string, data: any)
Ray Rahke
02/23/2024, 4:25 PMhfhbd
02/23/2024, 4:26 PMRay Rahke
02/23/2024, 4:26 PMhfhbd
02/23/2024, 4:27 PMRay Rahke
02/23/2024, 4:28 PMRay Rahke
02/23/2024, 4:28 PMRay Rahke
02/23/2024, 4:30 PMRay Rahke
02/23/2024, 4:31 PMRay Rahke
02/23/2024, 4:33 PMclass Whatever extends Publisher {
events = { "update": () => ({fps: this.getFPS()}) }
}
you could then do anywhere else in the code
typeof Whatever['events']
Ray Rahke
02/23/2024, 4:33 PMRay Rahke
02/23/2024, 4:33 PMRay Rahke
02/23/2024, 4:34 PMRay Rahke
02/23/2024, 4:35 PMclass Event {
from: Publisher
label: keyof typeof Publisher['events']
data: ReturnType<typeof Publisher[this['label']]>
}
Ray Rahke
02/23/2024, 4:38 PM