Style: Remove CommandReader class, move stuff from ClassicalSharp.TexturePack to ClassicalSharp.Textures

This commit is contained in:
UnknownShadow200 2016-10-17 17:15:24 +11:00
parent d24a929267
commit f0047be63c
32 changed files with 92 additions and 178 deletions

View File

@ -2,7 +2,7 @@
using System; using System;
using ClassicalSharp.GraphicsAPI; using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Model; using ClassicalSharp.Model;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
namespace ClassicalSharp { namespace ClassicalSharp {

View File

@ -5,7 +5,7 @@ using ClassicalSharp.Events;
using ClassicalSharp.GraphicsAPI; using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Gui.Widgets; using ClassicalSharp.Gui.Widgets;
using ClassicalSharp.Model; using ClassicalSharp.Model;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {

View File

@ -4,7 +4,7 @@ using System.IO;
using ClassicalSharp.Entities; using ClassicalSharp.Entities;
using ClassicalSharp.Map; using ClassicalSharp.Map;
using ClassicalSharp.Gui.Widgets; using ClassicalSharp.Gui.Widgets;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
@ -61,7 +61,7 @@ namespace ClassicalSharp.Gui.Screens {
int width, height, length; int width, height, length;
game.World.Reset(); game.World.Reset();
if( game.World.TextureUrl != null ) { if( game.World.TextureUrl != null ) {
TexturePackExtractor.ExtractDefault( game ); TexturePack.ExtractDefault( game );
game.World.TextureUrl = null; game.World.TextureUrl = null;
} }
game.BlockInfo.Reset( game ); game.BlockInfo.Reset( game );

View File

@ -2,7 +2,7 @@
using System; using System;
using System.IO; using System.IO;
using ClassicalSharp.Gui.Widgets; using ClassicalSharp.Gui.Widgets;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
@ -10,7 +10,7 @@ namespace ClassicalSharp.Gui.Screens {
public TexturePackScreen( Game game ) : base( game ) { public TexturePackScreen( Game game ) : base( game ) {
titleText = "Select a texture pack zip"; titleText = "Select a texture pack zip";
string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string dir = Path.Combine( Program.AppDirectory, TexturePack.Dir );
entries = Directory.GetFiles( dir, "*.zip" ); entries = Directory.GetFiles( dir, "*.zip" );
for( int i = 0; i < entries.Length; i++ ) for( int i = 0; i < entries.Length; i++ )
@ -21,15 +21,13 @@ namespace ClassicalSharp.Gui.Screens {
protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) { protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return; if( mouseBtn != MouseButton.Left ) return;
string file = ((ButtonWidget)widget).Text; string file = ((ButtonWidget)widget).Text;
string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string dir = Path.Combine( Program.AppDirectory, TexturePack.Dir );
string path = Path.Combine( dir, file ); string path = Path.Combine( dir, file );
if( !File.Exists( path ) ) return; if( !File.Exists( path ) ) return;
int index = currentIndex; int index = currentIndex;
game.DefaultTexturePack = file; game.DefaultTexturePack = file;
game.World.TextureUrl = null; TexturePack.ExtractDefault( game );
TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( path, game );
Recreate(); Recreate();
SetCurrentIndex( index ); SetCurrentIndex( index );
} }

View File

@ -253,7 +253,6 @@
<Compile Include="Network\Utils\FixedBufferStream.cs" /> <Compile Include="Network\Utils\FixedBufferStream.cs" />
<Compile Include="Network\Utils\GZipHeaderReader.cs" /> <Compile Include="Network\Utils\GZipHeaderReader.cs" />
<Compile Include="Commands\CommandList.cs" /> <Compile Include="Commands\CommandList.cs" />
<Compile Include="Commands\CommandReader.cs" />
<Compile Include="Network\Utils\NetWriter.cs" /> <Compile Include="Network\Utils\NetWriter.cs" />
<Compile Include="Math\PickedPos.cs" /> <Compile Include="Math\PickedPos.cs" />
<Compile Include="Math\Picking.cs" /> <Compile Include="Math\Picking.cs" />
@ -295,7 +294,7 @@
<Compile Include="TexturePack\TextureCache.cs" /> <Compile Include="TexturePack\TextureCache.cs" />
<Compile Include="TexturePack\TerrainAtlas1D.cs" /> <Compile Include="TexturePack\TerrainAtlas1D.cs" />
<Compile Include="TexturePack\TerrainAtlas2D.cs" /> <Compile Include="TexturePack\TerrainAtlas2D.cs" />
<Compile Include="TexturePack\TexturePackExtractor.cs" /> <Compile Include="TexturePack\TexturePack.cs" />
<Compile Include="TexturePack\ZipReader.cs" /> <Compile Include="TexturePack\ZipReader.cs" />
<Compile Include="Utils\Camera.cs" /> <Compile Include="Utils\Camera.cs" />
<Compile Include="Utils\ErrorHandler.cs" /> <Compile Include="Utils\ErrorHandler.cs" />

View File

@ -16,6 +16,6 @@ namespace ClassicalSharp.Commands {
protected internal Game game; protected internal Game game;
public abstract void Execute( CommandReader reader ); public abstract void Execute( string[] args );
} }
} }

View File

@ -22,7 +22,6 @@ namespace ClassicalSharp.Commands {
Register( new CommandsCommand() ); Register( new CommandsCommand() );
Register( new GpuInfoCommand() ); Register( new GpuInfoCommand() );
Register( new HelpCommand() ); Register( new HelpCommand() );
Register( new InfoCommand() );
Register( new RenderTypeCommand() ); Register( new RenderTypeCommand() );
if( !game.Server.IsSinglePlayer ) return; if( !game.Server.IsSinglePlayer ) return;
@ -63,23 +62,25 @@ namespace ClassicalSharp.Commands {
return match; return match;
} }
static char[] splitChar = { ' ' };
public void Execute( string text ) { public void Execute( string text ) {
if( Utils.CaselessStarts( text, prefix ) ) { if( Utils.CaselessStarts( text, prefix ) ) { // /client command args
text = text.Substring( prefix.Length ).TrimStart( ' ' ); text = text.Substring( prefix.Length ).TrimStart( splitChar );
text = "/" + text; } else { // /command args
text = text.Substring( 1 );
} }
CommandReader reader = new CommandReader( text ); if( text.Length == 1 ) { // only / or /client
string cmdName = reader.Next();
if( cmdName == null ) {
game.Chat.Add( "&eList of client commands:" ); game.Chat.Add( "&eList of client commands:" );
PrintDefinedCommands( game ); PrintDefinedCommands( game );
game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" ); game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
return; return;
} }
Command cmd = GetMatch( cmdName ); string[] args = text.Split( splitChar );
if( cmd != null ) cmd.Execute( reader ); Command cmd = GetMatch( args[0] );
if( cmd == null ) return;
cmd.Execute( args );
} }
public void PrintDefinedCommands( Game game ) { public void PrintDefinedCommands( Game game ) {

View File

@ -1,40 +0,0 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
namespace ClassicalSharp.Commands {
/// <summary> Reads and parses arguments for a client command. </summary>
/// <remarks> Spaces are designated as the argument separators. </remarks>
public class CommandReader {
string rawInput;
int curOffset;
/// <summary> Returns the next argument, or null if there are no more arguments left. </summary>
public string Next() {
if( curOffset >= rawInput.Length ) return null;
int next = rawInput.IndexOf( ' ', curOffset );
if( next == -1 ) {
next = rawInput.Length;
}
string arg = rawInput.Substring( curOffset, next - curOffset );
curOffset = next + 1; // skip following space
return arg;
}
/// <summary> Returns all remaining arguments (including the space separators),
/// or null if there are no more arguments left. </summary>
public string NextAll() {
if( curOffset >= rawInput.Length ) return null;
string arg = rawInput.Substring( curOffset, rawInput.Length - curOffset );
curOffset = rawInput.Length;
return arg;
}
public CommandReader( string input ) {
rawInput = input.TrimEnd( ' ' );
curOffset = 1; // skip start / for the ocmmand
}
}
}

View File

@ -18,7 +18,7 @@ namespace ClassicalSharp.Commands {
}; };
} }
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
game.CommandList.PrintDefinedCommands( game ); game.CommandList.PrintDefinedCommands( game );
} }
} }
@ -34,14 +34,13 @@ namespace ClassicalSharp.Commands {
}; };
} }
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
string cmdName = reader.Next(); if( args.Length == 1 ) {
if( cmdName == null ) {
game.Chat.Add( "&eList of client commands:" ); game.Chat.Add( "&eList of client commands:" );
game.CommandList.PrintDefinedCommands( game ); game.CommandList.PrintDefinedCommands( game );
game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" ); game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
} else { } else {
Command cmd = game.CommandList.GetMatch( cmdName ); Command cmd = game.CommandList.GetMatch( args[1] );
if( cmd == null ) return; if( cmd == null ) return;
string[] help = cmd.Help; string[] help = cmd.Help;
for( int i = 0; i < help.Length; i++ ) for( int i = 0; i < help.Length; i++ )
@ -61,50 +60,13 @@ namespace ClassicalSharp.Commands {
}; };
} }
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
string[] lines = game.Graphics.ApiInfo; string[] lines = game.Graphics.ApiInfo;
for( int i = 0; i < lines.Length; i++ ) for( int i = 0; i < lines.Length; i++ )
game.Chat.Add( "&a" + lines[i] ); game.Chat.Add( "&a" + lines[i] );
} }
} }
public sealed class InfoCommand : Command {
public InfoCommand() {
Name = "Info";
Help = new [] {
"&a/client info [property]",
"&bproperties: &epos, target, dimensions, jumpheight",
};
}
public override void Execute( CommandReader reader ) {
string property = reader.Next();
if( property == null ) {
game.Chat.Add( "&e/client: &cYou didn't specify a property." );
} else if( Utils.CaselessEquals( property, "pos" ) ) {
game.Chat.Add( "Feet: " + game.LocalPlayer.Position );
game.Chat.Add( "Eye: " + game.LocalPlayer.EyePosition );
Vector3I p = Vector3I.Floor( game.LocalPlayer.Position );
game.Chat.Add( game.World.GetLightHeight( p.X, p.Z ).ToString() );
} else if( Utils.CaselessEquals( property, "target" ) ) {
PickedPos pos = game.SelectedPos;
if( !pos.Valid ) {
game.Chat.Add( "Currently not targeting a block" );
} else {
game.Chat.Add( "Currently targeting at: " + pos.BlockPos );
game.Chat.Add( "ID of block targeted: " + game.World.SafeGetBlock( pos.BlockPos ) );
}
} else if( Utils.CaselessEquals( property, "dimensions" ) ) {
game.Chat.Add( "map width: " + game.World.Width );
game.Chat.Add( "map height: " + game.World.Height );
game.Chat.Add( "map length: " + game.World.Length );
} else {
game.Chat.Add( "&e/client: Unrecognised property: \"&f" + property + "&e\"." );
}
}
}
public sealed class RenderTypeCommand : Command { public sealed class RenderTypeCommand : Command {
public RenderTypeCommand() { public RenderTypeCommand() {
@ -118,14 +80,13 @@ namespace ClassicalSharp.Commands {
}; };
} }
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
string property = reader.Next(); if( args.Length == 1 ) {
if( property == null ) {
game.Chat.Add( "&e/client: &cYou didn't specify a new render type." ); game.Chat.Add( "&e/client: &cYou didn't specify a new render type." );
} else if( game.SetRenderType( property ) ) { } else if( game.SetRenderType( args[1] ) ) {
game.Chat.Add( "&e/client: &fRender type is now " + property + "." ); game.Chat.Add( "&e/client: &fRender type is now " + args[1] + "." );
} else { } else {
game.Chat.Add( "&e/client: &cUnrecognised render type &f\"" + property + "\"&c." ); game.Chat.Add( "&e/client: &cUnrecognised render type &f\"" + args[1] + "\"&c." );
} }
} }
} }

View File

@ -19,12 +19,11 @@ namespace ClassicalSharp.Commands {
}; };
} }
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
string name = reader.Next(); if( args.Length == 1 ) {
if( String.IsNullOrEmpty( name ) ) {
game.Chat.Add( "&e/client model: &cYou didn't specify a model name." ); game.Chat.Add( "&e/client model: &cYou didn't specify a model name." );
} else { } else {
game.LocalPlayer.SetModel( Utils.ToLower( name ) ); game.LocalPlayer.SetModel( Utils.ToLower( args[1] ) );
} }
} }
} }
@ -45,33 +44,31 @@ namespace ClassicalSharp.Commands {
Vector3I mark1, mark2; Vector3I mark1, mark2;
bool persist = false; bool persist = false;
public override void Execute( CommandReader reader ) { public override void Execute( string[] args ) {
game.UserEvents.BlockChanged -= BlockChanged; game.UserEvents.BlockChanged -= BlockChanged;
block = 0xFF; block = 0xFF;
mark1 = new Vector3I( int.MaxValue ); mark1 = new Vector3I( int.MaxValue );
mark2 = new Vector3I( int.MaxValue ); mark2 = new Vector3I( int.MaxValue );
persist = false; persist = false;
if( !ParseBlock( reader ) ) return; if( !ParseBlock( args ) ) return;
string arg = reader.Next(); if( args.Length > 2 && Utils.CaselessEquals( args[2], "yes" ) )
if( arg != null && Utils.CaselessEquals( arg, "yes" ) )
persist = true; persist = true;
game.Chat.Add( "&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3 ); game.Chat.Add( "&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3 );
game.UserEvents.BlockChanged += BlockChanged; game.UserEvents.BlockChanged += BlockChanged;
} }
bool ParseBlock( CommandReader reader ) { bool ParseBlock( string[] args ) {
string id = reader.Next(); if( args.Length == 1 ) return true;
if( id == null ) return true; if( Utils.CaselessEquals( args[1], "yes" ) ) { persist = true; return true; }
if( Utils.CaselessEquals( id, "yes" ) ) { persist = true; return true; }
byte blockID = 0; byte blockID = 0;
if( !byte.TryParse( id, out blockID ) ) { if( !byte.TryParse( args[1], out blockID ) ) {
game.Chat.Add( "&eCuboid: &c\"" + id + "\" is not a valid block id." ); return false; game.Chat.Add( "&eCuboid: &c\"" + args[1] + "\" is not a valid block id." ); return false;
} }
if( blockID >= Block.CpeCount && game.BlockInfo.Name[blockID] == "Invalid" ) { if( blockID >= Block.CpeCount && game.BlockInfo.Name[blockID] == "Invalid" ) {
game.Chat.Add( "&eCuboid: &cThere is no block with id \"" + id + "\"." ); return false; game.Chat.Add( "&eCuboid: &cThere is no block with id \"" + args[1] + "\"." ); return false;
} }
block = blockID; block = blockID;
return true; return true;

View File

@ -4,7 +4,7 @@ using ClassicalSharp.Entities;
using ClassicalSharp.GraphicsAPI; using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Physics; using ClassicalSharp.Physics;
using ClassicalSharp.Renderers; using ClassicalSharp.Renderers;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
namespace ClassicalSharp.Model { namespace ClassicalSharp.Model {

View File

@ -13,7 +13,7 @@ using ClassicalSharp.Network;
using ClassicalSharp.Particles; using ClassicalSharp.Particles;
using ClassicalSharp.Renderers; using ClassicalSharp.Renderers;
using ClassicalSharp.Selections; using ClassicalSharp.Selections;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
#if ANDROID #if ANDROID
using Android.Graphics; using Android.Graphics;
#endif #endif
@ -134,7 +134,7 @@ namespace ClassicalSharp {
void ExtractInitialTexturePack() { void ExtractInitialTexturePack() {
defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip"; defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePack extractor = new TexturePack();
extractor.Extract( "default.zip", this ); extractor.Extract( "default.zip", this );
// in case the user's default texture pack doesn't have all required textures // in case the user's default texture pack doesn't have all required textures
if( DefaultTexturePack != "default.zip" ) if( DefaultTexturePack != "default.zip" )

View File

@ -16,7 +16,7 @@ using ClassicalSharp.Network;
using ClassicalSharp.Particles; using ClassicalSharp.Particles;
using ClassicalSharp.Renderers; using ClassicalSharp.Renderers;
using ClassicalSharp.Selections; using ClassicalSharp.Selections;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
@ -222,7 +222,7 @@ namespace ClassicalSharp {
/// this method returns "default.zip". </remarks> /// this method returns "default.zip". </remarks>
public string DefaultTexturePack { public string DefaultTexturePack {
get { get {
string path = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string path = Path.Combine( Program.AppDirectory, TexturePack.Dir );
path = Path.Combine( path, defTexturePack ); path = Path.Combine( path, defTexturePack );
return File.Exists( path ) && !ClassicMode ? defTexturePack : "default.zip"; return File.Exists( path ) && !ClassicMode ? defTexturePack : "default.zip";
} }

View File

@ -17,7 +17,7 @@ using ClassicalSharp.Network;
using ClassicalSharp.Particles; using ClassicalSharp.Particles;
using ClassicalSharp.Renderers; using ClassicalSharp.Renderers;
using ClassicalSharp.Selections; using ClassicalSharp.Selections;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
#if ANDROID #if ANDROID
@ -258,7 +258,7 @@ namespace ClassicalSharp {
Drawer2D.InitColours(); Drawer2D.InitColours();
BlockInfo.Reset( this ); BlockInfo.Reset( this );
TexturePackExtractor.ExtractDefault( this ); TexturePack.ExtractDefault( this );
Gui.SetNewScreen( new ErrorScreen( this, title, reason ) ); Gui.SetNewScreen( new ErrorScreen( this, title, reason ) );
GC.Collect(); GC.Collect();
} }

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ClassicalSharp.GraphicsAPI; using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
namespace ClassicalSharp { namespace ClassicalSharp {

View File

@ -5,7 +5,7 @@ using System.IO;
using System.Net; using System.Net;
using ClassicalSharp.Gui.Screens; using ClassicalSharp.Gui.Screens;
using ClassicalSharp.Network; using ClassicalSharp.Network;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
#if ANDROID #if ANDROID
@ -117,10 +117,10 @@ namespace ClassicalSharp {
protected void CheckAsyncResources() { protected void CheckAsyncResources() {
DownloadedItem item; DownloadedItem item;
if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) { if( game.AsyncDownloader.TryGetItem( "terrain", out item ) ) {
TexturePackExtractor.ExtractTerrainPng( game, item ); TexturePack.ExtractTerrainPng( game, item.Url, item );
} }
if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) { if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
TexturePackExtractor.ExtractTexturePack( game, item ); TexturePack.ExtractTexturePack( game, item.Url, item );
} }
} }
#endregion #endregion

View File

@ -8,7 +8,7 @@ using ClassicalSharp.Entities;
using ClassicalSharp.Events; using ClassicalSharp.Events;
using ClassicalSharp.Gui; using ClassicalSharp.Gui;
using ClassicalSharp.Network; using ClassicalSharp.Network;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using ClassicalSharp.Network.Protocols; using ClassicalSharp.Network.Protocols;
namespace ClassicalSharp.Network { namespace ClassicalSharp.Network {

View File

@ -3,7 +3,7 @@ using System;
using ClassicalSharp.Entities; using ClassicalSharp.Entities;
using ClassicalSharp.Hotkeys; using ClassicalSharp.Hotkeys;
using ClassicalSharp.Map; using ClassicalSharp.Map;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK.Input; using OpenTK.Input;
namespace ClassicalSharp.Network.Protocols { namespace ClassicalSharp.Network.Protocols {
@ -312,7 +312,7 @@ namespace ClassicalSharp.Network.Protocols {
if( !game.AllowServerTextures ) return; if( !game.AllowServerTextures ) return;
if( url == "" ) { if( url == "" ) {
TexturePackExtractor.ExtractDefault( game ); TexturePack.ExtractDefault( game );
} else if( Utils.IsUrlPrefix( url, 0 ) ) { } else if( Utils.IsUrlPrefix( url, 0 ) ) {
net.RetrieveTexturePack( url ); net.RetrieveTexturePack( url );
} }

View File

@ -2,7 +2,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK; using OpenTK;
namespace ClassicalSharp { namespace ClassicalSharp {
@ -21,7 +21,7 @@ namespace ClassicalSharp {
CleanupMainDirectory(); CleanupMainDirectory();
Utils.LogDebug( "Starting " + AppName + ".." ); Utils.LogDebug( "Starting " + AppName + ".." );
string path = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string path = Path.Combine( Program.AppDirectory, TexturePack.Dir );
if( !File.Exists( Path.Combine( path, "default.zip" ) ) ) { if( !File.Exists( Path.Combine( path, "default.zip" ) ) ) {
Utils.LogDebug( "default.zip not found. Cannot start." ); Utils.LogDebug( "default.zip not found. Cannot start." );
return; return;
@ -85,7 +85,7 @@ namespace ClassicalSharp {
string mapPath = Path.Combine( Program.AppDirectory, "maps" ); string mapPath = Path.Combine( Program.AppDirectory, "maps" );
if( !Directory.Exists( mapPath ) ) if( !Directory.Exists( mapPath ) )
Directory.CreateDirectory( mapPath ); Directory.CreateDirectory( mapPath );
string texPath = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string texPath = Path.Combine( Program.AppDirectory, TexturePack.Dir );
if( !Directory.Exists( texPath ) ) if( !Directory.Exists( texPath ) )
Directory.CreateDirectory( texPath ); Directory.CreateDirectory( texPath );

View File

@ -9,7 +9,7 @@ using ClassicalSharp.GraphicsAPI;
using Android.Graphics; using Android.Graphics;
#endif #endif
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
/// <summary> Contains and describes the various animations applied to the terrain atlas. </summary> /// <summary> Contains and describes the various animations applied to the terrain atlas. </summary>
public class Animations : IGameComponent { public class Animations : IGameComponent {

View File

@ -3,7 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
public sealed class EntryList { public sealed class EntryList {

View File

@ -6,7 +6,7 @@ using ClassicalSharp.GraphicsAPI;
using Android.Graphics; using Android.Graphics;
#endif #endif
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
/// <summary> Represents a 2D packed texture atlas that has been converted into an array of 1D atlases. </summary> /// <summary> Represents a 2D packed texture atlas that has been converted into an array of 1D atlases. </summary>
public sealed class TerrainAtlas1D : IDisposable { public sealed class TerrainAtlas1D : IDisposable {

View File

@ -8,7 +8,7 @@ using Android.Graphics;
#endif #endif
using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
/// <summary> Caches terrain atlases and texture packs to avoid making redundant downloads. </summary> /// <summary> Caches terrain atlases and texture packs to avoid making redundant downloads. </summary>
public static class TextureCache { public static class TextureCache {

View File

@ -10,10 +10,10 @@ using Android.Graphics;
#endif #endif
using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
/// <summary> Extracts resources from a .zip texture pack. </summary> /// <summary> Extracts resources from a .zip texture pack. </summary>
public sealed class TexturePackExtractor { public sealed class TexturePack {
public const string Dir = "texpacks"; public const string Dir = "texpacks";
Game game; Game game;
@ -45,8 +45,8 @@ namespace ClassicalSharp.TexturePack {
} }
internal static void ExtractTerrainPng( Game game, DownloadedItem item ) { internal static void ExtractTerrainPng( Game game, string url, DownloadedItem item ) {
if( item.Data != null ) { if( item != null && item.Data != null ) {
Bitmap bmp = (Bitmap)item.Data; Bitmap bmp = (Bitmap)item.Data;
game.World.TextureUrl = item.Url; game.World.TextureUrl = item.Url;
game.Events.RaiseTexturePackChanged(); game.Events.RaiseTexturePackChanged();
@ -61,14 +61,14 @@ namespace ClassicalSharp.TexturePack {
TextureCache.AddETag( item.Url, item.ETag, game.ETags ); TextureCache.AddETag( item.Url, item.ETag, game.ETags );
TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified ); TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified );
} else { } else {
FileStream data = TextureCache.GetStream( item.Url ); FileStream data = TextureCache.GetStream( url );
if( data == null ) { // e.g. 404 errors if( data == null ) { // e.g. 404 errors
ExtractDefault( game ); ExtractDefault( game );
} else if( item.Url != game.World.TextureUrl ) { } else if( url != game.World.TextureUrl ) {
Bitmap bmp = GetBitmap( data ); Bitmap bmp = GetBitmap( data );
if( bmp == null ) { data.Dispose(); return; } if( bmp == null ) { data.Dispose(); return; }
game.World.TextureUrl = item.Url; game.World.TextureUrl = url;
game.Events.RaiseTexturePackChanged(); game.Events.RaiseTexturePackChanged();
if( game.ChangeTerrainAtlas( bmp, data ) ) return; if( game.ChangeTerrainAtlas( bmp, data ) ) return;
@ -80,11 +80,11 @@ namespace ClassicalSharp.TexturePack {
} }
} }
internal static void ExtractTexturePack( Game game, DownloadedItem item ) { internal static void ExtractTexturePack( Game game, string url, DownloadedItem item ) {
if( item.Data != null ) { if( item != null && item.Data != null ) {
game.World.TextureUrl = item.Url; game.World.TextureUrl = item.Url;
byte[] data = (byte[])item.Data; byte[] data = (byte[])item.Data;
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePack extractor = new TexturePack();
using( Stream ms = new MemoryStream( data ) ) { using( Stream ms = new MemoryStream( data ) ) {
extractor.Extract( ms, game ); extractor.Extract( ms, game );
} }
@ -93,12 +93,12 @@ namespace ClassicalSharp.TexturePack {
TextureCache.AddETag( item.Url, item.ETag, game.ETags ); TextureCache.AddETag( item.Url, item.ETag, game.ETags );
TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified ); TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified );
} else { } else {
FileStream data = TextureCache.GetStream( item.Url ); FileStream data = TextureCache.GetStream( url );
if( data == null ) { // e.g. 404 errors if( data == null ) { // e.g. 404 errors
ExtractDefault( game ); ExtractDefault( game );
} else if( item.Url != game.World.TextureUrl ) { } else if( url != game.World.TextureUrl ) {
game.World.TextureUrl = item.Url; game.World.TextureUrl = url;
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePack extractor = new TexturePack();
extractor.Extract( data, game ); extractor.Extract( data, game );
} }
} }
@ -106,7 +106,7 @@ namespace ClassicalSharp.TexturePack {
internal static void ExtractDefault( Game game ) { internal static void ExtractDefault( Game game ) {
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePack extractor = new TexturePack();
extractor.Extract( game.DefaultTexturePack, game ); extractor.Extract( game.DefaultTexturePack, game );
game.World.TextureUrl = null; game.World.TextureUrl = null;
} }

View File

@ -4,7 +4,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Text; using System.Text;
namespace ClassicalSharp.TexturePack { namespace ClassicalSharp.Textures {
public struct ZipEntry { public struct ZipEntry {
public int CompressedDataSize, UncompressedDataSize; public int CompressedDataSize, UncompressedDataSize;

View File

@ -2,9 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using OpenTK;
using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
@ -149,7 +147,7 @@ namespace ClassicalSharp {
if( Program.AppDirectory == null ) if( Program.AppDirectory == null )
Program.AppDirectory = AppDomain.CurrentDomain.BaseDirectory; Program.AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
string defZip = Path.Combine( Program.AppDirectory, "default.zip" ); string defZip = Path.Combine( Program.AppDirectory, "default.zip" );
string texDir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string texDir = Path.Combine( Program.AppDirectory, TexturePack.Dir );
if( File.Exists( defZip ) || !Directory.Exists( texDir ) ) if( File.Exists( defZip ) || !Directory.Exists( texDir ) )
Program.CleanupMainDirectory(); Program.CleanupMainDirectory();

View File

@ -3,7 +3,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using ClassicalSharp; using ClassicalSharp;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using Launcher.Drawing; using Launcher.Drawing;
namespace Launcher { namespace Launcher {

View File

@ -4,7 +4,7 @@ using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using ClassicalSharp; using ClassicalSharp;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
namespace Launcher.Patcher { namespace Launcher.Patcher {

View File

@ -1,7 +1,7 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT // ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System; using System;
using System.IO; using System.IO;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
namespace Launcher.Patcher { namespace Launcher.Patcher {

View File

@ -5,7 +5,7 @@ using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using ClassicalSharp; using ClassicalSharp;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
namespace Launcher.Patcher { namespace Launcher.Patcher {

View File

@ -4,7 +4,7 @@ using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Text; using System.Text;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
namespace Launcher.Patcher { namespace Launcher.Patcher {

View File

@ -6,7 +6,7 @@ using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using ClassicalSharp; using ClassicalSharp;
using ClassicalSharp.TexturePack; using ClassicalSharp.Textures;
using Launcher.Web; using Launcher.Web;
namespace Launcher.Updater { namespace Launcher.Updater {