public static SkiStuntLevel LoadFolder( string folder ) { SkiStuntLevel level = new SkiStuntLevel( folder ); if( ! File.Exists( folder + "\\studioFile.txt" ) ) return level; StreamReader studioFile = new StreamReader( folder + "\\studioFile.txt", false ); level.LevelTitle = studioFile.ReadLine(); level.GoalText = studioFile.ReadLine(); level.HintText = studioFile.ReadLine(); level.PlayerStart.x = float.Parse( studioFile.ReadLine() ); level.PlayerStart.y = float.Parse( studioFile.ReadLine() ); level.endzoneA.x = float.Parse( studioFile.ReadLine() ); level.endzoneA.y = float.Parse( studioFile.ReadLine() ); level.endzoneB.x = float.Parse( studioFile.ReadLine() ); level.endzoneB.y = float.Parse( studioFile.ReadLine() ); level.EndzoneRequirements = (EndzoneRequirementType)uint.Parse( studioFile.ReadLine() ); int vertexCount = int.Parse( studioFile.ReadLine() ); for( int i = 0 ; i < vertexCount ; ++i ) { level.vertices.Add( new LevelVertex ( float.Parse( studioFile.ReadLine() ), float.Parse( studioFile.ReadLine() ), int .Parse( studioFile.ReadLine() ) )); } int polygonCount = int.Parse( studioFile.ReadLine() ); for( int i = 0 ; i < polygonCount ; ++i ) { LevelPolygon p = new LevelPolygon(); p.Friction = float.Parse( studioFile.ReadLine() ); p.Bounce = float.Parse( studioFile.ReadLine() ); p.Solidity = float.Parse( studioFile.ReadLine() ); p.SolidAtAll = bool.Parse( studioFile.ReadLine() ); p.TextureID = int.Parse( studioFile.ReadLine() ); if( p.TextureID >= 0 ) { p.TextureOffsetX = float.Parse( studioFile.ReadLine() ); p.TextureOffsetY = float.Parse( studioFile.ReadLine() ); p.TextureScaleX = float.Parse( studioFile.ReadLine() ); p.TextureScaleY = float.Parse( studioFile.ReadLine() ); } else { p.Color = Color.FromArgb( int.Parse( studioFile.ReadLine() ) ); } int polyVertCount = int.Parse( studioFile.ReadLine() ); for( int j = 0 ; j < polyVertCount ; ++j ) { p.AddVertex( level.vertices[ int.Parse( studioFile.ReadLine() ) ] ); } level.AddPolygon( p ); } int objectCount = int.Parse( studioFile.ReadLine() ); for( int i = 0 ; i < objectCount ; ++i ) { LevelObject o = new LevelObject(); o.x = float.Parse( studioFile.ReadLine() ); o.y = float.Parse( studioFile.ReadLine() ); o.rotation = float.Parse( studioFile.ReadLine() ); o.type = (LevelObject.ObjectType)uint.Parse( studioFile.ReadLine() ); o.anchor = (LevelObject.AnchorType)uint.Parse( studioFile.ReadLine() ); level.AddObject( o ); } studioFile.Close(); return level; }
/** * <summary> * This function will generate a polygon from a set of points described in the format Ski Stunt Simulator uses (GND.TXT / GND.PTS). * It can be used to import an existing level shape, or a single polygon from another Studio level. * </summary> */ public static LevelPolygon CreateFromFile( string path ) { char[] separators = { ' ', '\t' }; string[] curLine; int curLegitIndex; float curReadX = 0.0f; LevelPolygon ret = new LevelPolygon(); using( StreamReader s = new StreamReader( path ) ) { while( !s.EndOfStream ) { curLegitIndex = 0; curLine = s.ReadLine().Split( separators ); for( int i = 0 ; i < curLine.Length ; ++i ) { if( curLine[i].Length == 0 ) continue; switch( curLegitIndex++ ) { case 0: curReadX = float.Parse( curLine[i] ); break; case 1: ret.AddVertex( new LevelVertex( curReadX, -float.Parse( curLine[i] ) ) ); break; case 2: ret.Friction = float.Parse( curLine[i] ); break; } } } s.Close(); } return ret; }