-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddde5af
commit 9344cdc
Showing
66 changed files
with
8,954 additions
and
9,307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 49 additions & 49 deletions
98
src/main/java/com/bladecoder/ink/runtime/AbstractValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
package com.bladecoder.ink.runtime; | ||
|
||
public abstract class AbstractValue extends RTObject { | ||
public abstract ValueType getValueType(); | ||
|
||
public abstract boolean isTruthy() throws Exception; | ||
|
||
public abstract AbstractValue cast(ValueType newType) throws Exception; | ||
|
||
public abstract Object getValueObject(); | ||
|
||
public static AbstractValue create(Object val) { | ||
// Implicitly lose precision from any doubles we get passed in | ||
if (val instanceof Double) { | ||
double doub = (Double) val; | ||
val = (float) doub; | ||
} | ||
|
||
if (val instanceof Boolean) { | ||
return new BoolValue((Boolean) val); | ||
} else if (val instanceof Integer) { | ||
return new IntValue((Integer) val); | ||
} else if (val instanceof Long) { | ||
return new IntValue(((Long) val).intValue()); | ||
} else if (val instanceof Float) { | ||
return new FloatValue((Float) val); | ||
} else if (val instanceof Double) { | ||
return new FloatValue((((Double) val).floatValue())); | ||
} else if (val instanceof String) { | ||
return new StringValue((String) val); | ||
} else if (val instanceof Path) { | ||
return new DivertTargetValue((Path) val); | ||
} else if (val instanceof InkList) { | ||
return new ListValue((InkList) val); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
RTObject copy() { | ||
return create(getValueObject()); | ||
} | ||
|
||
protected StoryException BadCastException(ValueType targetType) throws Exception { | ||
return new StoryException( | ||
"Can't cast " + this.getValueObject() + " from " + this.getValueType() + " to " + targetType); | ||
} | ||
} | ||
package com.bladecoder.ink.runtime; | ||
|
||
public abstract class AbstractValue extends RTObject { | ||
public abstract ValueType getValueType(); | ||
|
||
public abstract boolean isTruthy() throws Exception; | ||
|
||
public abstract AbstractValue cast(ValueType newType) throws Exception; | ||
|
||
public abstract Object getValueObject(); | ||
|
||
public static AbstractValue create(Object val) { | ||
// Implicitly lose precision from any doubles we get passed in | ||
if (val instanceof Double) { | ||
double doub = (Double) val; | ||
val = (float) doub; | ||
} | ||
|
||
if (val instanceof Boolean) { | ||
return new BoolValue((Boolean) val); | ||
} else if (val instanceof Integer) { | ||
return new IntValue((Integer) val); | ||
} else if (val instanceof Long) { | ||
return new IntValue(((Long) val).intValue()); | ||
} else if (val instanceof Float) { | ||
return new FloatValue((Float) val); | ||
} else if (val instanceof Double) { | ||
return new FloatValue((((Double) val).floatValue())); | ||
} else if (val instanceof String) { | ||
return new StringValue((String) val); | ||
} else if (val instanceof Path) { | ||
return new DivertTargetValue((Path) val); | ||
} else if (val instanceof InkList) { | ||
return new ListValue((InkList) val); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
RTObject copy() { | ||
return create(getValueObject()); | ||
} | ||
|
||
protected StoryException BadCastException(ValueType targetType) throws Exception { | ||
return new StoryException( | ||
"Can't cast " + this.getValueObject() + " from " + this.getValueType() + " to " + targetType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
package com.bladecoder.ink.runtime; | ||
|
||
class BoolValue extends Value<Boolean> { | ||
public BoolValue() { | ||
this(false); | ||
} | ||
|
||
public BoolValue(boolean boolVal) { | ||
super(boolVal); | ||
} | ||
|
||
@Override | ||
public AbstractValue cast(ValueType newType) throws Exception { | ||
if (newType == getValueType()) { | ||
return this; | ||
} | ||
|
||
if (newType == ValueType.Int) { | ||
return new IntValue(value ? 1 : 0); | ||
} | ||
|
||
if (newType == ValueType.Float) { | ||
return new FloatValue(value ? 1f : 0f); | ||
} | ||
|
||
if (newType == ValueType.String) { | ||
return new StringValue(value.toString()); | ||
} | ||
|
||
throw BadCastException(newType); | ||
} | ||
|
||
@Override | ||
public boolean isTruthy() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public ValueType getValueType() { | ||
return ValueType.Bool; | ||
} | ||
|
||
public BoolValue() { | ||
this(false); | ||
} | ||
|
||
public BoolValue(boolean boolVal) { | ||
super(boolVal); | ||
} | ||
|
||
@Override | ||
public AbstractValue cast(ValueType newType) throws Exception { | ||
if (newType == getValueType()) { | ||
return this; | ||
} | ||
|
||
if (newType == ValueType.Int) { | ||
return new IntValue(value ? 1 : 0); | ||
} | ||
|
||
if (newType == ValueType.Float) { | ||
return new FloatValue(value ? 1f : 0f); | ||
} | ||
|
||
if (newType == ValueType.String) { | ||
return new StringValue(value.toString()); | ||
} | ||
|
||
throw BadCastException(newType); | ||
} | ||
|
||
@Override | ||
public boolean isTruthy() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public ValueType getValueType() { | ||
return ValueType.Bool; | ||
} | ||
} |
Oops, something went wrong.