mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Initial work on /palette
This commit is contained in:
parent
cccf68549f
commit
d325a7c087
@ -48,7 +48,7 @@ namespace MCGalaxy.Blocks {
|
||||
byte extBlock = p.level.GetExtTile(x, y, z);
|
||||
BlockDefinition def = p.level.CustomBlockDefs[extBlock];
|
||||
if (def == null) return false; // custom block was removed
|
||||
if (def.CollideType == 2) return false;
|
||||
if (def.CollideType == CollideType.Solid) return false;
|
||||
|
||||
if (p.level.CustomBlockProps[extBlock].IsPortal) {
|
||||
return DoPortal(p, block, x, y, z);
|
||||
|
@ -104,6 +104,8 @@ namespace MCGalaxy.Blocks {
|
||||
return SoundType.Cloth;
|
||||
if (b >= Block.lightpink && b <= Block.turquoise)
|
||||
return SoundType.Cloth;
|
||||
if (b == Block.iron || b == Block.goldsolid)
|
||||
return SoundType.Metal;
|
||||
|
||||
if (b == Block.bookcase || b == Block.wood
|
||||
|| b == Block.trunk || b == Block.crate || b == Block.fire)
|
||||
|
@ -22,10 +22,10 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
public static class LeafPhysics {
|
||||
|
||||
public static void DoLeaf(Level lvl, ref Check C) {
|
||||
Random rand = lvl.physRandom;
|
||||
ushort x, y, z;
|
||||
lvl.IntToPos(C.b, out x, out y, out z);
|
||||
if (lvl.physics > 1) { //Adv physics kills flowers and mushroos in water/lava
|
||||
ushort x, y, z;
|
||||
lvl.IntToPos(C.b, out x, out y, out z);
|
||||
|
||||
AirPhysics.PhysAir(lvl, lvl.PosToInt((ushort)(x + 1), y, z));
|
||||
AirPhysics.PhysAir(lvl, lvl.PosToInt((ushort)(x - 1), y, z));
|
||||
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z + 1)));
|
||||
@ -33,14 +33,20 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, (ushort)(y + 1), z));
|
||||
}
|
||||
|
||||
// Just immediately remove from physics list
|
||||
if (!lvl.leafDecay) {
|
||||
lvl.leaves.Clear();
|
||||
C.data.Data = PhysicsArgs.RemoveFromChecks; return;
|
||||
}
|
||||
|
||||
// Delay checking for decay for a random amount of time
|
||||
if (C.data.Data < 5) {
|
||||
Random rand = lvl.physRandom;
|
||||
if (rand.Next(10) == 0) C.data.Data++;
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform actual leaf decay, then remove from physics list
|
||||
if (DoLeafDecay(lvl, ref C)) lvl.AddUpdate(C.b, Block.air);
|
||||
C.data.Data = PhysicsArgs.RemoveFromChecks;
|
||||
}
|
||||
|
@ -57,7 +57,12 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (parts.Length >= 2) {
|
||||
dArgs.palette = ImagePalette.Find(parts[1]);
|
||||
if (dArgs.palette == null) {
|
||||
Player.Message(p, "Palette {0} not found.", parts[1]); return;
|
||||
Player.Message(p, "Palette {0} not found.", parts[1]); return;
|
||||
}
|
||||
|
||||
if (dArgs.palette.FrontLayer == null || dArgs.palette.FrontLayer.Length == 0) {
|
||||
Player.Message(p, "Palette {0} does not have any entries");
|
||||
Player.Message(p, "Use %T/palette %Sto add entries to it"); return;
|
||||
}
|
||||
}
|
||||
|
||||
|
80
MCGalaxy/Commands/building/CmdPalette.cs
Normal file
80
MCGalaxy/Commands/building/CmdPalette.cs
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright 2015 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 MCGalaxy.Drawing;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdPalette : Command {
|
||||
public override string name { get { return "palette"; } }
|
||||
public override string shortcut { get { return "imgpalette"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces(4);
|
||||
if (message == "") { Help(p); return; }
|
||||
|
||||
if (args[0].CaselessEq("create")) {
|
||||
HandleCreate(p, args);
|
||||
} else if (args[0].CaselessEq("delete")) {
|
||||
HandleDelete(p, args);
|
||||
} else if (args[0].CaselessEq("add")) {
|
||||
Player.Message(p, "?????");
|
||||
} else if (args[0].CaselessEq("remove")) {
|
||||
Player.Message(p, "?????");
|
||||
}
|
||||
}
|
||||
|
||||
void HandleCreate(Player p, string[] args) {
|
||||
if (args.Length != 2) { Help(p); return; }
|
||||
if (!Formatter.ValidName(p, args[1], "palette")) return;
|
||||
|
||||
ImagePalette palette = ImagePalette.Find(args[1]);
|
||||
if (palette != null) {
|
||||
Player.Message(p, "Palette {0} already exists.", args[1]);
|
||||
} else {
|
||||
ImagePalette.Add(args[1]);
|
||||
Player.Message(p, "Created palette {0}", args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleDelete(Player p, string[] args) {
|
||||
if (args.Length != 2) { Help(p); return; }
|
||||
|
||||
ImagePalette palette = ImagePalette.Find(args[1]);
|
||||
if (palette == null) {
|
||||
Player.Message(p, "Palette {0} does not exist.", args[1]);
|
||||
} else {
|
||||
ImagePalette.Remove(palette);
|
||||
Player.Message(p, "Removed palette {0}", args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/palette create/delete [name]");
|
||||
Player.Message(p, "%HCreates or deletes a palette for %T/imageprint");
|
||||
Player.Message(p, "%T/palette add [name] [block] [hex color] <back>");
|
||||
Player.Message(p, "???");
|
||||
Player.Message(p, "%T/palette remove [name] [block]");
|
||||
Player.Message(p, "???");
|
||||
Player.Message(p, "%HPalettes: &f{0}", ImagePalette.Palettes.Join(pal => pal.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy.Drawing {
|
||||
|
||||
@ -25,6 +26,9 @@ namespace MCGalaxy.Drawing {
|
||||
/// <summary> The name of this palette. </summary>
|
||||
public string Name;
|
||||
|
||||
/// <summary> Relative file path on disc. </summary>
|
||||
public string FileName { get { return "extra/palettes/" + Name + ".pal"; } }
|
||||
|
||||
/// <summary> Blocks in the front, used in vertical and layer mode. </summary>
|
||||
public PaletteEntry[] FrontLayer;
|
||||
|
||||
@ -52,6 +56,74 @@ namespace MCGalaxy.Drawing {
|
||||
Palettes.Add(new ImagePalette("Grayscale", Grayscale_Front, Grayscale_Back));
|
||||
Palettes.Add(new ImagePalette("BlackWhite", BlackWhite_Front, null));
|
||||
Palettes.Add(new ImagePalette("SimpleGrayscale", Grayscale_Mathematical, null));
|
||||
|
||||
if (!Directory.Exists("extra/palettes"))
|
||||
Directory.CreateDirectory("extra/palettes");
|
||||
string[] files = Directory.GetFiles("extra/palettes");
|
||||
foreach (string file in files)
|
||||
LoadPalette(file);
|
||||
}
|
||||
|
||||
static void LoadPalette(string file) {
|
||||
string name = Path.GetFileNameWithoutExtension(file);
|
||||
ImagePalette palette = Find(name);
|
||||
if (palette != null) Palettes.Remove(palette);
|
||||
palette = new ImagePalette(name, null, null);
|
||||
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
List<PaletteEntry> front = new List<PaletteEntry>();
|
||||
List<PaletteEntry> back = new List<PaletteEntry>();
|
||||
|
||||
foreach (string line in lines) {
|
||||
if (line.StartsWith("#") || line.Length == 0) continue;
|
||||
|
||||
string[] parts = line.Split(':');
|
||||
if (parts.Length != 5) continue;
|
||||
|
||||
if (parts[0].CaselessEq("front")) {
|
||||
front.Add(ParseEntry(parts));
|
||||
} else if (parts[0].CaselessEq("back")) {
|
||||
back.Add(ParseEntry(parts));
|
||||
}
|
||||
}
|
||||
|
||||
palette.FrontLayer = front.ToArray();
|
||||
if (back.Count > 0) palette.BackLayer = back.ToArray();
|
||||
Palettes.Add(palette);
|
||||
}
|
||||
|
||||
static PaletteEntry ParseEntry(string[] parts) {
|
||||
byte r = byte.Parse(parts[4]), g = byte.Parse(parts[3]);
|
||||
byte b = byte.Parse(parts[2]), block = byte.Parse(parts[1]);
|
||||
return new PaletteEntry(r, g, b, block);
|
||||
}
|
||||
|
||||
public static void SavePalette(ImagePalette palette) {
|
||||
using (StreamWriter w = new StreamWriter(palette.FileName)) {
|
||||
w.WriteLine("#Line layout - type:block:red:green:blue");
|
||||
|
||||
if (palette.FrontLayer != null) {
|
||||
foreach (PaletteEntry e in palette.FrontLayer)
|
||||
w.WriteLine("front:" + e.Block + ":" + e.R + ":" + e.G + ":" + e.B);
|
||||
}
|
||||
|
||||
if (palette.BackLayer != null) {
|
||||
foreach (PaletteEntry e in palette.BackLayer)
|
||||
w.WriteLine("back:" + e.Block + ":" + e.R + ":" + e.G + ":" + e.B);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Add(string name) {
|
||||
ImagePalette palette = new ImagePalette(name, null, null);
|
||||
Palettes.Add(palette);
|
||||
using (File.Create(palette.FileName)) { }
|
||||
}
|
||||
|
||||
public static void Remove(ImagePalette palette) {
|
||||
Palettes.Remove(palette);
|
||||
if (!File.Exists(palette.FileName)) return;
|
||||
File.Delete(palette.FileName);
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,6 +64,9 @@ namespace MCGalaxy.Drawing.Transforms {
|
||||
rotY = sinZ * dx + cosZ * dy;
|
||||
dx = rotX; dy = rotY;
|
||||
|
||||
Server.s.Log("BASE: " + b.X + ", " + b.Y + ", + " + b.Z);
|
||||
Server.s.Log("ROTATED: " + (dx + P.X) + ", " + (dy + P.Y) + ", " + (dz + P.Z));
|
||||
|
||||
b.X = (ushort)(dx + P.X + ((dx % 1) >= 0.5 ? 1 : 0));
|
||||
b.Y = (ushort)(dy + P.Y + ((dy % 1) >= 0.5 ? 1 : 0));
|
||||
b.Z = (ushort)(dz + P.Z + ((dz % 1) >= 0.5 ? 1 : 0));
|
||||
|
@ -142,6 +142,7 @@
|
||||
<Compile Include="Commands\building\CmdMode.cs" />
|
||||
<Compile Include="Commands\building\CmdOutline.cs" />
|
||||
<Compile Include="Commands\building\CmdPaint.cs" />
|
||||
<Compile Include="Commands\building\CmdPalette.cs" />
|
||||
<Compile Include="Commands\building\CmdPaste.cs" />
|
||||
<Compile Include="Commands\building\CmdPlace.cs" />
|
||||
<Compile Include="Commands\building\CmdPortal.cs" />
|
||||
|
@ -13,7 +13,6 @@ or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Timers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user