Rev 1304 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BauzoidNET.parser;
namespace BauzoidNET
.graphics.sprite
{
public class SpriteUtil
{
public class SpriteRegionInfo
{
public float x
;
public float y
;
public float w
;
public float h
;
public SpriteRegionInfo
(float _x,
float _y,
float _w,
float _h
)
{
x
= _x
; y
= _y
; w
= _w
; h
= _h
;
}
}
private SpriteUtil
() { }
public static List
<SpriteRegionInfo
> readSpriteRegionInfo
(String filename
)
{
string text
= System.IO.File.ReadAllText(filename
);
Tokenizer t
= new Tokenizer
(text
);
t
.setStringDelimiter(new char[] { '\'',
'"' });
List
<SpriteRegionInfo
> result
= new List
<SpriteRegionInfo
>();
while (!t
.checkNoMoreTokens())
{
string identifier
= t
.readIdentifier();
if (identifier
.Equals("frame", StringComparison
.OrdinalIgnoreCase))
{
SpriteRegionInfo region
= readFrameLine
(t
);
result
.Add(region
);
}
else
{
// error
throw new ScanException
("Syntax error at: " + t
.getSurroundings());
}
}
return result
;
}
static private SpriteRegionInfo readFrameLine
(Tokenizer t
)
{
float x
= 0;
float y
= 0;
float w
= 0;
float h
= 0;
x
= t
.readNumber();
t
.readToken(", ");
y
= t
.readNumber();
t
.readToken(", ");
w
= t
.readNumber();
t
.readToken(", ");
h
= t
.readNumber();
t
.readToken(";");
return new SpriteRegionInfo
(x, y, w, h
);
}
}
}