|
|
@ -158,12 +158,18 @@ func (n *xmlNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { |
|
|
return d.DecodeElement((*node)(n), &start) |
|
|
return d.DecodeElement((*node)(n), &start) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// The parseVariable function parses a Variable value from a XML node.
|
|
|
|
|
|
// The variable type is inferred from the "type" attribute of the node.
|
|
|
|
|
|
// If this attribute is omitted, the type of the variable must be given through the
|
|
|
|
|
|
// "defaults" parameter to avoid a parsing error.
|
|
|
|
|
|
// If this attribute is specified, the "defaults" parameter will be unused and may be nil
|
|
|
func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Variable, error) { |
|
|
func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Variable, error) { |
|
|
ret := &Variable{} |
|
|
ret := &Variable{} |
|
|
|
|
|
|
|
|
typeOk := false |
|
|
typeOk := false |
|
|
nameOk := false |
|
|
nameOk := false |
|
|
|
|
|
|
|
|
|
|
|
//parsing default values
|
|
|
if defaults != nil { |
|
|
if defaults != nil { |
|
|
switch defaults.Type.(type) { |
|
|
switch defaults.Type.(type) { |
|
|
case *VariableType_badType: |
|
|
case *VariableType_badType: |
|
|
@ -174,6 +180,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//iterating on the attributes
|
|
|
for i := 0; i < len(root.Attrs); i++ { |
|
|
for i := 0; i < len(root.Attrs); i++ { |
|
|
attrName := root.Attrs[i].Name.Local |
|
|
attrName := root.Attrs[i].Name.Local |
|
|
attrVal := root.Attrs[i].Value |
|
|
attrVal := root.Attrs[i].Value |
|
|
@ -192,6 +199,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//check if no parse error
|
|
|
if !nameOk { |
|
|
if !nameOk { |
|
|
return nil, errors.New("Unnamed variable") |
|
|
return nil, errors.New("Unnamed variable") |
|
|
} |
|
|
} |
|
|
|