Ejemplo n.º 1
0
func (c *RGB) ToKeyValues() *keyvalues.KeyValues {
	var kv keyvalues.KeyValues

	color := kv.NewSubKey("color")
	color.SetValueString(fmt.Sprintf("%d %d %d", c.Red, c.Green, c.Blue))

	return color
}
Ejemplo n.º 2
0
func (vg *VisGroup) ToKeyValues() *keyvalues.KeyValues {
	var kv keyvalues.KeyValues

	visgroup := kv.NewSubKey("visgroup")
	visgroup.NewSubKey("name").SetValueString(vg.Name)
	visgroup.NewSubKey("visgroupid").SetValueInt(vg.ID)
	visgroup.Append(vg.Color.ToKeyValues())

	return visgroup
}
Ejemplo n.º 3
0
func (info *VersionInfo) ToKeyValues() *keyvalues.KeyValues {
	var kv keyvalues.KeyValues
	versioninfo := kv.NewSubKey("versioninfo")
	versioninfo.NewSubKey("editorversion").SetValueInt(info.EditorVersion)
	versioninfo.NewSubKey("editorbuild").SetValueInt(info.EditorBuild)
	versioninfo.NewSubKey("mapversion").SetValueInt(info.MapVersion)
	versioninfo.NewSubKey("formatversion").SetValueInt(info.FormatVersion)
	versioninfo.NewSubKey("prefab").SetValueBool(info.Prefab)

	return versioninfo
}
Ejemplo n.º 4
0
func (vg *VisGroups) ToKeyValues() *keyvalues.KeyValues {
	var kv keyvalues.KeyValues

	visgroups := kv.NewSubKey("visgroups")

	for _, group := range *vg {
		visgroups.Append(group.ToKeyValues())
	}

	return visgroups
}
Ejemplo n.º 5
0
func (c *RGB) FromKeyValues(kv *keyvalues.KeyValues) error {
	parts := strings.Fields(kv.String(""))

	if len(parts) != 3 {
		return fmt.Errorf("RGB: color has %d components, but expected %d", len(parts), 3)
	}

	components := [...]*uint8{&c.Red, &c.Green, &c.Blue}
	componentNames := [...]string{"red", "green", "blue"}
	for i := range components {
		if v, err := strconv.ParseUint(parts[i], 10, 8); err == nil {
			*components[i] = uint8(v)
		} else {
			return fmt.Errorf("RGB: error parsing %s component: %v", componentNames[i], err)
		}
	}

	return nil
}
Ejemplo n.º 6
0
func (vg *VisGroup) FromKeyValues(kv *keyvalues.KeyValues) error {
	if !strings.EqualFold(kv.Name(), "visgroup") {
		return fmt.Errorf("VisGroup: key name was %q, not %q", kv.Name(), "visgroup")
	}

	if name := kv.SubKey("name").String(""); name != "" {
		vg.Name = name
	} else {
		return fmt.Errorf("VisGroup: no name")
	}

	if id := kv.SubKey("visgroupid").Int(0); id > 0 {
		vg.ID = id
	} else {
		return fmt.Errorf("VisGroup: %s: ID = %d or no ID", vg.Name, id)
	}

	if err := vg.Color.FromKeyValues(kv.SubKey("color")); err != nil {
		return fmt.Errorf("VisGroup: %s: %v", vg.Name, err)
	}

	return nil
}
Ejemplo n.º 7
0
func (vg *VisGroups) FromKeyValues(kv *keyvalues.KeyValues) error {
	if !strings.EqualFold(kv.Name(), "visgroups") {
		return fmt.Errorf("VisGroups: key name was %q, not %q", kv.Name(), "visgroups")
	}

	*vg = (*vg)[:0]

	for subkey := range kv.Each() {
		var group VisGroup
		if err := group.FromKeyValues(subkey); err != nil {
			return err
		}
		*vg = append(*vg, group)
	}

	return nil
}
Ejemplo n.º 8
0
func (info *VersionInfo) FromKeyValues(kv *keyvalues.KeyValues) error {
	if !strings.EqualFold(kv.Name(), "versioninfo") {
		return fmt.Errorf("VersionInfo: key name was %q, not %q", kv.Name(), "versioninfo")
	}

	info.EditorVersion = kv.SubKey("editorversion").Int(0)
	info.EditorBuild = kv.SubKey("editorbuild").Int(0)
	info.MapVersion = kv.SubKey("mapversion").Int(0)
	info.FormatVersion = kv.SubKey("formatversion").Int(0)
	info.Prefab = kv.SubKey("prefab").Bool(false)

	return nil
}