Private
Public Access
Made it possible to instantly convert parameters to expressions
So things like circle 100 + i are possible now
This commit is contained in:
1 parent
1d9fed93a1
commit
351bf3f1fb
3 files changed
+45
-31
No files matched your search
+1
-25
@@ -20,31 +20,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
public UpdateVariable(ValueStorage storage, string name, string value) {
|
public UpdateVariable(ValueStorage storage, string name, string value) {
|
||||||
// incoming values look something like this "= 10"
|
// incoming values look something like this "= 10"
|
||||||
// or "= 10 + i"
|
// or "= 10 + i"
|
||||||
|
Init(storage, name, ValueHelper.ConvertToIValue(value, storage));
|
||||||
//seperate assignment characters from everything else
|
|
||||||
foreach (string op in new string[] { "=", "+", "-", "*", "/" }) {
|
|
||||||
value = value.Replace(op, " " + op + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
value = HelperFunctions.Strip(value);
|
|
||||||
if (value[0] == "="[0]) {
|
|
||||||
value = value.Substring(1);
|
|
||||||
}
|
|
||||||
// now will definitly look like this:
|
|
||||||
// 10 + i or i
|
|
||||||
|
|
||||||
string[] assignmentStrings = HelperFunctions.StripStringArray(value.Split(" "[0])).ToArray();
|
|
||||||
|
|
||||||
// assignmentStrings will look something like this:
|
|
||||||
// ["i"] or ["10", "+", "i"]
|
|
||||||
if (assignmentStrings.Length == 1) Init(storage, name, ValueFactory.CreateValue(storage, assignmentStrings[0]));
|
|
||||||
else if (assignmentStrings.Length == 3) {
|
|
||||||
// assignmentStrings looks like this => ["10", "+", "i"]
|
|
||||||
IValue value1 = ValueFactory.CreateValue(storage, assignmentStrings[0]);
|
|
||||||
string op = assignmentStrings[1];
|
|
||||||
IValue value2 = ValueFactory.CreateValue(storage, assignmentStrings[2]);
|
|
||||||
Init(storage, name, new ExpressionValue(value1, value2, op));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteVerb() {
|
public void ExecuteVerb() {
|
||||||
|
|||||||
+3
-3
@@ -60,10 +60,10 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IValue CreateValue(ValueStorage drawer, string value) {
|
public static IValue CreateValue(ValueStorage storage, string value) {
|
||||||
value = HelperFunctions.Strip(value);
|
value = HelperFunctions.Strip(value);
|
||||||
if (drawer.CheckVariableExists(value)) return new VariableValue(drawer, value);
|
if (storage.CheckVariableExists(value)) return new VariableValue(storage, value);
|
||||||
else return ValueHelper.ConvertToIValue(value);
|
else return ValueHelper.ConvertToIValue(value, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IValue CreateValue(bool b) {
|
public static IValue CreateValue(bool b) {
|
||||||
|
|||||||
+41
-3
@@ -120,7 +120,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IValue ConvertToIValue(string text) {
|
public static IValue ConvertToIValue(string text, ValueStorage storage = null) {
|
||||||
text = HelperFunctions.Strip(text);
|
text = HelperFunctions.Strip(text);
|
||||||
//No assignmnet
|
//No assignmnet
|
||||||
if (!text.Contains("=")) {
|
if (!text.Contains("=")) {
|
||||||
@@ -136,6 +136,37 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
try {
|
try {
|
||||||
return ValueFactory.CreateValue(text, "double");
|
return ValueFactory.CreateValue(text, "double");
|
||||||
} catch (Exception) { }
|
} catch (Exception) { }
|
||||||
|
|
||||||
|
//check for expression
|
||||||
|
if (storage != null)
|
||||||
|
try {
|
||||||
|
string value = text;
|
||||||
|
//seperate assignment characters from everything else
|
||||||
|
foreach (string op in new string[] { "=", "+", "-", "*", "/" }) {
|
||||||
|
value = value.Replace(op, " " + op + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
value = HelperFunctions.Strip(value);
|
||||||
|
if (value[0] == "="[0]) {
|
||||||
|
value = value.Substring(1);
|
||||||
|
}
|
||||||
|
// now will definitly look like this:
|
||||||
|
// 10 + i or i
|
||||||
|
|
||||||
|
string[] assignmentStrings = HelperFunctions.StripStringArray(value.Split(" "[0])).ToArray();
|
||||||
|
|
||||||
|
// assignmentStrings will look something like this:
|
||||||
|
// ["i"] or ["10", "+", "i"]
|
||||||
|
if (assignmentStrings.Length == 1) return ValueFactory.CreateValue(storage, assignmentStrings[0]);
|
||||||
|
else if (assignmentStrings.Length == 3) {
|
||||||
|
// assignmentStrings looks like this => ["10", "+", "i"]
|
||||||
|
IValue value1 = ValueFactory.CreateValue(storage, assignmentStrings[0]);
|
||||||
|
string op = assignmentStrings[1];
|
||||||
|
IValue value2 = ValueFactory.CreateValue(storage, assignmentStrings[2]);
|
||||||
|
return new ExpressionValue(value1, value2, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if color
|
//Check if color
|
||||||
@@ -145,8 +176,15 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
|||||||
} else {
|
} else {
|
||||||
//Check if string is a bool TODO
|
//Check if string is a bool TODO
|
||||||
|
|
||||||
//Check if string is an expression
|
//Check if expression
|
||||||
return ValueFactory.CreateValue(text, "expression");
|
if (storage != null) {
|
||||||
|
string value = text;
|
||||||
|
value = HelperFunctions.Strip(value);
|
||||||
|
if (value[0] == "="[0]) {
|
||||||
|
value = value.Substring(1);
|
||||||
|
}
|
||||||
|
return ConvertToIValue(value, storage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new Exception("Could not convert " + text + " to any type");
|
throw new Exception("Could not convert " + text + " to any type");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user