Bois icon indicating copy to clipboard operation
Bois copied to clipboard

Some object properties seralized with default constructor values instead of correct values

Open d-vyd opened this issue 5 years ago • 2 comments

Hi,

You are free to close my previous issue https://github.com/salarcode/Bois/issues/16. I thought everything was working flawlessly until this new curiosity popped up. My understanding is that we can use constructors with parameters in our code as long as we also provide a constructor without parameters, such as these two for my MapCellModel. However, when I save and reload a 5x5 map of cells, the X and Y data have default values while the terrain data retain the values assigned. Any idea why this might occur?

Thank you, -david

        public MapCellModel(int x, int y, int elevation, TerrainKindEnum terrain)
        {
            this.X = x;
            this.Y = y;
            this.Elevation = elevation;
            this.TerrainKind = terrain;
            this.Things = new ObservableCollection<string>();
        }

        // this version is used by the serializer, Bois, for initialization
        public MapCellModel()
        {
            this.X = -1;
            this.Y = -1;
            this.Elevation = -1;
            this.TerrainKind = TerrainKindEnum.Field;
            this.Things = new ObservableCollection<string>();
        }

Before Saving Map 1_A

MapCell 0_0: x=0 y=0 terrain=Forest MapCell 0_1: x=0 y=1 terrain=Forest MapCell 0_2: x=0 y=2 terrain=Forest MapCell 0_3: x=0 y=3 terrain=Field MapCell 0_4: x=0 y=4 terrain=Water MapCell 1_0: x=1 y=0 terrain=Water MapCell 1_1: x=1 y=1 terrain=Forest MapCell 1_2: x=1 y=2 terrain=Forest MapCell 1_3: x=1 y=3 terrain=Forest MapCell 1_4: x=1 y=4 terrain=Forest MapCell 2_0: x=2 y=0 terrain=Water MapCell 2_1: x=2 y=1 terrain=Field MapCell 2_2: x=2 y=2 terrain=Field MapCell 2_3: x=2 y=3 terrain=Field MapCell 2_4: x=2 y=4 terrain=Forest MapCell 3_0: x=3 y=0 terrain=Forest MapCell 3_1: x=3 y=1 terrain=Water MapCell 3_2: x=3 y=2 terrain=Water MapCell 3_3: x=3 y=3 terrain=Water MapCell 3_4: x=3 y=4 terrain=Forest MapCell 4_0: x=4 y=0 terrain=Field MapCell 4_1: x=4 y=1 terrain=Forest MapCell 4_2: x=4 y=2 terrain=Field MapCell 4_3: x=4 y=3 terrain=Water MapCell 4_4: x=4 y=4 terrain=Forest

After loading saved map 1_A

MapCell 0_0: x=-1 y=-1 terrain=Forest MapCell 0_1: x=-1 y=-1 terrain=Forest MapCell 0_2: x=-1 y=-1 terrain=Forest MapCell 0_3: x=-1 y=-1 terrain=Field MapCell 0_4: x=-1 y=-1 terrain=Water MapCell 1_0: x=-1 y=-1 terrain=Water MapCell 1_1: x=-1 y=-1 terrain=Forest MapCell 1_2: x=-1 y=-1 terrain=Forest MapCell 1_3: x=-1 y=-1 terrain=Forest MapCell 1_4: x=-1 y=-1 terrain=Forest MapCell 2_0: x=-1 y=-1 terrain=Water MapCell 2_1: x=-1 y=-1 terrain=Field MapCell 2_2: x=-1 y=-1 terrain=Field MapCell 2_3: x=-1 y=-1 terrain=Field MapCell 2_4: x=-1 y=-1 terrain=Forest MapCell 3_0: x=-1 y=-1 terrain=Forest MapCell 3_1: x=-1 y=-1 terrain=Water MapCell 3_2: x=-1 y=-1 terrain=Water MapCell 3_3: x=-1 y=-1 terrain=Water MapCell 3_4: x=-1 y=-1 terrain=Forest MapCell 4_0: x=-1 y=-1 terrain=Field MapCell 4_1: x=-1 y=-1 terrain=Forest MapCell 4_2: x=-1 y=-1 terrain=Field MapCell 4_3: x=-1 y=-1 terrain=Water MapCell 4_4: x=-1 y=-1 terrain=Forest

d-vyd avatar Nov 07 '20 19:11 d-vyd

Can you provide a working example so I can test it. Thanks

salarcode avatar Nov 08 '20 00:11 salarcode

I wish I could! When I tried a minimal example--the problem disappeared. The error must be on my side. Sorry to bother you.

EDIT: I believe I found the error. X and Y were "get" only since I was using the parameterized constructor to create the objects. I guess Bois needs to "set".

d-vyd avatar Nov 08 '20 19:11 d-vyd

You are welcome to close this. That issue was resolved back then.

manyworldspublishing avatar Nov 16 '22 20:11 manyworldspublishing