exaV / screeps-kotlin-types

Screep's Kotlin type definitions
MIT License
17 stars 18 forks source link

Not able to use RoomVisual styles #50

Closed WilhelmOks closed 4 years ago

WilhelmOks commented 4 years ago

There are styles defined in RoomVisual.kt for example the LineStyle interface LineStyle : Style.

When I pass a style to the line() function as the third (optional) parameter, it has no effect:

    val lineStyle = object : RoomVisual.LineStyle {
        override var color: String?
            get() = "#eeee00"
            set(value) {}
        override var lineStyle: LineStyleConstant?
            get() = LINE_STYLE_DASHED
            set(value) {}
        override var opacity: Double?
            get() = 0.5
            set(value) {}
        override var width: Double?
            get() = 1.0
            set(value) {}
    }

    creep.room.visual.line(creep.pos, destination, lineStyle)

The line is white and is not dashed. It is the same as if I omit the third parameter.

I also tried the TextStyle and it also has no effect on the text rendering.

exaV commented 4 years ago

have you tried?

    val lineStyle = object : RoomVisual.LineStyle {
        override var color: String =  "#eeee00"
        override var lineStyle = LINE_STYLE_DASHED
        override var opacity =  0.5
        override var width= 1.0
    }
WilhelmOks commented 4 years ago

the compiler wanted me to add the types:

    val lineStyle = object : RoomVisual.LineStyle {
        override var color: String? =  "#eeee00"
        override var lineStyle: LineStyleConstant? = LINE_STYLE_DASHED
        override var opacity: Double? =  0.5
        override var width: Double? = 1.0
    }

but this doesn't work either.

magnusesp commented 4 years ago

~I'm not entirely sure it's related as I don't understand what you are aiming to do, but~ This is how I set the styles when drawing:

RoomVisual(position.roomName)
                        .line(position, lastPosition, options {color = inColor; lineStyle = LINE_STYLE_DASHED })

The options {} construct by @Jomik is very powerful.

WilhelmOks commented 4 years ago

@MaggNorway I don't know why or how it works, but it does! Thanks!