private static void LoadShape(DataElement node, Shape shape, ShapeTemplatesSet templates) { string templateName = node.GetAttribValue("template_name"); ShapeTemplate template = templates.FindTemplate(templateName); shape.Template = template; shape.ZOrder = float.Parse(node.GetAttribValue("z_order")); string colorStr = node.GetAttribValue("color"); if(colorStr != null) { shape.Color = Color.FromArgb(int.Parse(colorStr)); } if(shape.EditableColor) { node.CreateAttribute("color", shape.Color.ToArgb().ToString()); } DataElement circlesEl = node.GetChild("circles"); IList<DataElement> circleElList = circlesEl.CollectChildren("circle"); IList<ShapeCircle> circles = shape.Circles; for(int index = 0; index < circleElList.Count; ++index) { DataElement circleEl = circleElList[index]; ShapeCircle circle = circles[index]; LoadShapeCircle(circleEl, circle); } DataElement userPropertiesEl = node.GetChild("user_properties"); LoadUserProperties(userPropertiesEl, shape); }
private static void LoadShapeCircle(DataElement node, ShapeCircle shapeCircle) { shapeCircle.Position = Vector2f.Parse(node.GetAttribValue("position")); shapeCircle.Radius = float.Parse(node.GetAttribValue("radius")); shapeCircle.Angle = float.Parse(node.GetAttribValue("angle")); }
private static void LoadRectTemplate(DataElement node, RectTemplate template) { LoadBaseTemplate(node, template); string normalizedStr = node.GetAttribValue("normalized"); template.Normalized = bool.Parse(normalizedStr); }
private static void LoadScene(DataElement sceneElement, Scene scene, ShapeTemplatesSet templates) { scene.Size = Vector2f.Parse(sceneElement.GetAttribValue("size")); DataElement shapesEl = sceneElement.GetChild("shapes"); foreach(DataElement shapeEl in shapesEl.CollectChildren("shape")) { string name = shapeEl.GetAttribValue("name"); Shape shape = scene.CreateShape(name); LoadShape(shapeEl, shape, templates); } DataElement propertiesContainer = sceneElement.GetChild("properties"); if(propertiesContainer != null) { LoadUserProperties(propertiesContainer, scene); } }
private static void LoadCircleTemplate(DataElement node, CircleTemplate template) { LoadBaseTemplate(node, template); string solidStr = node.GetAttribValue("solid"); template.Solid = bool.Parse(solidStr); }
private static void LoadBaseTemplate(DataElement node, ShapeTemplate template) { string colorStr = node.GetAttribValue("color"); string backgroudStr = node.GetAttribValue("background"); template.Color = Color.FromArgb(int.Parse(colorStr)); template.Backgroud = bool.Parse(backgroudStr); string editableColorStr = node.GetAttribValue("editable_color"); if(editableColorStr != null) { template.EditableColor = bool.Parse(editableColorStr); } DataElement circlesEl = node.GetChild("circles"); List<ShapeCircle> allCircles = template.RootCircle.AllCircles; int index = 0; foreach(DataElement circleEl in circlesEl.CollectChildren("circle")) { string positionStr = circleEl.GetAttribValue("position"); string radiusStr = circleEl.GetAttribValue("radius"); string angleStr = circleEl.GetAttribValue("angle"); ShapeCircle circle = allCircles[index]; circle.Position = Vector2f.Parse(positionStr); circle.Radius = float.Parse(radiusStr); circle.Angle = float.Parse(angleStr); ++index; } DataElement circlesSettingsEl = node.GetChild("circles_settings"); index = 0; foreach(DataElement circleSettingsEl in circlesSettingsEl.CollectChildren("settings")) { ShapeTemplate.ShapeCircleSettings settings = template.PerCircleSettings[index]; string enableOffsetStr = circleSettingsEl.GetAttribValue("enable_offset"); string enableRotateStr = circleSettingsEl.GetAttribValue("enable_rotate"); settings.EnableOffset = bool.Parse(enableOffsetStr); settings.EnableRotate = bool.Parse(enableRotateStr); ++index; } }
private static TemplateBaseInfo LoadTemplateBaseInfo(DataElement node, string folder) { TemplateBaseInfo info = new TemplateBaseInfo(); info.name = node.GetAttribValue("name"); string relPropertiesFilepath = node.GetAttribValue("rel_properties_filepath"); if(!string.IsNullOrEmpty(relPropertiesFilepath)) { info.propertiesFilepath = DirMethods.EvaluateAbsolutePath(folder, relPropertiesFilepath); } return info; }
private static void CreateImageTemplate(DataElement node, string folder, ShapeTemplatesSet templates) { TemplateBaseInfo info = LoadTemplateBaseInfo(node, folder); ImageTemplate template = templates.CreateImageTemplate(info.name, info.propertiesFilepath); string relDiffuseFilepath = node.GetAttribValue("rel_diffuse_filepath"); template.DiffuseFilepath = DirMethods.EvaluateAbsolutePath(folder, relDiffuseFilepath); LoadRectTemplate(node, template); }
private void AddProperty(DataElement propertyEl) { string name = propertyEl.GetAttribValue("name"); string typeStr = propertyEl.GetAttribValue("type"); IProperty property; switch(typeStr) { case "string": { property = CreateStringProperty(propertyEl); break; } case "bool": { property = CreateBoolProperty(propertyEl); break; } case "int": { property = CreateIntProperty(propertyEl); break; } case "float": { property = CreateFloatProperty(propertyEl); break; } case "vector2": { property = CreateVector2Property(propertyEl); break; } case "shape_ref": { property = CreateShapeRefProperty(propertyEl); break; } default: { throw new ArgumentException(); } } m_NameToPropertyMap[name] = property; string defaultValueStr = propertyEl.GetAttribValue("default"); if(defaultValueStr != null) { string errorStr = property.TrySetValue(defaultValueStr); if(errorStr != null) { throw new InvalidDataException(); } } }