Esempio n. 1
0
 public void AddChild(VMTDataWrapper child)
 {
     if (children == null)
     {
         children = new List <VMTDataWrapper>();
     }
     children.Add(child);
 }
Esempio n. 2
0
        private void Parse(byte[] byteData)
        {
            string originalVmtString = System.Text.Encoding.ASCII.GetString(byteData);

            wrappedData = VMTDataWrapper.WrapData(originalVmtString);


            if (wrappedData.IsOfType("patch"))
            {
                includedVmtPath = wrappedData.GetValue("include");
            }
            else//if (wrappedData.dataTitle.Equals("lightmappedgeneric"))
            {
                string surfaceProp = wrappedData.GetValue("$surfaceprop");
                if (!string.IsNullOrEmpty(surfaceProp) && surfaceProp.Equals("metal", System.StringComparison.OrdinalIgnoreCase))
                {
                    string tempBaseTexturePath = wrappedData.GetValue("$basetexture");
                    if (!string.IsNullOrEmpty(tempBaseTexturePath))
                    {
                        baseTexturePath = tempBaseTexturePath;
                    }

                    detailMapPath = wrappedData.GetValue("$detail");
                    //glossiness = 0.5f;
                }
                else
                {
                    baseTexturePath = wrappedData.GetValue("$basetexture");
                    //glossiness = 0;
                }

                glossiness      = 0;
                bumpMapPath     = wrappedData.GetValue("$bumpmap");
                hasTransparency = !string.IsNullOrEmpty(wrappedData.GetValue("$alphatest"));
            }
        }
Esempio n. 3
0
        public static VMTDataWrapper WrapData(string originalVmtString)
        {
            string         modifiedVmtString = originalVmtString;
            VMTDataWrapper currentVmtWrapper = new VMTDataWrapper();

            var nextEncapsulator = encapsulatorRegex.Match(modifiedVmtString);

            if (nextEncapsulator.Success)
            {
                currentVmtWrapper.dataTitle = titleRegex.Match(nextEncapsulator.Value).Value.ToLower();
                modifiedVmtString           = modifiedVmtString.Substring(nextEncapsulator.Index + nextEncapsulator.Length);
                int endEncapsulationIndex = modifiedVmtString.LastIndexOf("}");
                if (endEncapsulationIndex < 0)
                {
                    endEncapsulationIndex = modifiedVmtString.Length;
                }

                modifiedVmtString = modifiedVmtString.Substring(0, endEncapsulationIndex);

                string nextSubstring    = "";
                Match  peekEncapsulator = encapsulatorRegex.Match(modifiedVmtString);
                do
                {
                    peekEncapsulator = encapsulatorRegex.Match(modifiedVmtString);
                    if (peekEncapsulator.Success)
                    {
                        endEncapsulationIndex = FindEncapsulationEnd(modifiedVmtString, peekEncapsulator.Index + peekEncapsulator.Length);
                        if (endEncapsulationIndex < 0)
                        {
                            endEncapsulationIndex = modifiedVmtString.Length - 1;
                        }

                        int length = endEncapsulationIndex - peekEncapsulator.Index + 1;
                        if (length >= 0)
                        {
                            nextSubstring     = modifiedVmtString.Substring(peekEncapsulator.Index, length);
                            modifiedVmtString = modifiedVmtString.Substring(0, peekEncapsulator.Index) + modifiedVmtString.Substring(endEncapsulationIndex + 1);
                            currentVmtWrapper.AddChild(WrapData(nextSubstring));
                        }
                        else
                        {
                            Debug.LogError("VMTData: Next substring's length was less than zero in..\n\n" + originalVmtString);
                        }
                    }
                }while (peekEncapsulator.Success);

                var valuePairs = valuePairsRegex.Matches(modifiedVmtString);
                for (int i = 0; i < valuePairs.Count; i++)
                {
                    var    titleMatch       = titleRegex.Match(valuePairs[i].Value);
                    string valueName        = titleMatch.Value.ToLower();
                    int    cutIndex         = titleMatch.Index + titleMatch.Length + 1;
                    string secondHalfOfPair = "";
                    if (cutIndex < valuePairs[i].Value.Length)
                    {
                        secondHalfOfPair = valuePairs[i].Value.Substring(cutIndex).Trim();
                    }
                    string value = valueRegex.Match(secondHalfOfPair).Value;
                    currentVmtWrapper.SetValue(valueName, value);
                }
            }

            return(currentVmtWrapper);
        }