Start work on Transform classes, which can transform the output of draw operations.

This commit is contained in:
UnknownShadow200 2016-08-25 15:36:35 +10:00
parent 9260137d24
commit ad08d6fa7e
6 changed files with 170 additions and 4 deletions

View File

@ -47,18 +47,18 @@ namespace MCGalaxy.Drawing.Brushes {
public static string Available { get { return Brushes.Join(b => b.Name); } }
public static BrushFactory Find(string name) {
foreach (BrushFactory brush in Brushes) {
if (brush.Name.CaselessEq(name)) return brush;
foreach (BrushFactory entry in Brushes) {
if (entry.Name.CaselessEq(name)) return entry;
}
return null;
}
}
public struct BrushArgs {
/// <summary> Player that is providing arguments for this brush. </summary>
/// <summary> Player that is providing arguments. </summary>
public Player Player;
/// <summary> Raw message provided for arguments to the brush, including spaces. </summary>
/// <summary> Raw message provided for arguments, including spaces. </summary>
public string Message;
/// <summary> Raw block the player is currently holding. </summary>

View File

@ -0,0 +1,34 @@
/*
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 System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing.Transforms {
public sealed class NoTransform : Transform {
/// <summary> Human friendly name of this transform. </summary>
public override string Name { get { return "None"; } }
public override IEnumerable<DrawOpBlock> Perform(Vec3S32[] marks, Player p,
Level lvl, DrawOp op, Brush brush) {
return op.Perform(marks, p, lvl, brush);
}
}
}

View File

@ -0,0 +1,35 @@
/*
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 System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing.Transforms {
public abstract class Transform {
/// <summary> Human friendly name of this transform. </summary>
public abstract string Name { get; }
/// <summary> Performs calcuations (if necessary) for the given drawop. </summary>
public virtual void Configure(DrawOp op, Player p) { }
public abstract IEnumerable<DrawOpBlock> Perform(Vec3S32[] marks, Player p,
Level lvl, DrawOp op, Brush brush);
}
}

View File

@ -0,0 +1,38 @@
/*
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.Commands.Building;
using MCGalaxy.Drawing.Brushes;
namespace MCGalaxy.Drawing.Transforms {
public sealed class NoTransformFactory : TransformFactory {
public override string Name { get { return "None"; } }
public override string[] Help { get { return HelpString; } }
static string[] HelpString = new [] {
"%TArguments: none",
"%HDoes not affect the output of draw operations.",
};
public override Transform Construct(BrushArgs args) {
return new NoTransform();
}
public override bool Validate(BrushArgs args) { return true; }
}
}

View File

@ -0,0 +1,53 @@
/*
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 System.Collections.Generic;
using MCGalaxy.Commands;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing.Transforms {
public abstract class TransformFactory {
/// <summary> Human friendly name of this transform. </summary>
public abstract string Name { get; }
/// <summary> Description of the transform, in addition to its syntax. </summary>
public abstract string[] Help { get; }
/// <summary> Creates a transform from the given arguments,
/// returning null if invalid arguments are specified. </summary>
public abstract Transform Construct(BrushArgs args);
/// <summary> Validates the given arguments, returning false if they are invalid. </summary>
public virtual bool Validate(BrushArgs args) { return Construct(args) != null; }
public static List<TransformFactory> Transforms = new List<TransformFactory>() {
new NoTransformFactory(),
};
public static string Available { get { return Transforms.Join(b => b.Name); } }
public static TransformFactory Find(string name) {
foreach (TransformFactory entry in Transforms) {
if (entry.Name.CaselessEq(name)) return entry;
}
return null;
}
}
}

View File

@ -452,6 +452,10 @@
<Compile Include="Drawing\Flip.cs" />
<Compile Include="Drawing\Image\ImagePalette.cs" />
<Compile Include="Drawing\Image\IPalette.cs" />
<Compile Include="Drawing\TransformFactories\SimpleTransforms.cs" />
<Compile Include="Drawing\TransformFactories\TransformFactory.cs" />
<Compile Include="Drawing\Transform\SimpleTransforms.cs" />
<Compile Include="Drawing\Transform\Transform.cs" />
<Compile Include="Economy\Awards.cs" />
<Compile Include="Economy\ReviveItem.cs" />
<Compile Include="Economy\ZombieItems.cs" />
@ -700,6 +704,8 @@
<Folder Include="Drawing\Brushes" />
<Folder Include="Drawing\Image" />
<Folder Include="Drawing\BrushFactories" />
<Folder Include="Drawing\TransformFactories" />
<Folder Include="Drawing\Transform" />
<Folder Include="Games\Countdown" />
<Folder Include="Games\LavaSurvival" />
<Folder Include="Games\TntWars" />