Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ActorLook Parse(string str)
- {
- if (string.IsNullOrEmpty(str) || str[0] != '{')
- throw new Exception("Incorrect EntityLook format : " + str);
- var cursorPos = 1;
- var separatorPos = str.IndexOf('|');
- if (separatorPos == -1)
- {
- separatorPos = str.IndexOf("}");
- if (separatorPos == -1)
- throw new Exception("Incorrect EntityLook format : " + str);
- }
- var bonesId = short.Parse(str.Substring(cursorPos, separatorPos - cursorPos));
- cursorPos = separatorPos + 1;
- var skins = new short[0];
- if (( separatorPos = str.IndexOf('|', cursorPos) ) != -1 ||
- ( separatorPos = str.IndexOf('}', cursorPos) ) != -1)
- {
- skins = ParseCollection(str.Substring(cursorPos, separatorPos - cursorPos), short.Parse);
- cursorPos = separatorPos + 1;
- }
- var colors = new Tuple<int, int>[0];
- if (( separatorPos = str.IndexOf('|', cursorPos) ) != -1 ||
- ( separatorPos = str.IndexOf('}', cursorPos) ) != -1) // if false there are no informations between the two separators
- {
- colors = ParseCollection(str.Substring(cursorPos, separatorPos - cursorPos), ParseIndexedColor);
- cursorPos = separatorPos + 1;
- }
- var scales = new short[0];
- if (( separatorPos = str.IndexOf('|', cursorPos) ) != -1 ||
- ( separatorPos = str.IndexOf('}', cursorPos) ) != -1) // if false there are no informations between the two separators
- {
- scales = ParseCollection(str.Substring(cursorPos, separatorPos - cursorPos), short.Parse);
- cursorPos = separatorPos + 1;
- }
- var subEntities = new List<SubActorLook>();
- while (cursorPos < str.Length && (str.Length - cursorPos) >= 3)
- {
- var atSeparatorIndex = str.IndexOf('@', cursorPos, 3); // max size of a byte = 255, so 3 characters
- var equalsSeparatorIndex = str.IndexOf('=', atSeparatorIndex + 1, 3); // max size of a byte = 255, so 3 characters
- var category = byte.Parse(str.Substring(cursorPos, atSeparatorIndex - cursorPos));
- var index = byte.Parse(str.Substring(atSeparatorIndex + 1, equalsSeparatorIndex - ( atSeparatorIndex + 1 )));
- var hookDepth = 0;
- var i = equalsSeparatorIndex + 1;
- var subEntity = new StringBuilder();
- do
- {
- subEntity.Append(str[i]);
- switch (str[i])
- {
- case '{':
- hookDepth++;
- break;
- case '}':
- hookDepth--;
- break;
- }
- i++;
- } while (hookDepth > 0);
- subEntities.Add(new SubActorLook((sbyte)index, (SubEntityBindingPointCategoryEnum) category, Parse(subEntity.ToString())));
- cursorPos = i + 1; // ignore the comma and the last '}' char
- }
- return new ActorLook(bonesId, skins, colors.ToDictionary(x => x.Item1, x => Color.FromArgb(x.Item2)), scales, subEntities.ToArray());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement