From f0047be63c2231f91fe46660d0b892e975c31270 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 17 Oct 2016 17:15:24 +1100 Subject: [PATCH] Style: Remove CommandReader class, move stuff from ClassicalSharp.TexturePack to ClassicalSharp.Textures --- ClassicalSharp/2D/IsometricBlockDrawer.cs | 2 +- ClassicalSharp/2D/Screens/LoadingMapScreen.cs | 2 +- .../2D/Screens/Menu/LoadLevelScreen.cs | 4 +- .../2D/Screens/Menu/TexturePackScreen.cs | 10 ++-- ClassicalSharp/ClassicalSharp.csproj | 3 +- ClassicalSharp/Commands/Command.cs | 2 +- ClassicalSharp/Commands/CommandList.cs | 27 +++++---- ClassicalSharp/Commands/CommandReader.cs | 40 ------------- ClassicalSharp/Commands/DefaultCommands.cs | 59 ++++--------------- .../Commands/SinglePlayerCommands.cs | 27 ++++----- ClassicalSharp/Entities/Model/BlockModel.cs | 2 +- ClassicalSharp/Game/Game.Init.cs | 4 +- ClassicalSharp/Game/Game.Properties.cs | 4 +- ClassicalSharp/Game/Game.cs | 4 +- ClassicalSharp/MeshBuilder/TileDrawer.cs | 2 +- ClassicalSharp/Network/IServerConnection.cs | 6 +- ClassicalSharp/Network/NetworkProcessor.cs | 2 +- ClassicalSharp/Network/Protocols/CPE.cs | 4 +- ClassicalSharp/Program.cs | 6 +- ClassicalSharp/TexturePack/Animations.cs | 2 +- ClassicalSharp/TexturePack/EntryList.cs | 4 +- ClassicalSharp/TexturePack/TerrainAtlas1D.cs | 2 +- ClassicalSharp/TexturePack/TextureCache.cs | 2 +- ...TexturePackExtractor.cs => TexturePack.cs} | 30 +++++----- ClassicalSharp/TexturePack/ZipReader.cs | 2 +- ClassicalSharp/Utils/Options.cs | 6 +- Launcher2/LauncherWindow.Background.cs | 2 +- Launcher2/Patcher/BinUnpacker.cs | 2 +- Launcher2/Patcher/ResourceChecker.cs | 2 +- Launcher2/Patcher/ResourcePatcher.cs | 2 +- Launcher2/Patcher/ZipWriter.cs | 2 +- Launcher2/Updater/Applier.cs | 2 +- 32 files changed, 92 insertions(+), 178 deletions(-) delete mode 100644 ClassicalSharp/Commands/CommandReader.cs rename ClassicalSharp/TexturePack/{TexturePackExtractor.cs => TexturePack.cs} (80%) diff --git a/ClassicalSharp/2D/IsometricBlockDrawer.cs b/ClassicalSharp/2D/IsometricBlockDrawer.cs index 49e5bda1d..2db21c1ef 100644 --- a/ClassicalSharp/2D/IsometricBlockDrawer.cs +++ b/ClassicalSharp/2D/IsometricBlockDrawer.cs @@ -2,7 +2,7 @@ using System; using ClassicalSharp.GraphicsAPI; using ClassicalSharp.Model; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; namespace ClassicalSharp { diff --git a/ClassicalSharp/2D/Screens/LoadingMapScreen.cs b/ClassicalSharp/2D/Screens/LoadingMapScreen.cs index d93fec4f8..3b8fc51ca 100644 --- a/ClassicalSharp/2D/Screens/LoadingMapScreen.cs +++ b/ClassicalSharp/2D/Screens/LoadingMapScreen.cs @@ -5,7 +5,7 @@ using ClassicalSharp.Events; using ClassicalSharp.GraphicsAPI; using ClassicalSharp.Gui.Widgets; using ClassicalSharp.Model; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK.Input; namespace ClassicalSharp.Gui.Screens { diff --git a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs index 0cbacfbe2..154b26050 100644 --- a/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/LoadLevelScreen.cs @@ -4,7 +4,7 @@ using System.IO; using ClassicalSharp.Entities; using ClassicalSharp.Map; using ClassicalSharp.Gui.Widgets; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK.Input; namespace ClassicalSharp.Gui.Screens { @@ -61,7 +61,7 @@ namespace ClassicalSharp.Gui.Screens { int width, height, length; game.World.Reset(); if( game.World.TextureUrl != null ) { - TexturePackExtractor.ExtractDefault( game ); + TexturePack.ExtractDefault( game ); game.World.TextureUrl = null; } game.BlockInfo.Reset( game ); diff --git a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs index 489d7fe23..b31107d24 100644 --- a/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/TexturePackScreen.cs @@ -2,7 +2,7 @@ using System; using System.IO; using ClassicalSharp.Gui.Widgets; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK.Input; namespace ClassicalSharp.Gui.Screens { @@ -10,7 +10,7 @@ namespace ClassicalSharp.Gui.Screens { public TexturePackScreen( Game game ) : base( game ) { 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" ); 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 ) { if( mouseBtn != MouseButton.Left ) return; 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 ); if( !File.Exists( path ) ) return; int index = currentIndex; game.DefaultTexturePack = file; - game.World.TextureUrl = null; - TexturePackExtractor extractor = new TexturePackExtractor(); - extractor.Extract( path, game ); + TexturePack.ExtractDefault( game ); Recreate(); SetCurrentIndex( index ); } diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 18988cb82..8202f64f8 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -253,7 +253,6 @@ - @@ -295,7 +294,7 @@ - + diff --git a/ClassicalSharp/Commands/Command.cs b/ClassicalSharp/Commands/Command.cs index c1272fc59..9395a7281 100644 --- a/ClassicalSharp/Commands/Command.cs +++ b/ClassicalSharp/Commands/Command.cs @@ -16,6 +16,6 @@ namespace ClassicalSharp.Commands { protected internal Game game; - public abstract void Execute( CommandReader reader ); + public abstract void Execute( string[] args ); } } diff --git a/ClassicalSharp/Commands/CommandList.cs b/ClassicalSharp/Commands/CommandList.cs index 63df43a38..db93f6bf5 100644 --- a/ClassicalSharp/Commands/CommandList.cs +++ b/ClassicalSharp/Commands/CommandList.cs @@ -11,7 +11,7 @@ namespace ClassicalSharp.Commands { if( game.Server.IsSinglePlayer && Utils.CaselessStarts( input, "/" ) ) return true; - return Utils.CaselessStarts( input, prefix + " " ) + return Utils.CaselessStarts( input, prefix + " " ) || Utils.CaselessEquals( input, prefix ); } @@ -22,7 +22,6 @@ namespace ClassicalSharp.Commands { Register( new CommandsCommand() ); Register( new GpuInfoCommand() ); Register( new HelpCommand() ); - Register( new InfoCommand() ); Register( new RenderTypeCommand() ); if( !game.Server.IsSinglePlayer ) return; @@ -63,23 +62,25 @@ namespace ClassicalSharp.Commands { return match; } + static char[] splitChar = { ' ' }; public void Execute( string text ) { - if( Utils.CaselessStarts( text, prefix ) ) { - text = text.Substring( prefix.Length ).TrimStart( ' ' ); - text = "/" + text; - } + if( Utils.CaselessStarts( text, prefix ) ) { // /client command args + text = text.Substring( prefix.Length ).TrimStart( splitChar ); + } else { // /command args + text = text.Substring( 1 ); + } - CommandReader reader = new CommandReader( text ); - string cmdName = reader.Next(); - if( cmdName == null ) { + if( text.Length == 1 ) { // only / or /client game.Chat.Add( "&eList of client commands:" ); PrintDefinedCommands( game ); game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" ); return; - } - - Command cmd = GetMatch( cmdName ); - if( cmd != null ) cmd.Execute( reader ); + } + + string[] args = text.Split( splitChar ); + Command cmd = GetMatch( args[0] ); + if( cmd == null ) return; + cmd.Execute( args ); } public void PrintDefinedCommands( Game game ) { diff --git a/ClassicalSharp/Commands/CommandReader.cs b/ClassicalSharp/Commands/CommandReader.cs deleted file mode 100644 index a058ef3a6..000000000 --- a/ClassicalSharp/Commands/CommandReader.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT -using System; - -namespace ClassicalSharp.Commands { - - /// Reads and parses arguments for a client command. - /// Spaces are designated as the argument separators. - public class CommandReader { - - string rawInput; - int curOffset; - - /// Returns the next argument, or null if there are no more arguments left. - 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; - } - - /// Returns all remaining arguments (including the space separators), - /// or null if there are no more arguments left. - 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 - } - } -} diff --git a/ClassicalSharp/Commands/DefaultCommands.cs b/ClassicalSharp/Commands/DefaultCommands.cs index 2db96625e..958d09f29 100644 --- a/ClassicalSharp/Commands/DefaultCommands.cs +++ b/ClassicalSharp/Commands/DefaultCommands.cs @@ -18,7 +18,7 @@ namespace ClassicalSharp.Commands { }; } - public override void Execute( CommandReader reader ) { + public override void Execute( string[] args ) { game.CommandList.PrintDefinedCommands( game ); } } @@ -34,14 +34,13 @@ namespace ClassicalSharp.Commands { }; } - public override void Execute( CommandReader reader ) { - string cmdName = reader.Next(); - if( cmdName == null ) { + public override void Execute( string[] args ) { + if( args.Length == 1 ) { game.Chat.Add( "&eList of client commands:" ); game.CommandList.PrintDefinedCommands( game ); game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" ); } else { - Command cmd = game.CommandList.GetMatch( cmdName ); + Command cmd = game.CommandList.GetMatch( args[1] ); if( cmd == null ) return; string[] help = cmd.Help; 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; for( int i = 0; i < lines.Length; 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 RenderTypeCommand() { @@ -118,14 +80,13 @@ namespace ClassicalSharp.Commands { }; } - public override void Execute( CommandReader reader ) { - string property = reader.Next(); - if( property == null ) { + public override void Execute( string[] args ) { + if( args.Length == 1 ) { game.Chat.Add( "&e/client: &cYou didn't specify a new render type." ); - } else if( game.SetRenderType( property ) ) { - game.Chat.Add( "&e/client: &fRender type is now " + property + "." ); + } else if( game.SetRenderType( args[1] ) ) { + game.Chat.Add( "&e/client: &fRender type is now " + args[1] + "." ); } else { - game.Chat.Add( "&e/client: &cUnrecognised render type &f\"" + property + "\"&c." ); + game.Chat.Add( "&e/client: &cUnrecognised render type &f\"" + args[1] + "\"&c." ); } } } diff --git a/ClassicalSharp/Commands/SinglePlayerCommands.cs b/ClassicalSharp/Commands/SinglePlayerCommands.cs index 9f67b3079..546821b64 100644 --- a/ClassicalSharp/Commands/SinglePlayerCommands.cs +++ b/ClassicalSharp/Commands/SinglePlayerCommands.cs @@ -19,12 +19,11 @@ namespace ClassicalSharp.Commands { }; } - public override void Execute( CommandReader reader ) { - string name = reader.Next(); - if( String.IsNullOrEmpty( name ) ) { + public override void Execute( string[] args ) { + if( args.Length == 1 ) { game.Chat.Add( "&e/client model: &cYou didn't specify a model name." ); } else { - game.LocalPlayer.SetModel( Utils.ToLower( name ) ); + game.LocalPlayer.SetModel( Utils.ToLower( args[1] ) ); } } } @@ -45,33 +44,31 @@ namespace ClassicalSharp.Commands { Vector3I mark1, mark2; bool persist = false; - public override void Execute( CommandReader reader ) { + public override void Execute( string[] args ) { game.UserEvents.BlockChanged -= BlockChanged; block = 0xFF; mark1 = new Vector3I( int.MaxValue ); mark2 = new Vector3I( int.MaxValue ); persist = false; - if( !ParseBlock( reader ) ) return; - string arg = reader.Next(); - if( arg != null && Utils.CaselessEquals( arg, "yes" ) ) + if( !ParseBlock( args ) ) return; + if( args.Length > 2 && Utils.CaselessEquals( args[2], "yes" ) ) persist = true; game.Chat.Add( "&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3 ); game.UserEvents.BlockChanged += BlockChanged; } - bool ParseBlock( CommandReader reader ) { - string id = reader.Next(); - if( id == null ) return true; - if( Utils.CaselessEquals( id, "yes" ) ) { persist = true; return true; } + bool ParseBlock( string[] args ) { + if( args.Length == 1 ) return true; + if( Utils.CaselessEquals( args[1], "yes" ) ) { persist = true; return true; } byte blockID = 0; - if( !byte.TryParse( id, out blockID ) ) { - game.Chat.Add( "&eCuboid: &c\"" + id + "\" is not a valid block id." ); return false; + if( !byte.TryParse( args[1], out blockID ) ) { + game.Chat.Add( "&eCuboid: &c\"" + args[1] + "\" is not a valid block id." ); return false; } 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; return true; diff --git a/ClassicalSharp/Entities/Model/BlockModel.cs b/ClassicalSharp/Entities/Model/BlockModel.cs index fc86b2cb2..691e64db2 100644 --- a/ClassicalSharp/Entities/Model/BlockModel.cs +++ b/ClassicalSharp/Entities/Model/BlockModel.cs @@ -4,7 +4,7 @@ using ClassicalSharp.Entities; using ClassicalSharp.GraphicsAPI; using ClassicalSharp.Physics; using ClassicalSharp.Renderers; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; namespace ClassicalSharp.Model { diff --git a/ClassicalSharp/Game/Game.Init.cs b/ClassicalSharp/Game/Game.Init.cs index 45e06aa24..d2f3533f9 100644 --- a/ClassicalSharp/Game/Game.Init.cs +++ b/ClassicalSharp/Game/Game.Init.cs @@ -13,7 +13,7 @@ using ClassicalSharp.Network; using ClassicalSharp.Particles; using ClassicalSharp.Renderers; using ClassicalSharp.Selections; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; #if ANDROID using Android.Graphics; #endif @@ -134,7 +134,7 @@ namespace ClassicalSharp { void ExtractInitialTexturePack() { defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip"; - TexturePackExtractor extractor = new TexturePackExtractor(); + TexturePack extractor = new TexturePack(); extractor.Extract( "default.zip", this ); // in case the user's default texture pack doesn't have all required textures if( DefaultTexturePack != "default.zip" ) diff --git a/ClassicalSharp/Game/Game.Properties.cs b/ClassicalSharp/Game/Game.Properties.cs index 914244e3e..fa673665f 100644 --- a/ClassicalSharp/Game/Game.Properties.cs +++ b/ClassicalSharp/Game/Game.Properties.cs @@ -16,7 +16,7 @@ using ClassicalSharp.Network; using ClassicalSharp.Particles; using ClassicalSharp.Renderers; using ClassicalSharp.Selections; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; using OpenTK.Input; @@ -222,7 +222,7 @@ namespace ClassicalSharp { /// this method returns "default.zip". public string DefaultTexturePack { get { - string path = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); + string path = Path.Combine( Program.AppDirectory, TexturePack.Dir ); path = Path.Combine( path, defTexturePack ); return File.Exists( path ) && !ClassicMode ? defTexturePack : "default.zip"; } diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 691e56079..2d2708338 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -17,7 +17,7 @@ using ClassicalSharp.Network; using ClassicalSharp.Particles; using ClassicalSharp.Renderers; using ClassicalSharp.Selections; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; using OpenTK.Input; #if ANDROID @@ -258,7 +258,7 @@ namespace ClassicalSharp { Drawer2D.InitColours(); BlockInfo.Reset( this ); - TexturePackExtractor.ExtractDefault( this ); + TexturePack.ExtractDefault( this ); Gui.SetNewScreen( new ErrorScreen( this, title, reason ) ); GC.Collect(); } diff --git a/ClassicalSharp/MeshBuilder/TileDrawer.cs b/ClassicalSharp/MeshBuilder/TileDrawer.cs index 98030b516..fc308dcac 100644 --- a/ClassicalSharp/MeshBuilder/TileDrawer.cs +++ b/ClassicalSharp/MeshBuilder/TileDrawer.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using ClassicalSharp.GraphicsAPI; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; namespace ClassicalSharp { diff --git a/ClassicalSharp/Network/IServerConnection.cs b/ClassicalSharp/Network/IServerConnection.cs index a045f2a53..ba7c50552 100644 --- a/ClassicalSharp/Network/IServerConnection.cs +++ b/ClassicalSharp/Network/IServerConnection.cs @@ -5,7 +5,7 @@ using System.IO; using System.Net; using ClassicalSharp.Gui.Screens; using ClassicalSharp.Network; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; using OpenTK.Input; #if ANDROID @@ -117,10 +117,10 @@ namespace ClassicalSharp { protected void CheckAsyncResources() { DownloadedItem 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 ) ) { - TexturePackExtractor.ExtractTexturePack( game, item ); + TexturePack.ExtractTexturePack( game, item.Url, item ); } } #endregion diff --git a/ClassicalSharp/Network/NetworkProcessor.cs b/ClassicalSharp/Network/NetworkProcessor.cs index 8f6569d88..08727d67e 100644 --- a/ClassicalSharp/Network/NetworkProcessor.cs +++ b/ClassicalSharp/Network/NetworkProcessor.cs @@ -8,7 +8,7 @@ using ClassicalSharp.Entities; using ClassicalSharp.Events; using ClassicalSharp.Gui; using ClassicalSharp.Network; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using ClassicalSharp.Network.Protocols; namespace ClassicalSharp.Network { diff --git a/ClassicalSharp/Network/Protocols/CPE.cs b/ClassicalSharp/Network/Protocols/CPE.cs index fda299f45..c243a0bf7 100644 --- a/ClassicalSharp/Network/Protocols/CPE.cs +++ b/ClassicalSharp/Network/Protocols/CPE.cs @@ -3,7 +3,7 @@ using System; using ClassicalSharp.Entities; using ClassicalSharp.Hotkeys; using ClassicalSharp.Map; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK.Input; namespace ClassicalSharp.Network.Protocols { @@ -312,7 +312,7 @@ namespace ClassicalSharp.Network.Protocols { if( !game.AllowServerTextures ) return; if( url == "" ) { - TexturePackExtractor.ExtractDefault( game ); + TexturePack.ExtractDefault( game ); } else if( Utils.IsUrlPrefix( url, 0 ) ) { net.RetrieveTexturePack( url ); } diff --git a/ClassicalSharp/Program.cs b/ClassicalSharp/Program.cs index 39c90c1b1..29db89bda 100644 --- a/ClassicalSharp/Program.cs +++ b/ClassicalSharp/Program.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Net; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using OpenTK; namespace ClassicalSharp { @@ -21,7 +21,7 @@ namespace ClassicalSharp { CleanupMainDirectory(); 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" ) ) ) { Utils.LogDebug( "default.zip not found. Cannot start." ); return; @@ -85,7 +85,7 @@ namespace ClassicalSharp { string mapPath = Path.Combine( Program.AppDirectory, "maps" ); if( !Directory.Exists( mapPath ) ) Directory.CreateDirectory( mapPath ); - string texPath = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); + string texPath = Path.Combine( Program.AppDirectory, TexturePack.Dir ); if( !Directory.Exists( texPath ) ) Directory.CreateDirectory( texPath ); diff --git a/ClassicalSharp/TexturePack/Animations.cs b/ClassicalSharp/TexturePack/Animations.cs index e408ef636..3cc682294 100644 --- a/ClassicalSharp/TexturePack/Animations.cs +++ b/ClassicalSharp/TexturePack/Animations.cs @@ -9,7 +9,7 @@ using ClassicalSharp.GraphicsAPI; using Android.Graphics; #endif -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { /// Contains and describes the various animations applied to the terrain atlas. public class Animations : IGameComponent { diff --git a/ClassicalSharp/TexturePack/EntryList.cs b/ClassicalSharp/TexturePack/EntryList.cs index 9f64bfca8..1961f5aa0 100644 --- a/ClassicalSharp/TexturePack/EntryList.cs +++ b/ClassicalSharp/TexturePack/EntryList.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; using System.IO; -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { public sealed class EntryList { - public List Entries = new List(); + public List Entries = new List(); const string folder = "texturecache"; string file; diff --git a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs index 24c4f0caa..bb583c667 100644 --- a/ClassicalSharp/TexturePack/TerrainAtlas1D.cs +++ b/ClassicalSharp/TexturePack/TerrainAtlas1D.cs @@ -6,7 +6,7 @@ using ClassicalSharp.GraphicsAPI; using Android.Graphics; #endif -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { /// Represents a 2D packed texture atlas that has been converted into an array of 1D atlases. public sealed class TerrainAtlas1D : IDisposable { diff --git a/ClassicalSharp/TexturePack/TextureCache.cs b/ClassicalSharp/TexturePack/TextureCache.cs index e9931388c..240f62067 100644 --- a/ClassicalSharp/TexturePack/TextureCache.cs +++ b/ClassicalSharp/TexturePack/TextureCache.cs @@ -8,7 +8,7 @@ using Android.Graphics; #endif using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { /// Caches terrain atlases and texture packs to avoid making redundant downloads. public static class TextureCache { diff --git a/ClassicalSharp/TexturePack/TexturePackExtractor.cs b/ClassicalSharp/TexturePack/TexturePack.cs similarity index 80% rename from ClassicalSharp/TexturePack/TexturePackExtractor.cs rename to ClassicalSharp/TexturePack/TexturePack.cs index 9923a35c1..6445e68e1 100644 --- a/ClassicalSharp/TexturePack/TexturePackExtractor.cs +++ b/ClassicalSharp/TexturePack/TexturePack.cs @@ -10,10 +10,10 @@ using Android.Graphics; #endif using PathIO = System.IO.Path; // Android.Graphics.Path clash otherwise -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { /// Extracts resources from a .zip texture pack. - public sealed class TexturePackExtractor { + public sealed class TexturePack { public const string Dir = "texpacks"; Game game; @@ -45,8 +45,8 @@ namespace ClassicalSharp.TexturePack { } - internal static void ExtractTerrainPng( Game game, DownloadedItem item ) { - if( item.Data != null ) { + internal static void ExtractTerrainPng( Game game, string url, DownloadedItem item ) { + if( item != null && item.Data != null ) { Bitmap bmp = (Bitmap)item.Data; game.World.TextureUrl = item.Url; game.Events.RaiseTexturePackChanged(); @@ -61,14 +61,14 @@ namespace ClassicalSharp.TexturePack { TextureCache.AddETag( item.Url, item.ETag, game.ETags ); TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified ); } else { - FileStream data = TextureCache.GetStream( item.Url ); + FileStream data = TextureCache.GetStream( url ); if( data == null ) { // e.g. 404 errors ExtractDefault( game ); - } else if( item.Url != game.World.TextureUrl ) { + } else if( url != game.World.TextureUrl ) { Bitmap bmp = GetBitmap( data ); if( bmp == null ) { data.Dispose(); return; } - game.World.TextureUrl = item.Url; + game.World.TextureUrl = url; game.Events.RaiseTexturePackChanged(); if( game.ChangeTerrainAtlas( bmp, data ) ) return; @@ -80,11 +80,11 @@ namespace ClassicalSharp.TexturePack { } } - internal static void ExtractTexturePack( Game game, DownloadedItem item ) { - if( item.Data != null ) { + internal static void ExtractTexturePack( Game game, string url, DownloadedItem item ) { + if( item != null && item.Data != null ) { game.World.TextureUrl = item.Url; byte[] data = (byte[])item.Data; - TexturePackExtractor extractor = new TexturePackExtractor(); + TexturePack extractor = new TexturePack(); using( Stream ms = new MemoryStream( data ) ) { extractor.Extract( ms, game ); } @@ -93,12 +93,12 @@ namespace ClassicalSharp.TexturePack { TextureCache.AddETag( item.Url, item.ETag, game.ETags ); TextureCache.AdddLastModified( item.Url, item.LastModified, game.LastModified ); } else { - FileStream data = TextureCache.GetStream( item.Url ); + FileStream data = TextureCache.GetStream( url ); if( data == null ) { // e.g. 404 errors ExtractDefault( game ); - } else if( item.Url != game.World.TextureUrl ) { - game.World.TextureUrl = item.Url; - TexturePackExtractor extractor = new TexturePackExtractor(); + } else if( url != game.World.TextureUrl ) { + game.World.TextureUrl = url; + TexturePack extractor = new TexturePack(); extractor.Extract( data, game ); } } @@ -106,7 +106,7 @@ namespace ClassicalSharp.TexturePack { internal static void ExtractDefault( Game game ) { - TexturePackExtractor extractor = new TexturePackExtractor(); + TexturePack extractor = new TexturePack(); extractor.Extract( game.DefaultTexturePack, game ); game.World.TextureUrl = null; } diff --git a/ClassicalSharp/TexturePack/ZipReader.cs b/ClassicalSharp/TexturePack/ZipReader.cs index d735faec1..505133556 100644 --- a/ClassicalSharp/TexturePack/ZipReader.cs +++ b/ClassicalSharp/TexturePack/ZipReader.cs @@ -4,7 +4,7 @@ using System.IO; using System.IO.Compression; using System.Text; -namespace ClassicalSharp.TexturePack { +namespace ClassicalSharp.Textures { public struct ZipEntry { public int CompressedDataSize, UncompressedDataSize; diff --git a/ClassicalSharp/Utils/Options.cs b/ClassicalSharp/Utils/Options.cs index 500da7996..5425127f8 100644 --- a/ClassicalSharp/Utils/Options.cs +++ b/ClassicalSharp/Utils/Options.cs @@ -2,9 +2,7 @@ using System; using System.Collections.Generic; using System.IO; -using ClassicalSharp.TexturePack; -using OpenTK; -using OpenTK.Input; +using ClassicalSharp.Textures; namespace ClassicalSharp { @@ -149,7 +147,7 @@ namespace ClassicalSharp { if( Program.AppDirectory == null ) Program.AppDirectory = AppDomain.CurrentDomain.BaseDirectory; 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 ) ) Program.CleanupMainDirectory(); diff --git a/Launcher2/LauncherWindow.Background.cs b/Launcher2/LauncherWindow.Background.cs index abfaebbb6..94e615d9a 100644 --- a/Launcher2/LauncherWindow.Background.cs +++ b/Launcher2/LauncherWindow.Background.cs @@ -3,7 +3,7 @@ using System; using System.Drawing; using System.IO; using ClassicalSharp; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using Launcher.Drawing; namespace Launcher { diff --git a/Launcher2/Patcher/BinUnpacker.cs b/Launcher2/Patcher/BinUnpacker.cs index 8891b24d7..ec8435657 100644 --- a/Launcher2/Patcher/BinUnpacker.cs +++ b/Launcher2/Patcher/BinUnpacker.cs @@ -4,7 +4,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; using ClassicalSharp; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; namespace Launcher.Patcher { diff --git a/Launcher2/Patcher/ResourceChecker.cs b/Launcher2/Patcher/ResourceChecker.cs index f4afca07b..aa18ba974 100644 --- a/Launcher2/Patcher/ResourceChecker.cs +++ b/Launcher2/Patcher/ResourceChecker.cs @@ -1,7 +1,7 @@ // ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT using System; using System.IO; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; namespace Launcher.Patcher { diff --git a/Launcher2/Patcher/ResourcePatcher.cs b/Launcher2/Patcher/ResourcePatcher.cs index 768f3522d..f8dc31d1d 100644 --- a/Launcher2/Patcher/ResourcePatcher.cs +++ b/Launcher2/Patcher/ResourcePatcher.cs @@ -5,7 +5,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; using ClassicalSharp; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; namespace Launcher.Patcher { diff --git a/Launcher2/Patcher/ZipWriter.cs b/Launcher2/Patcher/ZipWriter.cs index c825619cd..814edf914 100644 --- a/Launcher2/Patcher/ZipWriter.cs +++ b/Launcher2/Patcher/ZipWriter.cs @@ -4,7 +4,7 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Text; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; namespace Launcher.Patcher { diff --git a/Launcher2/Updater/Applier.cs b/Launcher2/Updater/Applier.cs index bd5bb554c..ebb8c6a00 100644 --- a/Launcher2/Updater/Applier.cs +++ b/Launcher2/Updater/Applier.cs @@ -6,7 +6,7 @@ using System.Net; using System.Runtime.InteropServices; using System.Threading; using ClassicalSharp; -using ClassicalSharp.TexturePack; +using ClassicalSharp.Textures; using Launcher.Web; namespace Launcher.Updater {