private string GenerateInnerClasses(ScenesCodeCooker scenesCodeCooker) { var result = ""; var checkedNodes = new List <ParsedNode>(); var checkedClasses = new List <ParsedFramesTree>(); foreach (var pn in ParsedNodes.Where(c => !c.IsExternalScene)) { if (!checkedNodes.Exists(f => f.FieldName == pn.FieldName)) { checkedNodes.Add(pn); result += pn.GenerateCode(scenesCodeCooker.NodeCodeTemplate) + "\n"; } } foreach (var pft in InnerClasses.Where(c => !c.ParsedNode.IsExternalScene)) { if (!checkedClasses.Exists(f => f.FieldName == pft.FieldName)) { checkedClasses.Add(pft); result += pft.GenerateCode(scenesCodeCooker, isRootNode: false) + "\n"; } } return(result); }
private string GenerateFieldsInitialization(ScenesCodeCooker scenesCodeCooker) { var result = ""; if (!BaseClassName.IsNullOrWhiteSpace()) { result += $"{BaseClassName} = new Common.{BaseClassName}(Node);\n"; } foreach (var node in ParsedNodes) { result += string.Format( "@{2} = new {0}(Node.Find<Node>(\"{1}\"));", scenesCodeCooker.GetFullTypeOf(node), node.Id, node.FieldName ); result += "\n"; } foreach (var pft in InnerClasses) { result += string.Format( "@{2} = new {0}(Node.Find<Node>(\"{1}\"));", scenesCodeCooker.GetFullTypeOf(pft), pft.ParsedNode.Id, pft.FieldName ); result += "\n"; } return(result); }
public ParsedNode(Node node, string name, bool isInExternalScene) { Id = node.Id; Name = name; Type = node.GetType().Name; TypeFullName = node.GetType().FullName; ClassName = name; FieldName = "_" + name; ContentsPath = AssetPath.CorrectSlashes(node.ContentsPath ?? ""); IsInExternalScene = isInExternalScene; if (IsExternalScene) { string externalName; string externalBaseName; ScenesCodeCooker.ParseCommonName(Path.GetFileNameWithoutExtension(ContentsPath), out externalName, out externalBaseName); ClassName = externalName; } foreach (var animation in node.Animations) { var isDefault = animation == node.DefaultAnimation; foreach (var marker in animation.Markers.Where(marker => !string.IsNullOrEmpty(marker.Id))) { if (isDefault) { Markers.Add(marker.Id); } NamedMarkers.Add(new AnimationMarker(animation.Id, marker.Id)); } } }
private string GenerateInnerClasses(ScenesCodeCooker scenesCodeCooker) { var result = ""; foreach (var pft in InnerClasses.Where(c => !c.ParsedNode.IsExternalScene)) { result += pft.GenerateCode(scenesCodeCooker, isRootNode: false); } foreach (var pn in ParsedNodes.Where(c => !c.IsExternalScene)) { result += pn.GenerateCode(scenesCodeCooker.NodeCodeTemplate); } return(result); }
public string GenerateCode(ScenesCodeCooker scenesCodeCooker, bool isRootNode = true) { var result = isRootNode ? scenesCodeCooker.SceneCodeTemplate : scenesCodeCooker.FrameCodeTemplate; result = result.Replace("<%CLASS_NAME%>", ClassName); result = result.Replace("<%SCENE_PATH%>", "\"" + ScenePath + "\""); result = result.Replace("<%FIELDS%>", GenerateFields(scenesCodeCooker)); result = result.Replace("<%INIT_FIELDS%>", GenerateFieldsInitialization(scenesCodeCooker)); result = result.Replace("<%INNER_CLASSES%>", GenerateInnerClasses(scenesCodeCooker)); result = result.Replace("<%ANIMATIONS%>", ParsedNode.GenerateAnimations(isRootNode ? "T" : null)); result = result.Replace("<%IT%>", ParsedNode.GenerateIt()); result = result.Replace("<%COMMON_BASE%>", GenerateCommonBase()); return(result); }
private string GenerateFields(ScenesCodeCooker scenesCodeCooker) { var result = ""; var multiFields = new List <ParsedNode>(); var multiClasses = new List <ParsedFramesTree>(); foreach (var node in ParsedNodes) { bool haveSameFields = ParsedNodes.Count(f => f.FieldName == node.FieldName) > 1; if (haveSameFields) { if (multiFields.Exists(n => n.FieldName == node.FieldName)) { continue; } multiFields.Add(node); result += $"public readonly List<{scenesCodeCooker.GetFullTypeOf(node)}> @{node.FieldName};" + "\n"; } else { result += $"public readonly {scenesCodeCooker.GetFullTypeOf(node)} @{node.FieldName};" + "\n"; } } foreach (var pft in InnerClasses) { bool haveSameClasses = InnerClasses.Count(f => f.FieldName == pft.FieldName) > 1; if (haveSameClasses) { if (multiClasses.Exists(n => n.FieldName == pft.FieldName)) { continue; } multiClasses.Add(pft); result += $"public readonly List<{scenesCodeCooker.GetFullTypeOf(pft)}> @{pft.FieldName};" + "\n"; } else { result += $"public readonly {scenesCodeCooker.GetFullTypeOf(pft)} @{pft.FieldName};" + "\n"; } } return(result); }
public string GenerateCode(ScenesCodeCooker scenesCodeCooker, bool isRootNode = true) { var result = isRootNode ? scenesCodeCooker.SceneCodeTemplate : scenesCodeCooker.FrameCodeTemplate; result = result.Replace("<%CLASS_NAME%>", ClassName); result = result.Replace("<%WRAPPED_NODE_TYPE_GENERIC_ARGUMENT%>", ParsedNode.TypeFullName); result = result.Replace("<%SCENE_PATH%>", "\"" + Path.ChangeExtension(ScenePath, null) + "\""); result = result.Replace("<%FIELDS%>", GenerateFields(scenesCodeCooker)); result = result.Replace("<%INIT_FIELDS%>", GenerateFieldsInitialization(scenesCodeCooker)); result = result.Replace("<%INNER_CLASSES%>", GenerateInnerClasses(scenesCodeCooker)); result = result.Replace("<%ANIMATIONS%>", ParsedNode.GenerateAnimations(isRootNode ? "T" : null)); result = result.Replace("<%IT%>", ParsedNode.GenerateIt()); result = result.Replace("<%COMMON_BASE%>", GenerateCommonBase()); result = result.Replace("<%USING%>", GenerateUsingLibraries(result)); return(result); }
private string GenerateFields(ScenesCodeCooker scenesCodeCooker) { var result = ""; foreach (var node in ParsedNodes) { result += string.Format("public readonly {0} @{1};", scenesCodeCooker.GetFullTypeOf(node), node.FieldName); result += "\n"; } foreach (var pft in InnerClasses) { result += string.Format("public readonly {0} @{1};", scenesCodeCooker.GetFullTypeOf(pft), pft.FieldName); result += "\n"; } return(result); }
private string GenerateFieldsInitialization(ScenesCodeCooker scenesCodeCooker) { var result = ""; if (!BaseClassName.IsNullOrWhiteSpace()) { result += $"{BaseClassName} = new Common.{BaseClassName}(Node);\n"; } var multiNodes = new List <ParsedNode>(); var multiClasses = new List <ParsedFramesTree>(); foreach (var node in ParsedNodes) { bool haveSameFields = ParsedNodes.Count(f => f.FieldName == node.FieldName) > 1; if (haveSameFields) { if (multiNodes.Exists(n => n.FieldName == node.FieldName)) { continue; } multiNodes.Add(node); result += string.Format( "@{2} = Node.Descendants.Where(nodeEl => nodeEl.Id == \"{1}\")" + ".Select(nodeEl => new {0} (nodeEl)).ToList();" + "\n", scenesCodeCooker.GetFullTypeOf(node), node.Id, node.FieldName ); } else { result += string.Format( "@{2} = new {0}(Node.Find<Node>(\"{1}\"));" + "\n", scenesCodeCooker.GetFullTypeOf(node), node.Id, node.FieldName ); } } foreach (var pft in InnerClasses) { bool haveSameFields = InnerClasses.Count(f => f.FieldName == pft.FieldName) > 1; if (haveSameFields) { if (multiClasses.Exists(n => n.FieldName == pft.FieldName)) { continue; } multiClasses.Add(pft); result += string.Format( "@{2} = Node.Descendants.Where(nodeEl => nodeEl.Id == \"{1}\")" + ".Select(nodeEl => new {0} (nodeEl)).ToList();" + "\n", scenesCodeCooker.GetFullTypeOf(pft), pft.ParsedNode.Id, pft.FieldName ); } else { result += string.Format( "@{2} = new {0}(Node.Find<Node>(\"{1}\"));" + "\n", scenesCodeCooker.GetFullTypeOf(pft), pft.ParsedNode.Id, pft.FieldName ); } } return(result); }