rustyscreeps / screeps-game-api

Typed bindings to the Screeps in-game API for WASM Rust AIs
MIT License
138 stars 45 forks source link

Not exhaustive API of strokes in RoomVisual #379

Open xilexio opened 1 year ago

xilexio commented 1 year ago

In JS, it is possible to supply to, e.g., RoomVisual.circle options with

{
    stroke: undefined
}

It means that there should be no stroke and is different from empty options {} which mean that the stroke should be default (rather thick and light).

Currently in the API it is impossible to supply an undefined stroke. The stroke can either be None meaning default or Some(x) meaning width x, there is no undefined option that means no stroke. A working workaround is supplying transparent stroke color or extremely small (but positive or else it will not work) stroke width. However, this approach requires the stroke data to be sent to the client which needlessly uses up more of the already small (when visualizing something in the whole room) 500kB limit.

MrFaul commented 2 weeks ago

@shanemadden This can be closed, since it is old and no longer true.

It can be accomplished like so:

let rv = RoomVisual::new(None);
    rv.circle(
        10.0,
        10.0,
        Some(CircleStyle::default().fill("blue").radius(5.0)),
    );

undefined isn't valid JSON anyway and gets removed when serialized. And it will be serialized because it gets send to the client for remote execution.