Skip to content

Commit

Permalink
ANIMATION_RELATIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed May 27, 2024
1 parent e6fb5fa commit 3d67038
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DreamList(DreamObjectDefinition listDef, int size) : base(listDef) {
/// <summary>
/// Create a new DreamList using an existing list of values (does not copy them)
/// </summary>
private DreamList(DreamObjectDefinition listDef, List<DreamValue> values, Dictionary<DreamValue, DreamValue>? associativeValues) : base(listDef) {
public DreamList(DreamObjectDefinition listDef, List<DreamValue> values, Dictionary<DreamValue, DreamValue>? associativeValues) : base(listDef) {
_values = values;
_associativeValues = associativeValues;
}
Expand Down
52 changes: 52 additions & 0 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,58 @@ public static DreamValue NativeProc_animate(NativeProc.Bundle bundle, DreamObjec
var invisibility = bundle.GetArgument(24, "invisibility");
var suffix = bundle.GetArgument(25, "suffix");

if((flags & AnimationFlags.AnimationRelative) != 0){
// This works for maptext_x/y/width/height, pixel_x/y/w/z, luminosity, layer, alpha, transform, and color. For transform and color, the current value is multiplied by the new one. Vars not in this list are simply changed as if this flag is not present.
if(!pixelX.IsNull)
pixelX = new(pixelX.UnsafeGetValueAsFloat() + obj.GetVariable("pixel_x").UnsafeGetValueAsFloat());
if(!pixelY.IsNull)
pixelY = new(pixelY.UnsafeGetValueAsFloat() + obj.GetVariable("pixel_y").UnsafeGetValueAsFloat());
if(!pixelZ.IsNull)
pixelZ = new(pixelZ.UnsafeGetValueAsFloat() + obj.GetVariable("pixel_z").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!maptextWidth.IsNull)
maptextWidth = new(maptextWidth.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_width").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!maptextHeight.IsNull)
maptextHeight = new(maptextHeight.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_height").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!maptextX.IsNull)
maptextX = new(maptextX.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_x").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!maptextY.IsNull)
maptextY = new(maptextY.UnsafeGetValueAsFloat() + obj.GetVariable("maptext_y").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!luminosity.IsNull)
luminosity = new(luminosity.UnsafeGetValueAsFloat() + obj.GetVariable("luminosity").UnsafeGetValueAsFloat());

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
if(!layer.IsNull)
layer = new(layer.UnsafeGetValueAsFloat() + obj.GetVariable("layer").UnsafeGetValueAsFloat());
if(!alpha.IsNull)
alpha = new(alpha.UnsafeGetValueAsFloat() + obj.GetVariable("alpha").UnsafeGetValueAsFloat());
if(!transform.IsNull) {
if(transform.TryGetValueAsDreamObject<DreamObjectMatrix>(out var transformObj) && obj.GetVariable("transform").TryGetValueAsDreamObject<DreamObjectMatrix>(out var objTransform)){

Check warning

Code scanning / InspectCode

Unused local variable Warning

Local variable 'transformObj' is never used
transform = objTransform.OperatorMultiply(transform);
}
}
if(!color.IsNull) {
ColorMatrix cMatrix;
if(color.TryGetValueAsString(out var colorStr) && Color.TryParse(colorStr, out var colorObj)){
cMatrix = new ColorMatrix(colorObj);
} else if (color.TryGetValueAsDreamList(out var colorList) && DreamProcNativeHelpers.TryParseColorMatrix(colorList, out cMatrix)){
//parsed as colormatrix
} else {
cMatrix = ColorMatrix.Identity; //fallback to identity if invalid
}
ColorMatrix objCMatrix;
DreamValue objColor = obj.GetVariable("color");
if(objColor.TryGetValueAsString(out var objColorStr) && Color.TryParse(objColorStr, out var objColorObj)){
objCMatrix = new ColorMatrix(objColorObj);
} else if (objColor.TryGetValueAsDreamList(out var objColorList) && DreamProcNativeHelpers.TryParseColorMatrix(objColorList, out objCMatrix)){
//parsed as colormatrix
} else {
objCMatrix = ColorMatrix.Identity; //fallback to identity if invalid
}
ColorMatrix.Multiply(ref objCMatrix, ref cMatrix, out var resultMatrix);
color = new DreamValue(new DreamList(bundle.ObjectTree.List.ObjectDefinition, resultMatrix.GetValues().Select(x => new DreamValue(x)).ToList(), null));
}


}

bundle.AtomManager.AnimateAppearance(obj, TimeSpan.FromMilliseconds(time * 100), (AnimationEasing)easing, loop, flags, delay, chainAnim,
appearance => {
if (!pixelX.IsNull) {
Expand Down
17 changes: 15 additions & 2 deletions TestGame/renderer_tests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,21 @@
animate(transform = matrix(), time = 5, easing=SINE_EASING)
animate(transform = matrix()*2, time = 5, easing=CIRCULAR_EASING)
animate(transform = matrix(), time = 5, easing=JUMP_EASING)
i++
if(i>5)
if(i==6)
usr << "relative color"
animate(usr, color="#ff0000", time=5, flags=ANIMATION_RELATIVE)
animate(color="#00ff00", time=5, flags=ANIMATION_RELATIVE)
animate(color="#0000ff", time=5, flags=ANIMATION_RELATIVE)
if(i==7)
usr << "relative transform"
animate(usr, transform = matrix()*2, time = 5, flags=ANIMATION_RELATIVE)
animate(transform = matrix()*0.5, time = 5, flags=ANIMATION_RELATIVE)
if(i==8)
usr << "more relative tests"
animate(usr, alpha=-125, pixel_x=16, time = 5, flags=ANIMATION_RELATIVE)
animate(alpha=125, pixel_x=-16, time = 5, flags=ANIMATION_RELATIVE)
i++;
if(i>8)
i = 0
/obj/plaque/animation_test
data = "<h3>Animation Test</h3><p>Click the button to apply a series of animations to your mob</p>"
Expand Down

0 comments on commit 3d67038

Please sign in to comment.