Closed arvalaan closed 1 year ago
Hi. Thanks for your question. I can reproduce your problem and the cause is in Grid's fromJSON()
method. It looks like this:
static fromJSON({ hexSettings, coordinates }: GridAsJSON): Grid<Hex> {
const HexClass = defineHex(hexSettings)
return new Grid(
HexClass,
coordinates.map((_coordinates) => new HexClass(_coordinates)),
)
}
As you can see, it creates hexes by simply passing the coordinates to the constructor function, ignoring any custom properties you may have. I'll add an optional hexFactory
argument to fromJSON()
so that you can do something like this:
const hexFactory = ({ q, r, elevation, moisture, id }: CustomHex) => CustomHex.create({ q, r }, elevation, moisture, id)
const grid2 = Grid.fromJSON(deserializedGrid, hexFactory)
:tada: This issue has been resolved in version 4.1.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Hey there, I'm trying to deserialize a previously generated grid however am unable to do so as my CustomHex class gets lost.
Here you can find my steps to reproduce:
My custom class definition
My function to convert a square noise grid into a hexagon grid:
I then try to deserialize in another function however the output is not as expected.
Here's a test function I put together to try and see what I was doing wrong:
Am I missing something?