-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
24 changed files
with
611 additions
and
206 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package codex.vfx; | ||
|
||
import java.util.LinkedList; | ||
|
||
/** | ||
* Registry for root vfx objects. | ||
* | ||
* @author codex | ||
*/ | ||
public class VfxRegistry { | ||
|
||
private static final LinkedList<VirtualEffect> effects = new LinkedList<>(); | ||
|
||
public static void register(VirtualEffect effect) { | ||
effects.add(effect); | ||
} | ||
public static void remove(VirtualEffect effect) { | ||
effects.remove(effect); | ||
} | ||
|
||
public static LinkedList<VirtualEffect> getEffects() { | ||
return effects; | ||
} | ||
|
||
public static void play() { | ||
for (VirtualEffect e : effects) { | ||
e.play(); | ||
} | ||
} | ||
public static void pause() { | ||
for (VirtualEffect e : effects) { | ||
e.pause(); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template | ||
*/ | ||
package codex.vfx; | ||
|
||
import codex.vfx.annotations.VfxAttribute; | ||
import codex.vfx.annotations.VfxCommand; | ||
import codex.vfx.annotations.VfxInfo; | ||
|
||
/** | ||
* | ||
* @author codex | ||
*/ | ||
public interface VirtualEffect { | ||
|
||
@VfxCommand(name="play") | ||
public void play(); | ||
|
||
@VfxCommand(name="pause") | ||
public void pause(); | ||
|
||
@VfxAttribute(name="updateSpeed") | ||
public void setUpdateSpeed(float speed); | ||
|
||
@VfxAttribute(name="initialDelay") | ||
public void setInitialDelay(float delay); | ||
|
||
@VfxInfo(name="localPlayState") | ||
public boolean getLocalPlayState(); | ||
|
||
@VfxAttribute(name="updateSpeed", input=false) | ||
public float getUpdateSpeed(); | ||
|
||
@VfxAttribute(name="initialDelay", input=false) | ||
public float getInitialDelay(); | ||
|
||
@VfxInfo(name="worldPlayState") | ||
public boolean getWorldPlayState(); | ||
|
||
@VfxInfo(name="worldUpdateSpeed", important=false) | ||
public float getWorldUpdateSpeed(); | ||
|
||
@VfxInfo(name="worldInitialDelay", important=false) | ||
public float getWorldInitialDelay(); | ||
|
||
@VfxInfo(name="time") | ||
public float getTime(); | ||
|
||
public float getRawTime(); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template | ||
*/ | ||
package codex.vfx.annotations; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* | ||
* @author codex | ||
* @param <T> | ||
*/ | ||
public interface AnnotatedMethodLink <T extends Annotation> { | ||
|
||
public void set(Method method, T annotation); | ||
|
||
public void invokeInput(Object target, Object... arguments); | ||
|
||
public Object invokeOutput(Object target); | ||
|
||
public String getName(); | ||
|
||
public T getInAnnotation(); | ||
|
||
public T getOutAnnotation(); | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package codex.vfx.annotations; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* | ||
* @author codex | ||
*/ | ||
public class AttributeLink implements AnnotatedMethodLink<VfxAttribute> { | ||
|
||
private String name; | ||
private Method input, output; | ||
private VfxAttribute inAttribute, outAttribute; | ||
|
||
@Override | ||
public void set(Method method, VfxAttribute attribute) { | ||
assert method != null && attribute != null : "Parameters cannot be null."; | ||
if (attribute.input()) { | ||
if (input != null) { | ||
throw new IllegalStateException("Duplicate input attribute."); | ||
} | ||
input = method; | ||
inAttribute = attribute; | ||
} else { | ||
if (output != null) { | ||
throw new IllegalStateException("Duplicate output attribute."); | ||
} | ||
output = method; | ||
outAttribute = attribute; | ||
} | ||
if (name != null) { | ||
if (!attribute.name().equals(name)) { | ||
throw new IllegalArgumentException("Attribute names do not match."); | ||
} | ||
} else { | ||
name = attribute.name(); | ||
} | ||
if (isComplete()) { | ||
if (input.getParameterCount() != 1) { | ||
throw new IllegalArgumentException("Expected method accepting exactly one parameter as input."); | ||
} | ||
if (output.getReturnType() == Void.class || output.getParameterCount() == 0) { | ||
throw new IllegalArgumentException("Expected method with no paremeters and a return type as output."); | ||
} | ||
if (!input.getParameterTypes()[1].isAssignableFrom(output.getReturnType())) { | ||
throw new IllegalArgumentException("Return type of output method does not match parameter of input method."); | ||
} | ||
} | ||
} | ||
public void deleteInput() { | ||
input = null; | ||
inAttribute = null; | ||
if (output == null) { | ||
name = null; | ||
} | ||
} | ||
public void deleteOutput() { | ||
output = null; | ||
outAttribute = null; | ||
if (input == null) { | ||
name = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void invokeInput(Object object, Object... arguments) { | ||
try { | ||
input.invoke(object, arguments); | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | ||
throw new RuntimeException("Failed to invoke method: "+input.getName()); | ||
} | ||
} | ||
@Override | ||
public Object invokeOutput(Object object) { | ||
try { | ||
return output.invoke(object); | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | ||
throw new RuntimeException("Failed to invoke method: "+output.getName()); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
public Method getInputMethod() { | ||
return input; | ||
} | ||
public Method getOutputMethod() { | ||
return output; | ||
} | ||
@Override | ||
public VfxAttribute getInAnnotation() { | ||
return inAttribute; | ||
} | ||
@Override | ||
public VfxAttribute getOutAnnotation() { | ||
return outAttribute; | ||
} | ||
public boolean isComplete() { | ||
return input != null && output != null; | ||
} | ||
public Class getType() { | ||
if (output != null) { | ||
return output.getReturnType(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
package codex.vfx.annotations; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* | ||
* @author codex | ||
*/ | ||
public class CommandLink implements AnnotatedMethodLink<VfxCommand> { | ||
|
||
private Method method; | ||
private VfxCommand command; | ||
|
||
@Override | ||
public void set(Method method, VfxCommand command) { | ||
if (this.method != null) { | ||
throw new IllegalStateException("Duplicate commands."); | ||
} | ||
assert method != null && command != null : "Parameters cannot be null."; | ||
this.method = method; | ||
this.command = command; | ||
if (this.method.getParameterCount() != 0) { | ||
throw new IllegalArgumentException("Expected method requiring no parameters."); | ||
} | ||
} | ||
@Override | ||
public void invokeInput(Object object, Object... arguments) { | ||
try { | ||
method.invoke(object); | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | ||
throw new RuntimeException("Failed to invoke method: "+method.getName()); | ||
} | ||
} | ||
@Override | ||
public Object invokeOutput(Object target) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return command != null ? command.name() : null; | ||
} | ||
public Method getMethod() { | ||
return method; | ||
} | ||
@Override | ||
public VfxCommand getInAnnotation() { | ||
return command; | ||
} | ||
@Override | ||
public VfxCommand getOutAnnotation() { | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.