mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 04:34:58 -04:00
Style: Remove CommandReader class, move stuff from ClassicalSharp.TexturePack to ClassicalSharp.Textures
This commit is contained in:
parent
d24a929267
commit
f0047be63c
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Model;
|
||||
using ClassicalSharp.TexturePack;
|
||||
using ClassicalSharp.Textures;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
@ -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 {
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -253,7 +253,6 @@
|
||||
<Compile Include="Network\Utils\FixedBufferStream.cs" />
|
||||
<Compile Include="Network\Utils\GZipHeaderReader.cs" />
|
||||
<Compile Include="Commands\CommandList.cs" />
|
||||
<Compile Include="Commands\CommandReader.cs" />
|
||||
<Compile Include="Network\Utils\NetWriter.cs" />
|
||||
<Compile Include="Math\PickedPos.cs" />
|
||||
<Compile Include="Math\Picking.cs" />
|
||||
@ -295,7 +294,7 @@
|
||||
<Compile Include="TexturePack\TextureCache.cs" />
|
||||
<Compile Include="TexturePack\TerrainAtlas1D.cs" />
|
||||
<Compile Include="TexturePack\TerrainAtlas2D.cs" />
|
||||
<Compile Include="TexturePack\TexturePackExtractor.cs" />
|
||||
<Compile Include="TexturePack\TexturePack.cs" />
|
||||
<Compile Include="TexturePack\ZipReader.cs" />
|
||||
<Compile Include="Utils\Camera.cs" />
|
||||
<Compile Include="Utils\ErrorHandler.cs" />
|
||||
|
@ -16,6 +16,6 @@ namespace ClassicalSharp.Commands {
|
||||
|
||||
protected internal Game game;
|
||||
|
||||
public abstract void Execute( CommandReader reader );
|
||||
public abstract void Execute( string[] args );
|
||||
}
|
||||
}
|
||||
|
@ -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 ) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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" )
|
||||
|
@ -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". </remarks>
|
||||
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";
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.TexturePack;
|
||||
using ClassicalSharp.Textures;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -9,7 +9,7 @@ using ClassicalSharp.GraphicsAPI;
|
||||
using Android.Graphics;
|
||||
#endif
|
||||
|
||||
namespace ClassicalSharp.TexturePack {
|
||||
namespace ClassicalSharp.Textures {
|
||||
|
||||
/// <summary> Contains and describes the various animations applied to the terrain atlas. </summary>
|
||||
public class Animations : IGameComponent {
|
||||
|
@ -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<string> Entries = new List<string>();
|
||||
public List<string> Entries = new List<string>();
|
||||
const string folder = "texturecache";
|
||||
string file;
|
||||
|
||||
|
@ -6,7 +6,7 @@ using ClassicalSharp.GraphicsAPI;
|
||||
using Android.Graphics;
|
||||
#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>
|
||||
public sealed class TerrainAtlas1D : IDisposable {
|
||||
|
@ -8,7 +8,7 @@ using Android.Graphics;
|
||||
#endif
|
||||
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>
|
||||
public static class TextureCache {
|
||||
|
@ -10,10 +10,10 @@ using Android.Graphics;
|
||||
#endif
|
||||
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>
|
||||
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;
|
||||
}
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user