Skip to content

Commit 12d7bb0

Browse files
committed
verified tests are functional
1 parent f70ca96 commit 12d7bb0

24 files changed

+611
-206
lines changed

demo/codex/vfx/demo/MeteorFlameDriver.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/codex/vfx/VfxRegistry.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package codex.vfx;
6+
7+
import java.util.LinkedList;
8+
9+
/**
10+
* Registry for root vfx objects.
11+
*
12+
* @author codex
13+
*/
14+
public class VfxRegistry {
15+
16+
private static final LinkedList<VirtualEffect> effects = new LinkedList<>();
17+
18+
public static void register(VirtualEffect effect) {
19+
effects.add(effect);
20+
}
21+
public static void remove(VirtualEffect effect) {
22+
effects.remove(effect);
23+
}
24+
25+
public static LinkedList<VirtualEffect> getEffects() {
26+
return effects;
27+
}
28+
29+
public static void play() {
30+
for (VirtualEffect e : effects) {
31+
e.play();
32+
}
33+
}
34+
public static void pause() {
35+
for (VirtualEffect e : effects) {
36+
e.pause();
37+
}
38+
}
39+
40+
}

src/codex/vfx/VirtualEffect.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
4+
*/
5+
package codex.vfx;
6+
7+
import codex.vfx.annotations.VfxAttribute;
8+
import codex.vfx.annotations.VfxCommand;
9+
import codex.vfx.annotations.VfxInfo;
10+
11+
/**
12+
*
13+
* @author codex
14+
*/
15+
public interface VirtualEffect {
16+
17+
@VfxCommand(name="play")
18+
public void play();
19+
20+
@VfxCommand(name="pause")
21+
public void pause();
22+
23+
@VfxAttribute(name="updateSpeed")
24+
public void setUpdateSpeed(float speed);
25+
26+
@VfxAttribute(name="initialDelay")
27+
public void setInitialDelay(float delay);
28+
29+
@VfxInfo(name="localPlayState")
30+
public boolean getLocalPlayState();
31+
32+
@VfxAttribute(name="updateSpeed", input=false)
33+
public float getUpdateSpeed();
34+
35+
@VfxAttribute(name="initialDelay", input=false)
36+
public float getInitialDelay();
37+
38+
@VfxInfo(name="worldPlayState")
39+
public boolean getWorldPlayState();
40+
41+
@VfxInfo(name="worldUpdateSpeed", important=false)
42+
public float getWorldUpdateSpeed();
43+
44+
@VfxInfo(name="worldInitialDelay", important=false)
45+
public float getWorldInitialDelay();
46+
47+
@VfxInfo(name="time")
48+
public float getTime();
49+
50+
public float getRawTime();
51+
52+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
4+
*/
5+
package codex.vfx.annotations;
6+
7+
import java.lang.annotation.Annotation;
8+
import java.lang.reflect.Method;
9+
10+
/**
11+
*
12+
* @author codex
13+
* @param <T>
14+
*/
15+
public interface AnnotatedMethodLink <T extends Annotation> {
16+
17+
public void set(Method method, T annotation);
18+
19+
public void invokeInput(Object target, Object... arguments);
20+
21+
public Object invokeOutput(Object target);
22+
23+
public String getName();
24+
25+
public T getInAnnotation();
26+
27+
public T getOutAnnotation();
28+
29+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package codex.vfx.annotations;
6+
7+
import java.lang.reflect.InvocationTargetException;
8+
import java.lang.reflect.Method;
9+
10+
/**
11+
*
12+
* @author codex
13+
*/
14+
public class AttributeLink implements AnnotatedMethodLink<VfxAttribute> {
15+
16+
private String name;
17+
private Method input, output;
18+
private VfxAttribute inAttribute, outAttribute;
19+
20+
@Override
21+
public void set(Method method, VfxAttribute attribute) {
22+
assert method != null && attribute != null : "Parameters cannot be null.";
23+
if (attribute.input()) {
24+
if (input != null) {
25+
throw new IllegalStateException("Duplicate input attribute.");
26+
}
27+
input = method;
28+
inAttribute = attribute;
29+
} else {
30+
if (output != null) {
31+
throw new IllegalStateException("Duplicate output attribute.");
32+
}
33+
output = method;
34+
outAttribute = attribute;
35+
}
36+
if (name != null) {
37+
if (!attribute.name().equals(name)) {
38+
throw new IllegalArgumentException("Attribute names do not match.");
39+
}
40+
} else {
41+
name = attribute.name();
42+
}
43+
if (isComplete()) {
44+
if (input.getParameterCount() != 1) {
45+
throw new IllegalArgumentException("Expected method accepting exactly one parameter as input.");
46+
}
47+
if (output.getReturnType() == Void.class || output.getParameterCount() == 0) {
48+
throw new IllegalArgumentException("Expected method with no paremeters and a return type as output.");
49+
}
50+
if (!input.getParameterTypes()[1].isAssignableFrom(output.getReturnType())) {
51+
throw new IllegalArgumentException("Return type of output method does not match parameter of input method.");
52+
}
53+
}
54+
}
55+
public void deleteInput() {
56+
input = null;
57+
inAttribute = null;
58+
if (output == null) {
59+
name = null;
60+
}
61+
}
62+
public void deleteOutput() {
63+
output = null;
64+
outAttribute = null;
65+
if (input == null) {
66+
name = null;
67+
}
68+
}
69+
70+
@Override
71+
public void invokeInput(Object object, Object... arguments) {
72+
try {
73+
input.invoke(object, arguments);
74+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
75+
throw new RuntimeException("Failed to invoke method: "+input.getName());
76+
}
77+
}
78+
@Override
79+
public Object invokeOutput(Object object) {
80+
try {
81+
return output.invoke(object);
82+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
83+
throw new RuntimeException("Failed to invoke method: "+output.getName());
84+
}
85+
}
86+
87+
@Override
88+
public String getName() {
89+
return name;
90+
}
91+
public Method getInputMethod() {
92+
return input;
93+
}
94+
public Method getOutputMethod() {
95+
return output;
96+
}
97+
@Override
98+
public VfxAttribute getInAnnotation() {
99+
return inAttribute;
100+
}
101+
@Override
102+
public VfxAttribute getOutAnnotation() {
103+
return outAttribute;
104+
}
105+
public boolean isComplete() {
106+
return input != null && output != null;
107+
}
108+
public Class getType() {
109+
if (output != null) {
110+
return output.getReturnType();
111+
} else {
112+
return null;
113+
}
114+
}
115+
116+
}

src/codex/vfx/VfxAttribute.java renamed to src/codex/vfx/annotations/ChildTraverse.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
33
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
44
*/
5-
package codex.vfx;
5+
package codex.vfx.annotations;
66

77
import java.lang.annotation.Documented;
88
import java.lang.annotation.Retention;
99
import java.lang.annotation.RetentionPolicy;
1010

1111
/**
12-
*
12+
* Marks a method that returns a configurable object.
13+
*
1314
* @author codex
1415
*/
1516
@Retention(RetentionPolicy.RUNTIME)
1617
@Documented
17-
public @interface VfxAttribute {
18-
String value();
19-
boolean lookupDefault() default true;
18+
public @interface ChildTraverse {
19+
20+
21+
2022
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
package codex.vfx.annotations;
6+
7+
import java.lang.reflect.InvocationTargetException;
8+
import java.lang.reflect.Method;
9+
import java.util.logging.Level;
10+
import java.util.logging.Logger;
11+
12+
/**
13+
*
14+
* @author codex
15+
*/
16+
public class CommandLink implements AnnotatedMethodLink<VfxCommand> {
17+
18+
private Method method;
19+
private VfxCommand command;
20+
21+
@Override
22+
public void set(Method method, VfxCommand command) {
23+
if (this.method != null) {
24+
throw new IllegalStateException("Duplicate commands.");
25+
}
26+
assert method != null && command != null : "Parameters cannot be null.";
27+
this.method = method;
28+
this.command = command;
29+
if (this.method.getParameterCount() != 0) {
30+
throw new IllegalArgumentException("Expected method requiring no parameters.");
31+
}
32+
}
33+
@Override
34+
public void invokeInput(Object object, Object... arguments) {
35+
try {
36+
method.invoke(object);
37+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
38+
throw new RuntimeException("Failed to invoke method: "+method.getName());
39+
}
40+
}
41+
@Override
42+
public Object invokeOutput(Object target) {
43+
return null;
44+
}
45+
46+
@Override
47+
public String getName() {
48+
return command != null ? command.name() : null;
49+
}
50+
public Method getMethod() {
51+
return method;
52+
}
53+
@Override
54+
public VfxCommand getInAnnotation() {
55+
return command;
56+
}
57+
@Override
58+
public VfxCommand getOutAnnotation() {
59+
return null;
60+
}
61+
62+
}

0 commit comments

Comments
 (0)