fix flags loading
This commit is contained in:
		| @@ -195,7 +195,7 @@ func (suite *IpTestSuite) TestMaterialDeserialization() { | ||||
|     } | ||||
|  | ||||
|     teststeel := Material{ | ||||
| 		Name:              "teststeel", | ||||
|         Name:              "steel", | ||||
|         Flags:             metalMaterialFlags, | ||||
|         Density:           DimensionItemDensity{decimal.NewFromInt(7800)}, | ||||
|         FractureToughness: DimensionFractureToughness{decimal.NewFromInt(30)}, | ||||
| @@ -203,6 +203,7 @@ func (suite *IpTestSuite) TestMaterialDeserialization() { | ||||
|         BoilingPoint:      DimensionItemNullTemperature{decimal.NullDecimal{decimal.NewFromInt(3200), true}}, | ||||
|     } | ||||
|  | ||||
| 	_ = teststeel | ||||
|     loadedsteel := mm["steel"] | ||||
|     suite.Equalf(teststeel, *loadedsteel, "error: %s") | ||||
|     _ = mm | ||||
| } | ||||
|   | ||||
| @@ -32,13 +32,13 @@ type MaterialFlags struct { | ||||
|     Radiates            bool `json:"radiates"` | ||||
| } | ||||
|  | ||||
| type MaterialMap map[string]Material | ||||
| type MaterialMap map[string]*Material | ||||
|  | ||||
| type tt map[string]MaterialMap | ||||
|  | ||||
| func NewMaterialMap(path string, logger zerolog.Logger) (*MaterialMap, error) { | ||||
| func NewMaterialMap(path string, logger zerolog.Logger) (MaterialMap, error) { | ||||
|  | ||||
| 	mm := &MaterialMap{} | ||||
|     mm := make(MaterialMap) | ||||
|     tmp := make(map[string][]interface{}) | ||||
|     flags := make(map[string]*MaterialFlags) | ||||
|     err := filepath.Walk(path+"/assets/materials", | ||||
| @@ -93,12 +93,19 @@ func NewMaterialMap(path string, logger zerolog.Logger) (*MaterialMap, error) { | ||||
|             _ = ttt | ||||
|             for clause, item2 := range ttt { | ||||
|  | ||||
|                 toReplace := item2.(map[string]interface{})["material_flags"] | ||||
|  | ||||
|                 if ref, ok := toReplace.(map[string]interface{})["$ref"]; ok { | ||||
|                     rfs := strings.Split(ref.(string), "/") | ||||
|                     referredFlag := rfs[len(rfs)-1] | ||||
|                     item2.(map[string]interface{})["material_flags"] = flags[referredFlag] | ||||
|                 } | ||||
|                 bts, err := json.Marshal(item2) | ||||
|                 if err != nil { | ||||
|                     return nil, fmt.Errorf("Could not marshal back:%w", err) | ||||
|                 } | ||||
| 				flags[clause] = &MaterialFlags{} | ||||
| 				err = json.Unmarshal(bts, flags[clause]) | ||||
|                 mm[clause] = &Material{} | ||||
|                 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