Get rid of lambda usage in LevelOption, reduce size by another 1KB

This commit is contained in:
UnknownShadow200 2017-09-20 20:16:25 +10:00
parent 57a4777a87
commit 3dc6b9e2a6
3 changed files with 77 additions and 78 deletions

View File

@ -195,7 +195,6 @@ namespace MCGalaxy.Commands.Fun {
switch (text[1]) {
case "all":
case "a":
case "everyone":
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
Player.Message(pl, "TNT Wars Rules: (sent to all players by " + p.ColoredName + " %S)");
@ -206,9 +205,6 @@ namespace MCGalaxy.Commands.Fun {
case "level":
case "l":
case "lvl":
case "map":
case "m":
foreach (Player pl in p.level.players) {
Player.Message(pl, "TNT Wars Rules: (sent to all players in map by " + p.ColoredName + " %S)");
SendRules(pl);
@ -217,8 +213,6 @@ namespace MCGalaxy.Commands.Fun {
return;
case "players":
case "pls":
case "pl":
case "p":
TntWarsGame gm = TntWarsGame.GameIn(p);
if (gm == null) { Player.Message(p, "TNT Wars Error: You aren't in a TNT Wars game!"); return; }
@ -285,10 +279,6 @@ namespace MCGalaxy.Commands.Fun {
}
break;
case "me":
case "mine":
case "score":
case "i":
default:
if (tntwrs.GameStatus == TntWarsGame.TntWarsGameStatus.InProgress) {
Player.Message(p, "TNT Wars: Your Score: " + Colors.white + TntWarsGame.GameIn(p).FindPlayer(p).Score);
@ -1022,10 +1012,7 @@ namespace MCGalaxy.Commands.Fun {
Player.Message(p, "TNT Wars: {0} is now &cdisabled", name); return true;
case "check":
case "current":
case "now":
case "ATM":
case "c":
case "t":
Player.Message(p, "TNT Wars: {0} is currently {1}", name, target ? "&aenabled" : "&cdisabled"); return false;
default:
target = !target;

View File

@ -102,8 +102,21 @@ namespace MCGalaxy.Drawing.Ops {
static ulong[] letters;
static WriteDrawOp() {
letters = new ulong[256];
// each set bit means place a block at y offset equal to that bit index.
// e.g. 0x0A means place a block at 'y = 0' and at 'y = 3'
// Each letter is represented as 8 bytes
// Each byte represents a vertical line in that letter.
// For each byte, each set bit means place a block at y offset equal to the index of that bit.
// For example, take the letter 'A', which is 0x0F140F0000000000UL
// Taking each byte in the 'A' until value is 0, we get 0x0F 0x14 0x0F, which becomes
// y = 7
// y = 6
// y = 5
// █ y = 4
// █ █ y = 3
// ███ y = 2
// █ █ y = 1
// █ █ y = 0
letters['A'] = 0x0F140F0000000000UL;
letters['B'] = 0x1F150A0000000000UL;
letters['C'] = 0x0E11110000000000UL;

View File

@ -23,35 +23,16 @@ using MCGalaxy.Generator.Foliage;
namespace MCGalaxy {
public static class LevelOptions {
public delegate void OptionSetter(Player p, Level lvl, string value);
public delegate bool OptionIntValidator(Player p, int value);
public static Dictionary<string, OptionSetter> Options = new Dictionary<string, OptionSetter>() {
{ "motd", SetMotd },
{ "RealmOwner", SetRealmOwner },
{ "TreeType", SetTreeType },
{ "PhysicSpeed", (p, l, value) => SetInt(p, l, ref l.Config.PhysicsSpeed, value, "Physics speed", SpeedValidator) },
{ "Overload", (p, l, value) => SetInt(p, l, ref l.Config.PhysicsOverload, value, "Physics overload", OverloadValidator) },
{ "Fall", (p, l, value) => SetInt(p, l, ref l.Config.FallHeight, value, "Fall distance") },
{ "Drown", (p, l, value) => SetInt(p, l, ref l.Config.DrownTime, value, "Drown time (in tenths of a second)") },
{ "Finite", (p, l, value) => Toggle(p, l, ref l.Config.FiniteLiquids, "Finite mode") },
{ "AI", (p, l, value) => Toggle(p, l, ref l.Config.AnimalHuntAI, "Animal AI") },
{ "Edge", (p, l, value) => Toggle(p, l, ref l.Config.EdgeWater, "Edge water") },
{ "Grass", (p, l, value) => Toggle(p, l, ref l.Config.GrassGrow, "Growing grass") },
{ "Death", (p, l, value) => Toggle(p, l, ref l.Config.SurvivalDeath, "Survival death") },
{ "Killer", (p, l, value) => Toggle(p, l, ref l.Config.KillerBlocks, "Killer blocks") },
{ "Unload", (p, l, value) => Toggle(p, l, ref l.Config.AutoUnload, "Auto unload") },
{ "LoadOnGoto", (p, l, value) => Toggle(p, l, ref l.Config.LoadOnGoto, "Load on goto") },
{ "LeafDecay", (p, l, value) => Toggle(p, l, ref l.Config.LeafDecay, "Leaf decay") },
{ "RandomFlow", (p, l, value) => Toggle(p, l, ref l.Config.RandomFlow, "Random flow") },
{ "GrowTrees", (p, l, value) => Toggle(p, l, ref l.Config.GrowTrees, "Tree growing") },
{ "Chat", (p, l, value) => Toggle(p, l, ref l.Config.ServerWideChat, "Roleplay (level only) chat", true) },
{ "Guns", ToggleGuns },
{ "Buildable", (p, l, value) => TogglePerms(p, l, ref l.Config.Buildable, "Buildable") },
{ "Deletable", (p, l, value) => TogglePerms(p, l, ref l.Config.Deletable, "Deletable") },
{ "LoadDelay", (p, l, value) => SetInt(p, l, ref l.Config.LoadDelay, value, "Load delay", DelayValidator) },
{ "motd", SetMotd }, { "RealmOwner", SetRealmOwner }, { "TreeType", SetTreeType },
{ "PhysicSpeed", SetPhysicSpeed }, { "Overload", SetOverload }, { "Fall", SetFall }, { "Drown", SetDrown },
{ "Finite", SetFinite }, { "AI", SetAI }, { "Edge", SetEdge }, { "Grass", SetGrass },
{ "Death", SetDeath }, { "Killer", SetKiller }, { "Unload", SetUnload }, { "LoadOnGoto", SetLoadOnGoto },
{ "LeafDecay", SetLeafDecay }, { "RandomFlow", SetRandomFlow }, { "GrowTrees", SetGrowTrees },
{ "Chat", SetChat }, { "Guns", ToggleGuns }, { "Buildable", SetBuildable }, { "Deletable", SetDeletable },
{ "LoadDelay", SetLoadDelay },
};
public static Dictionary<string, string> Help = new Dictionary<string, string>() {
@ -90,8 +71,6 @@ namespace MCGalaxy {
return opt;
}
static string GetBool(bool value) { return value ? "&aON" : "&cOFF"; }
static void SetMotd(Player p, Level lvl, string value) {
lvl.Config.MOTD = value.Length == 0 ? "ignore" : value;
lvl.ChatLevel("Map's MOTD was changed to: &b" + lvl.Config.MOTD);
@ -127,40 +106,58 @@ namespace MCGalaxy {
Player.Message(p, "Set tree type that saplings grow into to {0}.", value);
}
static bool SpeedValidator(Player p, int raw) {
if (raw < 10) { Player.Message(p, "Physics speed cannot be below 10 milliseconds."); return false; }
return true;
static void SetFinite(Player p, Level l, string v) { Toggle(p, l, ref l.Config.FiniteLiquids, "Finite mode"); }
static void SetAI(Player p, Level l, string v) { Toggle(p, l, ref l.Config.AnimalHuntAI, "Animal AI"); }
static void SetEdge(Player p, Level l, string v) { Toggle(p, l, ref l.Config.EdgeWater, "Edge water"); }
static void SetGrass(Player p, Level l, string v) { Toggle(p, l, ref l.Config.GrassGrow, "Growing grass"); }
static void SetDeath(Player p, Level l, string v) { Toggle(p, l, ref l.Config.SurvivalDeath, "Survival death"); }
static void SetKiller(Player p, Level l, string v) { Toggle(p, l, ref l.Config.KillerBlocks, "Killer blocks"); }
static void SetUnload(Player p, Level l, string v) { Toggle(p, l, ref l.Config.AutoUnload, "Auto unload"); }
static void SetLoadOnGoto(Player p, Level l, string v) { Toggle(p, l, ref l.Config.LoadOnGoto, "Load on goto"); }
static void SetLeafDecay(Player p, Level l, string v) { Toggle(p, l, ref l.Config.LeafDecay, "Leaf decay"); }
static void SetRandomFlow(Player p, Level l, string v) { Toggle(p, l, ref l.Config.RandomFlow, "Random flow"); }
static void SetGrowTrees(Player p, Level l, string v) { Toggle(p, l, ref l.Config.GrowTrees, "Tree growing"); }
static void SetBuildable(Player p, Level l, string v) { TogglePerms(p, l, ref l.Config.Buildable, "Buildable"); }
static void SetDeletable(Player p, Level l, string v) { TogglePerms(p, l, ref l.Config.Deletable, "Deletable"); }
static void SetChat(Player p, Level l, string v) {
Toggle(p, l, ref l.Config.ServerWideChat, "Roleplay (level only) chat", true);
}
static bool OverloadValidator(Player p, int raw) {
if (raw < 500) {
Player.Message(p, "Physics overload cannot go below 500 (default is 1500)"); return false;
}
if (p != null && p.Rank < LevelPermission.Admin && raw > 2500) {
Player.Message(p, "Only SuperOPs may set physics overload higher than 2500"); return false;
}
return true;
}
static bool DelayValidator(Player p, int raw) {
if (raw < 0) {
Player.Message(p, "Load delay cannot go below 0 milliseconds. (default is 0)"); return false;
}
if (raw > 2000) {
Player.Message(p, "Load delay cannot go above 2000 milliseconds."); return false;
}
return true;
}
static void SetInt(Player p, Level lvl, ref int target, string value, string name,
OptionIntValidator validator = null) {
if (value.Length == 0) { Player.Message(p, "You must provide an integer."); return; }
static void SetLoadDelay(Player p, Level l, string value) {
int raw = 0;
if (!CommandParser.GetInt(p, value, name, ref raw)) return;
if (!CommandParser.GetInt(p, value, "Load delay", ref raw, 0, 2000)) return;
SetInt(l, raw, ref l.Config.LoadDelay, "Load delay");
}
if (validator != null && !validator(p, raw)) return;
static void SetPhysicSpeed(Player p, Level l, string value) {
int raw = 0;
if (!CommandParser.GetInt(p, value, "Physics speed", ref raw, 10)) return;
SetInt(l, raw, ref l.Config.PhysicsSpeed, "Physics speed");
}
static void SetOverload(Player p, Level l, string value) {
int raw = 0;
if (!CommandParser.GetInt(p, value, "Physics overload", ref raw, 500)) return;
if (p != null && p.Rank < LevelPermission.Admin && raw > 2500) {
Player.Message(p, "Only SuperOPs may set physics overload higher than 2500"); return;
}
SetInt(l, raw, ref l.Config.PhysicsOverload, "Physics overload");
}
static void SetFall(Player p, Level l, string value) {
int raw = 0;
if (!CommandParser.GetInt(p, value, "Fall distance", ref raw)) return;
SetInt(l, raw, ref l.Config.FallHeight, "Fall distance");
}
static void SetDrown(Player p, Level l, string value) {
int raw = 0;
if (!CommandParser.GetInt(p, value, "Drown time (in tenths of a second)", ref raw)) return;
SetInt(l, raw, ref l.Config.DrownTime, "Drown time (in tenths of a second)");
}
static void SetInt(Level lvl, int raw, ref int target, string name) {
target = raw;
lvl.ChatLevel(name + ": &b" + target);
}
@ -187,10 +184,12 @@ namespace MCGalaxy {
static void Toggle(Player p, Level lvl, ref bool target, string name, bool not = false) {
target = !target;
bool display = not ? !target : target;
lvl.ChatLevel(name + ": " + GetBool(display));
string targetStr = display ? "&aON" : "&cOFF";
lvl.ChatLevel(name + ": " + targetStr);
if (p == null || p.level != lvl)
Player.Message(p, name + ": " + GetBool(display));
if (p == null || p.level != lvl) {
Player.Message(p, name + ": " + targetStr);
}
}
}
}