mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Allow dropping map files onto the .exe to start the game in singleplayer on that map, fixes #522.
also fix texture pack being downloaded twice in singleplayer
This commit is contained in:
parent
9453c70e5d
commit
b3e67ca2ff
@ -37,10 +37,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
protected override void TextButtonClick(Game game, Widget widget) {
|
||||
string path = Path.Combine("maps", GetCur(widget));
|
||||
if (!Platform.FileExists(path)) return;
|
||||
LoadMap(path);
|
||||
LoadMap(game, path);
|
||||
}
|
||||
|
||||
void LoadMap(string path) {
|
||||
internal static void LoadMap(Game game, string path) {
|
||||
game.World.Reset();
|
||||
game.WorldEvents.RaiseOnNewMap();
|
||||
|
||||
@ -66,7 +66,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
} else if (path.EndsWith(".lvl")) {
|
||||
importer = new MapLvlImporter();
|
||||
}
|
||||
|
||||
blocks = importer.Load(fs, game, out width, out height, out length);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -77,9 +76,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
game.World.SetNewMap(blocks, width, height, length);
|
||||
game.WorldEvents.RaiseOnNewMapLoaded();
|
||||
if (game.AllowServerTextures && game.World.TextureUrl != null) {
|
||||
game.Server.RetrieveTexturePack(game.World.TextureUrl);
|
||||
}
|
||||
|
||||
LocalPlayer p = game.LocalPlayer;
|
||||
LocationUpdate update = LocationUpdate.MakePosAndOri(p.Spawn, p.SpawnRotY, p.SpawnHeadX, false);
|
||||
|
@ -81,8 +81,10 @@ namespace ClassicalSharp.Map {
|
||||
if (curCpeExt.ContainsKey("TextureURL"))
|
||||
url = (string)curCpeExt["TextureURL"].Value;
|
||||
if (url.Length == 0) url = null;
|
||||
if (game.AllowServerTextures && url != null)
|
||||
|
||||
if (game.AllowServerTextures && url != null) {
|
||||
game.Server.RetrieveTexturePack(url);
|
||||
}
|
||||
|
||||
byte sidesBlock = (byte)curCpeExt["SideBlock"].Value;
|
||||
byte edgeBlock = (byte)curCpeExt["EdgeBlock"].Value;
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
//#define TEST_VANILLA
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using ClassicalSharp.Entities;
|
||||
using ClassicalSharp.Generator;
|
||||
@ -30,9 +31,17 @@ namespace ClassicalSharp.Singleplayer {
|
||||
for (int i = 1; i <= max; i++) {
|
||||
BlockInfo.CanPlace[i] = true;
|
||||
BlockInfo.CanDelete[i] = true;
|
||||
}
|
||||
}
|
||||
game.Events.RaiseBlockPermissionsChanged();
|
||||
|
||||
// For when user drops a map file onto ClassicalSharp.exe
|
||||
string path = game.Username;
|
||||
if (path.IndexOf(Path.DirectorySeparatorChar) >= 0 && File.Exists(path)) {
|
||||
LoadLevelScreen.LoadMap(game, path);
|
||||
game.Gui.SetNewScreen(null);
|
||||
return;
|
||||
}
|
||||
|
||||
NotchyGenerator gen = new NotchyGenerator();
|
||||
gen.Width = 128; gen.Height = 64; gen.Length = 128;
|
||||
gen.Seed = new Random().Next();
|
||||
@ -81,7 +90,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
physics.Tick();
|
||||
CheckAsyncResources();
|
||||
}
|
||||
netTicks++;
|
||||
netTicks++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1585,7 +1585,7 @@ static void LoadLevelScreen_SelectEntry(STRING_PURE String* filename, void* obj)
|
||||
StringsBuffer_Add(entries, filename);
|
||||
}
|
||||
|
||||
static void LoadLevelScreen_LoadMap(STRING_PURE String* path) {
|
||||
void LoadLevelScreen_LoadMap(STRING_PURE String* path) {
|
||||
World_Reset();
|
||||
Event_RaiseVoid(&WorldEvents_NewMap);
|
||||
|
||||
@ -1619,9 +1619,6 @@ static void LoadLevelScreen_LoadMap(STRING_PURE String* path) {
|
||||
|
||||
World_SetNewMap(World_Blocks, World_BlocksSize, World_Width, World_Height, World_Length);
|
||||
Event_RaiseVoid(&WorldEvents_MapLoaded);
|
||||
if (Game_AllowServerTextures && World_TextureUrl.length > 0) {
|
||||
ServerConnection_RetrieveTexturePack(&World_TextureUrl);
|
||||
}
|
||||
|
||||
LocalPlayer* p = &LocalPlayer_Instance;
|
||||
LocationUpdate update; LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnRotY, p->SpawnHeadX, false);
|
||||
|
@ -19,6 +19,7 @@ Screen* MouseKeyBindingsScreen_MakeInstance(void);
|
||||
|
||||
Screen* GenLevelScreen_MakeInstance(void);
|
||||
Screen* ClassicGenScreen_MakeInstance(void);
|
||||
void LoadLevelScreen_LoadMap(STRING_PURE String* path);
|
||||
Screen* LoadLevelScreen_MakeInstance(void);
|
||||
Screen* SaveLevelScreen_MakeInstance(void);
|
||||
Screen* TexturePackScreen_MakeInstance(void);
|
||||
|
@ -178,6 +178,14 @@ static void SPConnection_BeginConnect(void) {
|
||||
}
|
||||
Event_RaiseVoid(&BlockEvents_PermissionsChanged);
|
||||
|
||||
/* For when user drops a map file onto ClassicalSharp.exe */
|
||||
String path = Game_Username;
|
||||
if (String_IndexOf(&path, Platform_DirectorySeparator, 0) >= 0 && Platform_FileExists(&path)) {
|
||||
LoadLevelScreen_LoadMap(&path);
|
||||
Gui_ReplaceActive(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
Random rnd; Random_InitFromCurrentTime(&rnd);
|
||||
Get_SetDimensions(128, 64, 128); Gen_Vanilla = true;
|
||||
Gen_Seed = Random_Next(&rnd, Int32_MaxValue);
|
||||
|
Loading…
x
Reference in New Issue
Block a user