Skip to content

Commit

Permalink
verified tests are functional
Browse files Browse the repository at this point in the history
  • Loading branch information
codex128 committed Dec 25, 2023
1 parent f70ca96 commit 12d7bb0
Show file tree
Hide file tree
Showing 24 changed files with 611 additions and 206 deletions.
61 changes: 0 additions & 61 deletions demo/codex/vfx/demo/MeteorFlameDriver.java

This file was deleted.

40 changes: 40 additions & 0 deletions src/codex/vfx/VfxRegistry.java
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();
}
}

}
52 changes: 52 additions & 0 deletions src/codex/vfx/VirtualEffect.java
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();

}
29 changes: 29 additions & 0 deletions src/codex/vfx/annotations/AnnotatedMethodLink.java
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();

}
116 changes: 116 additions & 0 deletions src/codex/vfx/annotations/AttributeLink.java
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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
* 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;
package codex.vfx.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
*
* Marks a method that returns a configurable object.
*
* @author codex
*/
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface VfxAttribute {
String value();
boolean lookupDefault() default true;
public @interface ChildTraverse {



}
62 changes: 62 additions & 0 deletions src/codex/vfx/annotations/CommandLink.java
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;
}

}
Loading

0 comments on commit 12d7bb0

Please sign in to comment.