Ejemplo n.º 1
0
 public static unsafe ABaseAssetType[] Load(byte[] buffer)
 {
     if (buffer == null)
     {
         return null;
     }
     string theString;
     fixed (byte* pBuffer = &buffer[0])
     {
         theString = BufferReader.ReadString(pBuffer, buffer.Length);
     }
     Tokenizer tokenizer = new Tokenizer(theString, _iniExpressions, addNewLine: true);
     tokenizer.First();
     List<ABaseAssetType> result = new List<ABaseAssetType>();
     Tokenizer.Token token;
     ABaseAssetType currentObject = null;
     IniTypeDescription type = null;
     Match match;
     TypeHash typeHash;
     uint hash;
     while (tokenizer.Current() != null)
     {
         CommonParser.GoToValue(tokenizer);
         if ((token = tokenizer.Current()).Type != EXPRESSION_OBJECTSTART)
         {
             throw new OpenSAGEException(ErrorCode.IniParser, "Token '$TOKEN$' was not recognized", "token", token);
         }
         hash = GetHash(tokenizer);
         match = _objectTypeAndId.Match(token.Value);
         typeHash = match.Groups["type"].Value;
         type = _descriptions.Find(x => x.Name == typeHash);
         if (type == null)
         {
             throw new OpenSAGEException(ErrorCode.IniParser, "No object of type $TYPE$ can be instanciated.", "type", typeHash.TheString);
         }
         currentObject = Activator.CreateInstance(type.Type, match.Groups["id"].Value, hash) as ABaseAssetType;
         tokenizer.Next();
         Parse(tokenizer, currentObject, type);
         result.Add(currentObject);
     }
     return result.ToArray();
 }
Ejemplo n.º 2
0
 public unsafe void Load(byte[] buffer)
 {
     if (buffer == null)
     {
         return;
     }
     string theString;
     fixed (byte* pBuffer = &buffer[0])
     {
         theString = BufferReader.ReadString(pBuffer, buffer.Length);
     }
     Tokenizer tokenizer = new Tokenizer(theString, _datExpressions, addNewLine: true);
     tokenizer.First();
     Tokenizer.Token token;
     Character currentCharacter;
     while ((token = tokenizer.Current()) != null)
     {
         if (token.Type == CommonParser.EXPRESSION_COMMENT || token.Type == Tokenizer.EXPRESSION_END_OF_LINE)
         {
             CommonParser.GoToValue(tokenizer);
             continue;
         }
         if (token.Type != Tokenizer.EXPRESSION_NUMBER)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
         }
         currentCharacter = new Character(uint.Parse(token.Value));
         if ((token = tokenizer.Next()).Type != EXPRESSION_IMAGE && token.Type != EXPRESSION_TEXTURE)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
         }
         ISource source = null;
         switch (token.Type)
         {
             case EXPRESSION_IMAGE:
                 SourceImage sourceImage = new SourceImage();
                 token = tokenizer.Next();
                 if (token.Type == EXPRESSION_SOURCE_STANDARD)
                 {
                     sourceImage.Type = SourceImageType.STANDARD;
                 }
                 else if (token.Type == EXPRESSION_SOURCE_CLASSIC)
                 {
                     sourceImage.Type = SourceImageType.CLASSIC;
                 }
                 else
                 {
                     throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
                 }
                 sourceImage.X = int.Parse(token.Match.Groups["X"].Value);
                 sourceImage.Y = int.Parse(token.Match.Groups["Y"].Value);
                 sourceImage.Width = int.Parse(token.Match.Groups["Width"].Value);
                 sourceImage.Height = int.Parse(token.Match.Groups["Height"].Value);
                 source = sourceImage;
                 break;
             case EXPRESSION_TEXTURE:
                 SourceTexture sourceTexture = new SourceTexture();
                 token = tokenizer.Next();
                 if (token.Type != Tokenizer.EXPRESSION_NUMBER)
                 {
                     throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
                 }
                 sourceTexture.Id = int.Parse(token.Value);
                 source = sourceTexture;
                 break;
         }
         currentCharacter.Source = source;
         _characters.Add(currentCharacter);
         tokenizer.Next();
     }
 }
Ejemplo n.º 3
0
 public unsafe void Load(byte[] buffer)
 {
     if (buffer == null)
     {
         return;
     }
     string theString;
     fixed (byte* pBuffer = &buffer[0])
     {
         theString = BufferReader.ReadString(pBuffer, buffer.Length);
     }
     Tokenizer tokenizer = new Tokenizer(theString, _geometryExpressions, addNewLine: true);
     tokenizer.First();
     Tokenizer.Token token;
     Character currentCharacter;
     while (tokenizer.Current() != null)
     {
         if (tokenizer.Current().Type != EXPRESSION_CHARACTER)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
         }
         currentCharacter = new Character();
         tokenizer.Next();
         CommonParser.GoToValue(tokenizer);
         if (tokenizer.Current().Type != EXPRESSION_SHAPE)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
         }
         IShape shape = null;
         token = tokenizer.Next();
         switch (token.Type)
         {
             case EXPRESSION_SHAPE_SOLID:
                 ShapeSolid shapeSolid = new ShapeSolid();
                 shapeSolid.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shape = shapeSolid;
                 break;
             case EXPRESSION_SHAPE_LINE:
                 ShapeLine shapeLine = new ShapeLine();
                 shapeLine.Width = float.Parse(token.Match.Groups["Width"].Value);
                 shapeLine.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shape = shapeLine;
                 break;
             case EXPRESSION_SHAPE_TEXTURE:
                 ShapeTexture shapeTexture = new ShapeTexture();
                 shapeTexture.Color = new Color(
                     byte.Parse(token.Match.Groups["C"].Captures[0].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[1].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[2].Value),
                     byte.Parse(token.Match.Groups["C"].Captures[3].Value));
                 shapeTexture.TextureId = uint.Parse(token.Match.Groups["TextureId"].Value);
                 shapeTexture.Rotation = new Matrix2x2(
                     float.Parse(token.Match.Groups["R"].Captures[0].Value),
                     float.Parse(token.Match.Groups["R"].Captures[1].Value),
                     float.Parse(token.Match.Groups["R"].Captures[2].Value),
                     float.Parse(token.Match.Groups["R"].Captures[3].Value));
                 shapeTexture.Translation = new Vector2(
                     float.Parse(token.Match.Groups["T"].Captures[0].Value),
                     float.Parse(token.Match.Groups["T"].Captures[1].Value));
                 shape = shapeTexture;
                 break;
         }
         currentCharacter.TheShape.Type = shape;
         tokenizer.Next();
         CommonParser.GoToValue(tokenizer);
         while ((token = tokenizer.Current()) != null && token.Type != EXPRESSION_CHARACTER)
         {
             IShapeItem item = null;
             switch (token.Type)
             {
                 case EXPRESSION_LINE:
                     ItemLine itemLine = new ItemLine();
                     itemLine.Start = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[0].Value),
                         float.Parse(token.Match.Groups["V"].Captures[1].Value));
                     itemLine.End = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[2].Value),
                         float.Parse(token.Match.Groups["V"].Captures[3].Value));
                     item = itemLine;
                     break;
                 case EXPRESSION_TRIANGLE:
                     ItemTriangle itemTriangle = new ItemTriangle();
                     itemTriangle.V0 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[0].Value),
                         float.Parse(token.Match.Groups["V"].Captures[1].Value));
                     itemTriangle.V1 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[2].Value),
                         float.Parse(token.Match.Groups["V"].Captures[3].Value));
                     itemTriangle.V2 = new Vector2(
                         float.Parse(token.Match.Groups["V"].Captures[4].Value),
                         float.Parse(token.Match.Groups["V"].Captures[5].Value));
                     item = itemTriangle;
                     break;
             }
             currentCharacter.TheShape.Items.Add(item);
             tokenizer.Next();
             CommonParser.GoToValue(tokenizer);
         }
         _characters.Add(currentCharacter);
     }
 }