本文整理匯總了Golang中github.com/Nightgunner5/go-valve/keyvalues.KeyValues類的典型用法代碼示例。如果您正苦於以下問題:Golang KeyValues類的具體用法?Golang KeyValues怎麽用?Golang KeyValues使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了KeyValues類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ToKeyValues
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
}
示例2: ToKeyValues
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
}
示例3: ToKeyValues
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
}
示例4: FromKeyValues
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
}
示例5: FromKeyValues
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
}
示例6: FromKeyValues
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
}