Private
Public Access
Refactored for chunks
This commit is contained in:
1 parent
ffc5891469
commit
f104f3846c
4 files changed
+76
-31
No files matched your search
+1
@@ -76,6 +76,7 @@
|
|||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Verbs\DrawingVerbs\Actions\NoOp.cs" />
|
||||||
<Compile Include="Verbs\DrawingVerbs\Shape\Circle.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Shape\Circle.cs" />
|
||||||
<Compile Include="Verbs\DrawingVerbs\Actions\Clear.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Actions\Clear.cs" />
|
||||||
<Compile Include="Verbs\DrawingVerbs\Shape\Dot.cs" />
|
<Compile Include="Verbs\DrawingVerbs\Shape\Dot.cs" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Advanced_Software_Engineering.Verbs.Value;
|
using Advanced_Software_Engineering.Verbs.Flow;
|
||||||
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -13,6 +14,8 @@ namespace Advanced_Software_Engineering {
|
|||||||
public class Drawer {
|
public class Drawer {
|
||||||
|
|
||||||
private ValueStorage valueStorage = new ValueStorage();
|
private ValueStorage valueStorage = new ValueStorage();
|
||||||
|
private ValueStorage verbFactoryVariables = new ValueStorage();
|
||||||
|
public List<VerbChunk> verbChunks = new List<VerbChunk>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The starting color of the pen / brush
|
/// The starting color of the pen / brush
|
||||||
@@ -197,5 +200,9 @@ namespace Advanced_Software_Engineering {
|
|||||||
return valueStorage;
|
return valueStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ValueStorage GetVerbFactoryVariables() {
|
||||||
|
return verbFactoryVariables;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
|||||||
this.conditional = conditional;
|
this.conditional = conditional;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteVerb() {
|
public new void ExecuteVerb() {
|
||||||
if (conditional.ToBool()) base.ExecuteVerb();
|
if (conditional.ToBool()) base.ExecuteVerb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Advanced_Software_Engineering.Verbs.DrawingVerbs;
|
using Advanced_Software_Engineering.Verbs.DrawingVerbs;
|
||||||
|
using Advanced_Software_Engineering.Verbs.DrawingVerbs.Actions;
|
||||||
|
using Advanced_Software_Engineering.Verbs.Flow;
|
||||||
using Advanced_Software_Engineering.Verbs.Value;
|
using Advanced_Software_Engineering.Verbs.Value;
|
||||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||||
@@ -22,20 +24,29 @@ namespace Advanced_Software_Engineering {
|
|||||||
/// <param name="fullCommand">The command as a string</param>
|
/// <param name="fullCommand">The command as a string</param>
|
||||||
/// <returns>A IVerb that maches the command</returns>
|
/// <returns>A IVerb that maches the command</returns>
|
||||||
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
|
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
|
||||||
int stackLevel = 0;
|
|
||||||
|
|
||||||
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
ValueStorage rootValueStorage = drawer.GetValueStorage();
|
||||||
|
|
||||||
|
List<VerbChunk> verbChunks = drawer.verbChunks;
|
||||||
|
if (verbChunks.Count == 0) verbChunks.Add(null);
|
||||||
|
|
||||||
|
int chunkDepth = verbChunks.Count - 1;
|
||||||
|
VerbChunk currentChunk = verbChunks[chunkDepth];
|
||||||
|
|
||||||
CommandAndParameterParserResult result = HelperFunctions.CommandAndParameterParser(fullCommand);
|
CommandAndParameterParserResult result = HelperFunctions.CommandAndParameterParser(fullCommand);
|
||||||
|
|
||||||
string command = result.getCommand();
|
string command = result.getCommand();
|
||||||
string[] commandParameters = result.getParameters();
|
string[] commandParameters = result.getParameters();
|
||||||
if (command == null) throw new Exception("There is no command to process");
|
if (command == null) throw new Exception("There is no command to process");
|
||||||
|
|
||||||
|
IVerb tmpVerb;
|
||||||
|
|
||||||
//check for names in directory
|
//check for names in directory
|
||||||
if (rootValueStorage.CheckVariableExists(command)) {
|
if (rootValueStorage.CheckVariableExists(command)) {
|
||||||
if (commandParameters.Length == 1) {
|
if (commandParameters.Length == 1) {
|
||||||
return new UpdateVariable(rootValueStorage, command, commandParameters[0]);
|
tmpVerb = new UpdateVariable(rootValueStorage, command, commandParameters[0]);
|
||||||
|
if (chunkDepth == 0) return tmpVerb;
|
||||||
|
currentChunk.AddVerb(tmpVerb);
|
||||||
|
return new NoOp();
|
||||||
} else throw new Exception(command + "needs something to be assigned to it");
|
} else throw new Exception(command + "needs something to be assigned to it");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +55,10 @@ namespace Advanced_Software_Engineering {
|
|||||||
switch (command) {
|
switch (command) {
|
||||||
case "var":
|
case "var":
|
||||||
if (commandParameters.Length == 1) {
|
if (commandParameters.Length == 1) {
|
||||||
return new DeclareVariable(rootValueStorage, commandParameters[0]);
|
tmpVerb = new DeclareVariable(rootValueStorage, commandParameters[0]);
|
||||||
|
if (chunkDepth == 0) return tmpVerb;
|
||||||
|
currentChunk.AddVerb(tmpVerb);
|
||||||
|
return new NoOp();
|
||||||
} else throw new Exception(command + "s need to be initialised");
|
} else throw new Exception(command + "s need to be initialised");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -52,7 +66,10 @@ namespace Advanced_Software_Engineering {
|
|||||||
if (rootValueStorage.CheckVariableExists(command)) {
|
if (rootValueStorage.CheckVariableExists(command)) {
|
||||||
string[] assignmentCommands = command.Split("="[0]);
|
string[] assignmentCommands = command.Split("="[0]);
|
||||||
if (assignmentCommands.Length > 2) throw new Exception("Cannot have two assignments");
|
if (assignmentCommands.Length > 2) throw new Exception("Cannot have two assignments");
|
||||||
return new UpdateVariable(rootValueStorage, assignmentCommands[0], ValueFactory.CreateValue(rootValueStorage, assignmentCommands[1]));
|
tmpVerb = new UpdateVariable(rootValueStorage, assignmentCommands[0], ValueFactory.CreateValue(rootValueStorage, assignmentCommands[1]));
|
||||||
|
if (chunkDepth == 0) return tmpVerb;
|
||||||
|
currentChunk.AddVerb(tmpVerb);
|
||||||
|
return new NoOp();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -63,6 +80,8 @@ namespace Advanced_Software_Engineering {
|
|||||||
}
|
}
|
||||||
int parameterLength = parameters.Count;
|
int parameterLength = parameters.Count;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//process drawing commands and extras
|
//process drawing commands and extras
|
||||||
switch (command) {
|
switch (command) {
|
||||||
//Drawing commands
|
//Drawing commands
|
||||||
@@ -70,50 +89,55 @@ namespace Advanced_Software_Engineering {
|
|||||||
case "moveto":
|
case "moveto":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 2) {
|
if (parameterLength == 2) {
|
||||||
return new MoveTo(drawer, new PointValue(parameters[0], parameters[1]));
|
tmpVerb = new MoveTo(drawer, new PointValue(parameters[0], parameters[1]));
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "drawto":
|
case "drawto":
|
||||||
case "line":
|
case "line":
|
||||||
case "lineto":
|
case "lineto":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 2) {
|
if (parameterLength == 2) {
|
||||||
return new DrawTo(drawer, new PointValue(parameters[0], parameters[1]));
|
tmpVerb = new DrawTo(drawer, new PointValue(parameters[0], parameters[1]));
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "regularpolygon":
|
case "regularpolygon":
|
||||||
case "rp":
|
case "rp":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 2) {
|
if (parameterLength == 2) {
|
||||||
return new RegularPolygon(drawer, parameters[0], parameters[1], new IntValue(0), new BoolValue(true));
|
tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], new IntValue(0), new BoolValue(true));
|
||||||
} else if (parameterLength == 3) {
|
} else if (parameterLength == 3) {
|
||||||
return new RegularPolygon(drawer, parameters[0], parameters[1], parameters[2], new BoolValue(true));
|
tmpVerb = new RegularPolygon(drawer, parameters[0], parameters[1], parameters[2], new BoolValue(true));
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "square":
|
case "square":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 1) {
|
if (parameterLength == 1) {
|
||||||
return new
|
tmpVerb = new
|
||||||
Square(drawer, parameters[0]);
|
Square(drawer, parameters[0]);
|
||||||
} else if (parameterLength == 2) {
|
} else if (parameterLength == 2) {
|
||||||
return new Square(drawer, parameters[0], parameters[1]);
|
tmpVerb = new Square(drawer, parameters[0], parameters[1]);
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "quadrilateral":
|
case "quadrilateral":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 8) {
|
if (parameterLength == 8) {
|
||||||
return new Quadrilateral(drawer,
|
tmpVerb = new Quadrilateral(drawer,
|
||||||
new PointValue(parameters[0], parameters[1]),
|
new PointValue(parameters[0], parameters[1]),
|
||||||
new PointValue(parameters[2], parameters[3]),
|
new PointValue(parameters[2], parameters[3]),
|
||||||
new PointValue(parameters[4], parameters[5]),
|
new PointValue(parameters[4], parameters[5]),
|
||||||
new PointValue(parameters[6], parameters[7])
|
new PointValue(parameters[6], parameters[7])
|
||||||
);
|
);
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "rectangle":
|
case "rectangle":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 2) {
|
if (parameterLength == 2) {
|
||||||
return new Rectangle(drawer, parameters[0], parameters[1]);
|
tmpVerb = new Rectangle(drawer, parameters[0], parameters[1]);
|
||||||
} else if (parameterLength == 8) {
|
} else if (parameterLength == 8) {
|
||||||
return new Quadrilateral(drawer,
|
return new Quadrilateral(drawer,
|
||||||
new PointValue(parameters[0], parameters[1]),
|
new PointValue(parameters[0], parameters[1]),
|
||||||
@@ -122,77 +146,90 @@ namespace Advanced_Software_Engineering {
|
|||||||
new PointValue(parameters[6], parameters[7])
|
new PointValue(parameters[6], parameters[7])
|
||||||
);
|
);
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "circle":
|
case "circle":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 1) {
|
if (parameterLength == 1) {
|
||||||
return new Circle(drawer, parameters[0]);
|
tmpVerb = new Circle(drawer, parameters[0]);
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "triangle":
|
case "triangle":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameterLength == 1) {
|
if (parameterLength == 1) {
|
||||||
return new
|
tmpVerb = new
|
||||||
Triangle(drawer, parameters[0]);
|
Triangle(drawer, parameters[0]);
|
||||||
} else if (parameterLength == 2) {
|
} else if (parameterLength == 2) {
|
||||||
return new
|
tmpVerb = new
|
||||||
Triangle(drawer, parameters[0], parameters[1]);
|
Triangle(drawer, parameters[0], parameters[1]);
|
||||||
} else if (parameterLength == 6) {
|
} else if (parameterLength == 6) {
|
||||||
return new Triangle(drawer,
|
tmpVerb = new Triangle(drawer,
|
||||||
new PointValue(parameters[0], parameters[1]),
|
new PointValue(parameters[0], parameters[1]),
|
||||||
new PointValue(parameters[2], parameters[3]),
|
new PointValue(parameters[2], parameters[3]),
|
||||||
new PointValue(parameters[4], parameters[5])
|
new PointValue(parameters[4], parameters[5])
|
||||||
);
|
);
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "dot":
|
case "dot":
|
||||||
if (parameterLength == 0) {
|
if (parameterLength == 0) {
|
||||||
return new Dot(drawer);
|
tmpVerb = new Dot(drawer);
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "clear":
|
case "clear":
|
||||||
if (parameterLength == 0) {
|
if (parameterLength == 0) {
|
||||||
return new Clear(drawer);
|
tmpVerb = new Clear(drawer);
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "reset":
|
case "reset":
|
||||||
case "resetpen":
|
case "resetpen":
|
||||||
if (parameterLength == 0) {
|
if (parameterLength == 0) {
|
||||||
return new ResetPen(drawer);
|
tmpVerb = new ResetPen(drawer);
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "fillon":
|
case "fillon":
|
||||||
if (parameterLength == 0) {
|
if (parameterLength == 0) {
|
||||||
return new Fill(drawer, true);
|
tmpVerb = new Fill(drawer, true);
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "filloff":
|
case "filloff":
|
||||||
if (parameterLength == 0) {
|
if (parameterLength == 0) {
|
||||||
return new Fill(drawer, false);
|
tmpVerb = new Fill(drawer, false);
|
||||||
} else throw new Exception(command + " doesn't take parameters");
|
} else throw new Exception(command + " doesn't take parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "pen":
|
case "pen":
|
||||||
if (parameterLength == 1) {
|
if (parameterLength == 1) {
|
||||||
return new PenColor(drawer, parameters[0]);
|
tmpVerb = new PenColor(drawer, parameters[0]);
|
||||||
} else if (parameterLength == 3) {
|
} else if (parameterLength == 3) {
|
||||||
return new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2]));
|
tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2]));
|
||||||
} else if (parameterLength == 4) {
|
} else if (parameterLength == 4) {
|
||||||
return new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
|
tmpVerb = new PenColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
case "fill":
|
case "fill":
|
||||||
if (parameterLength == 1) {
|
if (parameterLength == 1) {
|
||||||
return new FillColor(drawer, parameters[0]);
|
tmpVerb = new FillColor(drawer, parameters[0]);
|
||||||
} else if (parameterLength == 3) {
|
} else if (parameterLength == 3) {
|
||||||
return new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], new IntValue(255)));
|
tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], new IntValue(255)));
|
||||||
} else if (parameterLength == 4) {
|
} else if (parameterLength == 4) {
|
||||||
return new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
|
tmpVerb = new FillColor(drawer, new ColorValue(parameters[0], parameters[1], parameters[2], parameters[3]));
|
||||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
throw new Exception("Unknown command or cannot parse");
|
throw new Exception("Unknown command or cannot parse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chunkDepth == 0) return tmpVerb;
|
||||||
|
currentChunk.AddVerb(tmpVerb);
|
||||||
|
return new NoOp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user