GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

`Color` - unable to access rgba fields #7

Closed aSemy closed 2 years ago

aSemy commented 2 years ago

I have a LuaPlayer variable, and I'd like to access the rgba fields of player.color. However I'm unable to do this - the fields are not resolvable.

  export function playerToTable(player: LuaPlayer): PlayerData {

    player.color.r // Unresolved variable r
    player.color.g // Unresolved variable g 
    player.color.b // Unresolved variable b
    player.color.a // Unresolved variable a 

    //...
  }

I'm sure there's an easy way to do this, I'm just not familiar enough with TypeScript to figure it out :) But it would be nice to be able to access the rgba fields without having to determine whether player.color is a ColorTable or a ColorArray

If an improvement is possible, I think ColorModifier, Position, ChunkPosition, TilePosition, BoundingBox, and GuiLocation, would also benefit from the same improvement.

GlassBricks commented 2 years ago

This could be possible since typescript 4.3 with setter overloading. Certain other attributes already have setter overloading (defined manually), but this could be done automatically in these cases too (stay tuned)!

GlassBricks commented 2 years ago

Now implemented in v0.15.0: table or array types, whenever known to be in a "read" position, are declared in Table form.

For more details, see the Changelog/Readme.

aSemy commented 2 years ago

Thanks for this change - it's much nicer to use now!

One small note: I think BoundingBoxTable and BoundingBoxArray also needs the left_top and right_bottom fields marked as PositionTable instead of Position.

GlassBricks commented 2 years ago

One small note: I think BoundingBoxTable and BoundingBoxArray also needs the left_top and right_bottom fields marked as PositionTable instead of Position.

See BoundingBoxRead for those situations. A BoundingBox specification can still be either table or array.

aSemy commented 2 years ago

That helps, thanks!