fix indirection
This commit is contained in:
		@@ -62,7 +62,8 @@ func (suite *IpTestSuite) TestMaterialWeightAndVolume() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    teststeel := Material{
 | 
			
		||||
        Name:              "teststeel",
 | 
			
		||||
        Id:                "teststeel",
 | 
			
		||||
        Name:              "steel",
 | 
			
		||||
        Flags:             metalMaterialFlags,
 | 
			
		||||
        Density:           DimensionItemDensity{decimal.NewFromInt(7800)},
 | 
			
		||||
        FractureToughness: DimensionFractureToughness{decimal.NewFromInt(30)},
 | 
			
		||||
@@ -71,7 +72,8 @@ func (suite *IpTestSuite) TestMaterialWeightAndVolume() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    testOakWood := Material{
 | 
			
		||||
        Name:              "testoakwood",
 | 
			
		||||
        Id:                "testoakwood",
 | 
			
		||||
        Name:              "oakwood",
 | 
			
		||||
        Flags:             woodMaterialFlags,
 | 
			
		||||
        Density:           DimensionItemDensity{decimal.NewFromInt(700)},
 | 
			
		||||
        FractureToughness: DimensionFractureToughness{decimal.NewFromFloat(4.5)},
 | 
			
		||||
@@ -149,7 +151,8 @@ func (suite *IpTestSuite) TestMaterialSerialization() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    teststeel := Material{
 | 
			
		||||
        Name:              "teststeel",
 | 
			
		||||
        Id:                "teststeel",
 | 
			
		||||
        Name:              "steel",
 | 
			
		||||
        Flags:             metalMaterialFlags,
 | 
			
		||||
        Density:           DimensionItemDensity{decimal.NewFromInt(7800)},
 | 
			
		||||
        FractureToughness: DimensionFractureToughness{decimal.NewFromInt(30)},
 | 
			
		||||
@@ -158,7 +161,8 @@ func (suite *IpTestSuite) TestMaterialSerialization() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    testOakWood := Material{
 | 
			
		||||
        Name:              "testoakwood",
 | 
			
		||||
        Id:                "testoakwood",
 | 
			
		||||
        Name:              "oakwood",
 | 
			
		||||
        Flags:             woodMaterialFlags,
 | 
			
		||||
        Density:           DimensionItemDensity{decimal.NewFromInt(700)},
 | 
			
		||||
        FractureToughness: DimensionFractureToughness{decimal.NewFromFloat(4.5)},
 | 
			
		||||
@@ -167,13 +171,13 @@ func (suite *IpTestSuite) TestMaterialSerialization() {
 | 
			
		||||
    bytes, err := json.Marshal(teststeel)
 | 
			
		||||
    suite.NoError(err)
 | 
			
		||||
    suite.Equal(
 | 
			
		||||
        `{"name":"teststeel","material_flags":{"conducts_elictricity":true,"blocks_liquid":true,"acid_resistant":true,"blocks_gas":true,"flammable":false,"conducts_heat":true,"radiates":true},"density":"7800","fracture_toughness":"30","melting_point":"1400","boiling_point":"3200"}`,
 | 
			
		||||
        `{"id":"teststeel","name":"steel","material_flags":{"conducts_elictricity":true,"blocks_liquid":true,"acid_resistant":true,"blocks_gas":true,"flammable":false,"conducts_heat":true,"radiates":true},"density":"7800","fracture_toughness":"30","melting_point":"1400","boiling_point":"3200"}`,
 | 
			
		||||
        string(bytes),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    bytes, err = json.Marshal(testOakWood)
 | 
			
		||||
    suite.NoError(err)
 | 
			
		||||
    suite.Equal(`{"name":"testoakwood","material_flags":{"conducts_elictricity":false,"blocks_liquid":true,"acid_resistant":false,"blocks_gas":true,"flammable":true,"conducts_heat":false,"radiates":false},"density":"700","fracture_toughness":"4.5","melting_point":"600","boiling_point":null}`,
 | 
			
		||||
    suite.Equal(`{"id":"testoakwood","name":"oakwood","material_flags":{"conducts_elictricity":false,"blocks_liquid":true,"acid_resistant":false,"blocks_gas":true,"flammable":true,"conducts_heat":false,"radiates":false},"density":"700","fracture_toughness":"4.5","melting_point":"600","boiling_point":null}`,
 | 
			
		||||
        string(bytes),
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
@@ -195,6 +199,7 @@ func (suite *IpTestSuite) TestMaterialDeserialization() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    teststeel := Material{
 | 
			
		||||
        Id:                "steel",
 | 
			
		||||
        Name:              "steel",
 | 
			
		||||
        Flags:             metalMaterialFlags,
 | 
			
		||||
        Density:           DimensionItemDensity{decimal.NewFromInt(7800)},
 | 
			
		||||
 
 | 
			
		||||
@@ -95,6 +95,7 @@ func NewMaterialMap(path string, logger zerolog.Logger) (MaterialMap, error) {
 | 
			
		||||
 | 
			
		||||
                toReplace := item2.(map[string]interface{})["material_flags"]
 | 
			
		||||
 | 
			
		||||
                //todo generalize
 | 
			
		||||
                if ref, ok := toReplace.(map[string]interface{})["$ref"]; ok {
 | 
			
		||||
                    rfs := strings.Split(ref.(string), "/")
 | 
			
		||||
                    referredFlag := rfs[len(rfs)-1]
 | 
			
		||||
@@ -104,7 +105,7 @@ func NewMaterialMap(path string, logger zerolog.Logger) (MaterialMap, error) {
 | 
			
		||||
                if err != nil {
 | 
			
		||||
                    return nil, fmt.Errorf("Could not marshal back:%w", err)
 | 
			
		||||
                }
 | 
			
		||||
                mm[clause] = &Material{}
 | 
			
		||||
                mm[clause] = &Material{Id: clause}
 | 
			
		||||
                err = json.Unmarshal(bts, mm[clause])
 | 
			
		||||
                if err != nil {
 | 
			
		||||
                    return nil, fmt.Errorf("Could not unmarshal to material_flags:%w", err)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user