mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Completely remove LvlProperties class and replace with LevelConfig
This commit is contained in:
parent
aa26c3b9b1
commit
78ddd724cc
@ -1,79 +0,0 @@
|
||||
/*
|
||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy.Levels.IO {
|
||||
public static class LvlProperties {
|
||||
|
||||
public static void Save(Level level, string path) {
|
||||
try {
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
WriteLevelProperties(level, writer);
|
||||
} catch (Exception ex) {
|
||||
Logger.Log(LogType.Warning, "Failed to save level properties!");
|
||||
Logger.LogError(ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteLevelProperties(Level level, StreamWriter w) {
|
||||
w.WriteLine("#Level properties for " + level.name);
|
||||
w.WriteLine("#Drown-time in seconds is [drown time] * 200 / 3 / 1000");
|
||||
w.WriteLine("Physics = " + level.physics);
|
||||
ConfigElement.Serialise(Server.levelConfig, " settings", w, level.Config);
|
||||
}
|
||||
|
||||
|
||||
public static void Load(Level level, string path) {
|
||||
PropertiesFile.Read(path, ref level, PropLineProcessor);
|
||||
}
|
||||
|
||||
public static void LoadEnv(Level level) {
|
||||
string path = "levels/level properties/" + level.MapName + ".env";
|
||||
PropertiesFile.Read(path, ref level, EnvLineProcessor);
|
||||
}
|
||||
|
||||
static void EnvLineProcessor(string key, string value, ref Level level) {
|
||||
switch (key.ToLower()) {
|
||||
case "cloudcolor": level.Config.CloudColor = value; break;
|
||||
case "fogcolor": level.Config.FogColor = value; break;
|
||||
case "skycolor": level.Config.SkyColor = value; break;
|
||||
case "shadowcolor": level.Config.ShadowColor = value; break;
|
||||
case "lightcolor": level.Config.LightColor = value; break;
|
||||
case "edgeblock": level.Config.EdgeBlock = byte.Parse(value); break;
|
||||
case "edgelevel": level.Config.EdgeLevel = short.Parse(value); break;
|
||||
case "cloudsheight": level.Config.CloudsHeight = short.Parse(value); break;
|
||||
case "maxfog": level.Config.MaxFogDistance = short.Parse(value); break;
|
||||
case "horizonblock": level.Config.HorizonBlock = byte.Parse(value); break;
|
||||
}
|
||||
}
|
||||
|
||||
static void PropLineProcessor(string key, string value, ref Level level) {
|
||||
switch (key.ToLower()) {
|
||||
case "physics":
|
||||
level.setPhysics(int.Parse(value)); break;
|
||||
default:
|
||||
if (!ConfigElement.Parse(Server.levelConfig, key, value, level.Config)) {
|
||||
Logger.Log(LogType.Warning, "\"{0}\" was not a recognised level property key.", key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -223,8 +223,10 @@ namespace MCGalaxy {
|
||||
public static void SaveSettings(Level lvl) {
|
||||
if (lvl.IsMuseum) return; // museums do not save properties
|
||||
|
||||
lock (lvl.savePropsLock)
|
||||
LvlProperties.Save(lvl, LevelInfo.PropertiesPath(lvl.MapName));
|
||||
lock (lvl.savePropsLock) {
|
||||
string path = LevelInfo.PropertiesPath(lvl.MapName);
|
||||
LevelConfig.Save(path, lvl.Config, lvl.name);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if ListCheck does not already have an check in the position.
|
||||
@ -373,13 +375,15 @@ namespace MCGalaxy {
|
||||
try {
|
||||
string propsPath = LevelInfo.FindPropertiesFile(lvl.MapName);
|
||||
if (propsPath != null) {
|
||||
LvlProperties.Load(lvl, propsPath);
|
||||
LevelConfig.Load(propsPath, lvl.Config);
|
||||
lvl.setPhysics(lvl.Config.Physics);
|
||||
} else {
|
||||
Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName);
|
||||
}
|
||||
|
||||
// Backwards compatibility for older levels which had .env files.
|
||||
LvlProperties.LoadEnv(lvl);
|
||||
string envPath = "levels/level properties/" + lvl.MapName + ".env";
|
||||
LevelConfig.Load(envPath, lvl.Config);
|
||||
} catch (Exception e) {
|
||||
Logger.LogError(e);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MCGalaxy.Config;
|
||||
using MCGalaxy.Games;
|
||||
|
||||
@ -131,6 +132,8 @@ namespace MCGalaxy {
|
||||
public List<string> BuildBlacklist = new List<string>();
|
||||
|
||||
// Physics settings
|
||||
[ConfigInt("Physics", "Physics", null, 0, 0, 5)]
|
||||
public int Physics;
|
||||
[ConfigInt("Physics overload", "Physics", null, 250)]
|
||||
public int PhysicsOverload = 1500;
|
||||
[ConfigInt("Physics speed", "Physics", null, 250)]
|
||||
@ -187,5 +190,29 @@ namespace MCGalaxy {
|
||||
public int RoundsPlayed = 0;
|
||||
[ConfigInt("RoundsHumanWon", "Game", null, 0)]
|
||||
public int RoundsHumanWon = 0;
|
||||
|
||||
|
||||
public static void Load(string path, LevelConfig config) {
|
||||
PropertiesFile.Read(path, ref config, LineProcessor);
|
||||
}
|
||||
|
||||
static void LineProcessor(string key, string value, ref LevelConfig config) {
|
||||
if (!ConfigElement.Parse(Server.levelConfig, key, value, config)) {
|
||||
Logger.Log(LogType.Warning, "\"{0}\" was not a recognised level property key.", key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(string path, LevelConfig config, string lvlname) {
|
||||
try {
|
||||
using (StreamWriter w = new StreamWriter(path)) {
|
||||
w.WriteLine("#Level properties for " + lvlname);
|
||||
w.WriteLine("#Drown-time in seconds is [drown time] * 200 / 3 / 1000");
|
||||
ConfigElement.Serialise(Server.levelConfig, " settings", w, config);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.Log(LogType.Warning, "Failed to save level properties!");
|
||||
Logger.LogError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -529,7 +529,6 @@
|
||||
<Compile Include="Levels\IO\Importers\FcmImporter.cs" />
|
||||
<Compile Include="Levels\IO\Importers\LvlImporter.cs" />
|
||||
<Compile Include="Levels\IO\Importers\McfImporter.cs" />
|
||||
<Compile Include="Levels\IO\LvlProperties.cs" />
|
||||
<Compile Include="Levels\IO\MapFormats.cs" />
|
||||
<Compile Include="Levels\Level.Blocks.cs" />
|
||||
<Compile Include="Levels\Level.Fields.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user