public Bone(IntermediateNode node) { Hardpoints = new List <HardpointDefinition>(); foreach (Node subNode in node) { switch (subNode.Name.ToLowerInvariant()) { case "bone to root": BoneToRoot = (subNode as LeafNode).MatrixData4x3.Value; break; case "lod bits": LodBits = (subNode as LeafNode).ByteArrayData[0]; break; case "hardpoints": IntermediateNode hardpointsNode = subNode as IntermediateNode; foreach (IntermediateNode hardpointTypeNode in hardpointsNode) { switch (hardpointTypeNode.Name.ToLowerInvariant()) { case "fixed": foreach (IntermediateNode fixedNode in hardpointTypeNode) { Hardpoints.Add(new FixedHardpointDefinition(fixedNode)); } break; case "revolute": foreach (IntermediateNode revoluteNode in hardpointTypeNode) { Hardpoints.Add(new RevoluteHardpointDefinition(revoluteNode)); } break; default: throw new Exception("Invalid node in " + hardpointsNode.Name + ": " + hardpointTypeNode.Name); } } break; default: throw new Exception("Invalid node in " + node.Name + ": " + subNode.Name); } } }
public override void RenderNode(IntermediateNode node, IntermediateNodeWriter writer) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _scopes.Add(new ScopeInternal(writer)); Visitor.Visit(node); _scopes.RemoveAt(_scopes.Count - 1); }
public static HtmlContentIntermediateNode Content(IntermediateNode node, string content, bool trim = true) { Assert.NotNull(node); var contentNode = Assert.IsType <HtmlContentIntermediateNode>(node); var actual = new StringBuilder(); for (var i = 0; i < contentNode.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(contentNode.Children[i]); Assert.Equal(TokenKind.Html, token.Kind); actual.Append(token.Content); } Assert.Equal(content, trim ? actual.ToString().Trim() : actual.ToString()); return(contentNode); }
private static T FindWithAnnotation <T>(IntermediateNode node, object annotation) where T : IntermediateNode { if (node is T target && object.ReferenceEquals(target.Annotations[annotation], annotation)) { return(target); } for (var i = 0; i < node.Children.Count; i++) { var result = FindWithAnnotation <T>(node.Children[i], annotation); if (result != null) { return(result); } } return(null); }
public TexFrameAnimation(IntermediateNode node) { foreach (var child in node) { var leaf = child as LeafNode; if (leaf == null) { throw new Exception("Texture Animation should not have child intermediate node"); } switch (leaf.Name.ToLowerInvariant()) { case "texture count": TextureCount = leaf.Int32Data.Value; break; case "frame count": FrameCount = leaf.Int32Data.Value; break; case "fps": FPS = leaf.SingleData.Value; break; case "frame rects": var floats = leaf.SingleArrayData; if (floats.Length % 5 != 0) { throw new Exception("Incorrect frame data for Texture Animation"); } Frames = new TexFrame[floats.Length / 5]; for (int i = 0; i < Frames.Length; i++) { Frames[i] = new TexFrame( (int)floats[i * 5], floats[i * 5 + 1], floats[i * 5 + 2], floats[i * 5 + 3], floats[i * 5 + 4] ); } break; } } }
private IntermediateNode RewriteParameterUsage(IntermediateNode parent, TagHelperDirectiveAttributeParameterIntermediateNode node) { // Now rewrite the node to look like: // // builder.AddEventPreventDefaultAttribute(2, "onclick", true); // If minimized. // or // builder.AddEventPreventDefaultAttribute(2, "onclick", someBoolExpression); // If a bool expression is provided in the value. string eventHandlerMethod; if (node.BoundAttributeParameter.Name == "preventDefault") { eventHandlerMethod = ComponentsApi.RenderTreeBuilder.AddEventPreventDefaultAttribute; } else if (node.BoundAttributeParameter.Name == "stopPropagation") { eventHandlerMethod = ComponentsApi.RenderTreeBuilder.AddEventStopPropagationAttribute; } else { // Unsupported event handler attribute parameter. This can only happen if bound attribute descriptor // is configured to expect a parameter other than 'preventDefault' and 'stopPropagation'. return(node); } var result = new ComponentAttributeIntermediateNode(node) { Annotations = { [ComponentMetadata.Common.OriginalAttributeName] = node.OriginalAttributeName, [ComponentMetadata.Common.AddAttributeMethodName] = eventHandlerMethod, }, }; result.Children.Clear(); if (node.AttributeStructure != AttributeStructure.Minimized) { var tokens = GetAttributeContent(node); result.Children.Add(new CSharpExpressionIntermediateNode()); result.Children[0].Children.AddRange(tokens); } return(result); }
public Channel(IntermediateNode root) { //Fetch from nodes byte[] cdata = null; foreach (LeafNode channelSubNode in root) { if (channelSubNode.Name.Equals("header", StringComparison.OrdinalIgnoreCase)) { ReadHeader(channelSubNode); } else if (channelSubNode.Name.Equals("frames", StringComparison.OrdinalIgnoreCase)) { cdata = channelSubNode.ByteArrayData; } } /* Pad data to avoid ARM data alignment errors */ if ((ChannelType & 0x80) == 0x80 || (ChannelType & 0x40) == 0x40) { int startStride = 0; if (Interval < 0) { startStride += 4; } if ((ChannelType & 0x1) == 0x1) { startStride += 4; } if ((ChannelType & 0x2) == 0x2) startStride += 12; } int fullStride = startStride + 8; int compStride = startStride + 6; channelData = new byte[fullStride * FrameCount]; for (int i = 0; i < FrameCount; i++) { int src = compStride * i; int dst = fullStride * i; for (int j = 0; j < compStride; j++) { channelData[dst + j] = cdata[src + j]; } } }
private void setMaterials(IntermediateNode materialLibraryNode) { //TODO: int count = 0; foreach (Node materialNode in materialLibraryNode) { if (materialNode is IntermediateNode) { uint materialId = CrcTool.FLModelCrc(materialNode.Name); if (!Materials.ContainsKey(materialId)) { Materials.Add(materialId, Material.FromNode(materialNode as IntermediateNode, this)); } } //else if (subNode.Name.Equals("material count", StringComparison.OrdinalIgnoreCase)) //count = (subNode as LeafNode).getIntegerBlaBLubb; } //if (count != materials.Count) //throw new Exception("Invalid material count: " + count + " != " + materials.Count); }
internal static void PreallocatedTagHelperPropertyValue( IntermediateNode node, string attributeName, string value, AttributeStructure valueStyle) { var propertyValueNode = Assert.IsType <PreallocatedTagHelperPropertyValueIntermediateNode>(node); try { Assert.Equal(attributeName, propertyValueNode.AttributeName); Assert.Equal(value, propertyValueNode.Value); Assert.Equal(valueStyle, propertyValueNode.AttributeStructure); } catch (XunitException e) { throw new IntermediateNodeAssertException(propertyValueNode, e.Message); } }
internal static void TagHelperHtmlAttribute( string name, AttributeStructure valueStyle, IntermediateNode node, params Action <IntermediateNode>[] valueValidators) { var tagHelperHtmlAttribute = Assert.IsType <TagHelperHtmlAttributeIntermediateNode>(node); try { Assert.Equal(name, tagHelperHtmlAttribute.AttributeName); Assert.Equal(valueStyle, tagHelperHtmlAttribute.AttributeStructure); Children(tagHelperHtmlAttribute, valueValidators); } catch (XunitException e) { throw new IntermediateNodeAssertException(tagHelperHtmlAttribute, tagHelperHtmlAttribute.Children, e.Message, e); } }
public ObjectMap(IntermediateNode root) { NodeName = root.Name; foreach (Node node in root) { if (node.Name.Equals("parent name", StringComparison.OrdinalIgnoreCase)) { ParentName = (node as LeafNode).StringData; } else if (node.Name.Equals("child name", StringComparison.OrdinalIgnoreCase)) { ChildName = (node as LeafNode).StringData; } else if (node.Name.Equals("channel", StringComparison.OrdinalIgnoreCase)) { Channel = new Channel(node as IntermediateNode); } } }
public static void EndInstrumentation(IntermediateNode node) { try { var endNode = Assert.IsType <CSharpCodeIntermediateNode>(node); var content = new StringBuilder(); for (var i = 0; i < endNode.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(endNode.Children[i]); Assert.Equal(TokenKind.CSharp, token.Kind); content.Append(token.Content); } Assert.Equal("EndContext();", content.ToString()); } catch (XunitException e) { throw new IntermediateNodeAssertException(node, node.Children, e.Message, e); } }
public AleFile(IntermediateNode root) { //TODO: This is ugly foreach (var node in root) { switch (node.Name.ToLowerInvariant()) { case "aleffectlib": FxLib = new ALEffectLib((node as IntermediateNode) [0] as LeafNode); break; case "alchemynodelibrary": NodeLib = new AlchemyNodeLibrary((node as IntermediateNode) [0] as LeafNode); break; default: throw new NotImplementedException(node.Name); } } }
public static void Html(string expected, IntermediateNode node) { try { var html = Assert.IsType <HtmlContentIntermediateNode>(node); var content = new StringBuilder(); for (var i = 0; i < html.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(html.Children[i]); Assert.Equal(TokenKind.Html, token.Kind); content.Append(token.Content); } Assert.Equal(expected, content.ToString()); } catch (XunitException e) { throw new IntermediateNodeAssertException(node, node.Children, e.Message, e); } }
public static void BeginInstrumentation(string expected, IntermediateNode node) { try { var beginNode = Assert.IsType <CSharpCodeIntermediateNode>(node); var content = new StringBuilder(); for (var i = 0; i < beginNode.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(beginNode.Children[i]); Assert.True(token.IsCSharp); content.Append(token.Content); } Assert.Equal($"BeginContext({expected});", content.ToString()); } catch (XunitException e) { throw new IntermediateNodeAssertException(node, node.Children, e.Message, e); } }
public TxmFile(string path) : this() { foreach (Node node in parseFile(path)) { switch (node.Name.ToLowerInvariant()) { case "texture library": IntermediateNode textureLibraryNode = node as IntermediateNode; setTextures(textureLibraryNode); break; case "exporter version": break; default: throw new Exception("Invalid node in txm root: " + node.Name); } } }
public override void VisitDefault(IntermediateNode node) { var foundHtml = false; for (var i = 0; i < node.Children.Count; i++) { var child = node.Children[i]; Visit(child); if (child is HtmlContentIntermediateNode) { foundHtml = true; } } if (foundHtml) { RewriteChildren(_source, node); } }
public JointMap(IntermediateNode root) { foreach (Node node in root) { switch (node.Name.ToLowerInvariant()) { case "parent name": if (ParentName == null) { ParentName = (node as LeafNode).StringData; } else { throw new Exception("Multiple parent name nodes in channel root"); } break; case "child name": if (ChildName == null) { ChildName = (node as LeafNode).StringData; } else { throw new Exception("Multiple child name nodes in channel root"); } break; case "channel": if (Channel == null) { Channel = new Channel((node as IntermediateNode), false); } else { throw new Exception("Multiple data nodes in channel root"); } break; } } }
public CmpCameraInfo(IntermediateNode node) { var cameraNode = (node.FirstOrDefault((x) => x.Name.Equals("camera", StringComparison.OrdinalIgnoreCase)) as IntermediateNode); if (cameraNode == null) { FLLog.Error("Cmp", "Camera does not contain valid camera node"); //This won't be thrown in normal loading return; } foreach (var child in cameraNode) { var leaf = (child as LeafNode); if (leaf == null) { FLLog.Error("Cmp", "Invalid node in camera " + child.Name); continue; } switch (child.Name.ToLowerInvariant()) { case "znear": Znear = leaf.SingleData.Value; break; case "zfar": Zfar = leaf.SingleData.Value; break; case "fovx": Fovx = leaf.SingleData.Value; break; case "fovy": Fovy = leaf.SingleData.Value; break; default: FLLog.Error("Cmp", "Invalid node in camera " + child.Name); break; } } }
internal static void SetTagHelperProperty( string name, string propertyName, AttributeStructure valueStyle, IntermediateNode node, params Action <IntermediateNode>[] valueValidators) { var propertyNode = Assert.IsType <TagHelperPropertyIntermediateNode>(node); try { Assert.Equal(name, propertyNode.AttributeName); Assert.Equal(propertyName, propertyNode.BoundAttribute.GetPropertyName()); Assert.Equal(valueStyle, propertyNode.AttributeStructure); Children(propertyNode, valueValidators); } catch (XunitException e) { throw new IntermediateNodeAssertException(propertyNode, propertyNode.Children, e.Message, e); } }
private void EndNode(IntermediateNode node) { if (_content != null && (_properties.Count == 0 || ContentMode == FormatterContentMode.PreferContent)) { Writer.Write(" "); Writer.Write("\""); Writer.Write(EscapeNewlines(_content)); Writer.Write("\""); } if (_properties.Count > 0 && (_content == null || ContentMode == FormatterContentMode.PreferProperties)) { Writer.Write(" "); Writer.Write("{ "); Writer.Write(string.Join(", ", _properties.Select(kvp => $"{kvp.Key}: \"{kvp.Value}\""))); Writer.Write(" }"); } _content = null; _properties.Clear(); }
bool CopyTree_OnNodeBegin(IntermediateNode tree, IntermediateNode node, List <CopyTreeContext> stack, int depth) { node.Children.Sort(); _abstChanceTree.SetDepth(_nodesCount, (byte)depth); _abstChanceTree.Nodes[_nodesCount].Position = node.Position; _abstChanceTree.Nodes[_nodesCount].Card = node.Card; _abstChanceTree.Nodes[_nodesCount].Probab = node.Probab; if (_nodesCount > 0) { double[] potShare = new double[_gameDef.MinPlayers]; UInt16 [] activePlayers = depth == _maxDepth ? _activePlayersAll : _activePlayersOne; foreach (UInt16 ap in activePlayers) { node.GetPotShare(ap, potShare); _abstChanceTree.Nodes[_nodesCount].SetPotShare(ap, potShare); } } _nodesCount++; return(true); }
public Channel(IntermediateNode root) { byte[] frameBytes = new byte[0]; foreach (LeafNode channelSubNode in root) { switch (channelSubNode.Name.ToLowerInvariant()) { case "header": using (BinaryReader reader = new BinaryReader(new MemoryStream(channelSubNode.ByteArrayData))) { FrameCount = reader.ReadInt32(); Interval = reader.ReadSingle(); ChannelType = reader.ReadInt32(); } break; case "frames": frameBytes = channelSubNode.ByteArrayData; break; default: throw new Exception("Invalid node in " + root.Name + ": " + channelSubNode.Name); } } FrameType frameType = FrameType.Float; if ((ChannelType & 0xC0) == 0xC0) { frameType = FrameType.IK; } Frames = new Frame[FrameCount]; using (BinaryReader reader = new BinaryReader(new MemoryStream(frameBytes))) { for (int i = 0; i < FrameCount; i++) { Frames[i] = new Frame(reader, Interval == -1, frameType); } } }
public static void ConditionalAttribute( string prefix, string name, string suffix, IntermediateNode node, params Action <IntermediateNode>[] valueValidators) { var attribute = Assert.IsType <HtmlAttributeIntermediateNode>(node); try { Assert.Equal(prefix, attribute.Prefix); Assert.Equal(name, attribute.AttributeName); Assert.Equal(suffix, attribute.Suffix); Children(attribute, valueValidators); } catch (XunitException e) { throw new IntermediateNodeAssertException(attribute, attribute.Children, e.Message, e); } }
private bool TryGetFormatNode( IntermediateNode node, TagHelperPropertyIntermediateNode attributeNode, string valueAttributeName, out TagHelperPropertyIntermediateNode formatNode) { for (var i = 0; i < node.Children.Count; i++) { var child = node.Children[i] as TagHelperPropertyIntermediateNode; if (child != null && child.TagHelper != null && child.TagHelper == attributeNode.TagHelper && child.AttributeName == "format-" + valueAttributeName) { formatNode = child; return(true); } } formatNode = null; return(false); }
private bool ShouldGenerateField(IntermediateNode parent) { var parameters = parent.FindDescendantNodes <TagHelperDirectiveAttributeParameterIntermediateNode>(); for (var i = 0; i < parameters.Count; i++) { var parameter = parameters[i]; if (parameter.TagHelper.IsRefTagHelper() && parameter.BoundAttributeParameter.Name == "suppressField") { if (parameter.HasDiagnostics) { parent.Diagnostics.AddRange(parameter.GetAllDiagnostics()); } parent.Children.Remove(parameter); if (parameter.AttributeStructure == AttributeStructure.Minimized) { return(false); } // We do not support non-minimized attributes here because we can't allow the value to be dynamic. // As a design/experience decision, we don't let you write @ref:suppressField="false" even though // we could parse it. The rationale is that it's misleading, you type something that looks like code, // but it's not really. parent.Diagnostics.Add(ComponentDiagnosticFactory.Create_RefSuppressFieldNotMinimized(parameter.Source)); } } if (parent is ComponentIntermediateNode component && component.Component.IsGenericTypedComponent()) { // We cannot automatically generate a 'ref' field for generic components because we don't know // how to write the type. parent.Diagnostics.Add(ComponentDiagnosticFactory.Create_RefSuppressFieldRequiredForGeneric(parent.Source)); return(false); } return(true); }
public static void LiteralAttributeValue(string prefix, string expected, IntermediateNode node) { var attributeValue = Assert.IsType <HtmlAttributeValueIntermediateNode>(node); try { var content = new StringBuilder(); for (var i = 0; i < attributeValue.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(attributeValue.Children[i]); Assert.True(token.IsHtml); content.Append(token.Content); } Assert.Equal(prefix, attributeValue.Prefix); Assert.Equal(expected, content.ToString()); } catch (XunitException e) { throw new IntermediateNodeAssertException(attributeValue, e.Message); } }
public static HtmlAttributeIntermediateNode CSharpAttribute(IntermediateNode node, string attributeName, string attributeValue) { Assert.NotNull(node); var attributeNode = Assert.IsType <HtmlAttributeIntermediateNode>(node); Assert.Equal(attributeName, attributeNode.AttributeName); var attributeValueNode = Assert.IsType <CSharpExpressionAttributeValueIntermediateNode>(Assert.Single(attributeNode.Children)); var actual = new StringBuilder(); for (var i = 0; i < attributeValueNode.Children.Count; i++) { var token = Assert.IsAssignableFrom <IntermediateToken>(attributeValueNode.Children[i]); Assert.Equal(TokenKind.CSharp, token.Kind); actual.Append(token.Content); } Assert.Equal(attributeValue, actual.ToString()); return(attributeNode); }
public override void RenderChildren(IntermediateNode node, IntermediateNodeWriter writer) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } _scopes.Add(new ScopeInternal(writer)); _ancestors.Push(node); for (var i = 0; i < node.Children.Count; i++) { Visitor.Visit(node.Children[i]); } _ancestors.Pop(); _scopes.RemoveAt(_scopes.Count - 1); }
private void load(IntermediateNode root, ConstructCollection constructs) { Scripts = new Dictionary <string, Script>(); foreach (Node node in root) { switch (node.Name.ToLowerInvariant()) { case "script": foreach (IntermediateNode scNode in (IntermediateNode)node) { Scripts.Add(scNode.Name, new Script(scNode, constructs)); } break; case "anim_credits": //TODO: What is this? break; default: throw new Exception("Invalid node in " + root.Name + ": " + node.Name); } } }