mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Start work on Transform classes, which can transform the output of draw operations.
This commit is contained in:
parent
9260137d24
commit
ad08d6fa7e
@ -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>
|
||||
|
34
Drawing/Transform/SimpleTransforms.cs
Normal file
34
Drawing/Transform/SimpleTransforms.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
35
Drawing/Transform/Transform.cs
Normal file
35
Drawing/Transform/Transform.cs
Normal 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);
|
||||
}
|
||||
}
|
38
Drawing/TransformFactories/SimpleTransforms.cs
Normal file
38
Drawing/TransformFactories/SimpleTransforms.cs
Normal 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; }
|
||||
}
|
||||
}
|
53
Drawing/TransformFactories/TransformFactory.cs
Normal file
53
Drawing/TransformFactories/TransformFactory.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user