260 lines
4.7 KiB
Java
260 lines
4.7 KiB
Java
package org.hwo.pulscounter.simplescript;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.UUID;
|
|
|
|
import org.hwo.models.TableMapper.TableColumn;
|
|
|
|
public class SimpleScript {
|
|
|
|
private UUID id;
|
|
private String name;
|
|
private String description;
|
|
private ArrayList<SimpleScriptElement> simpleScriptElements;
|
|
|
|
public SimpleScript(){
|
|
id = UUID.randomUUID();
|
|
name = "";
|
|
description = "";
|
|
simpleScriptElements = new ArrayList<>();
|
|
}
|
|
|
|
public SimpleScript(String name,String description,SimpleScriptElement elements[]){
|
|
this.id = UUID.randomUUID();
|
|
this.name = name;
|
|
this.description = description;
|
|
this.simpleScriptElements = new ArrayList<>();
|
|
this.simpleScriptElements.addAll(Arrays.asList(elements));
|
|
}
|
|
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public ArrayList<SimpleScriptElement> getSimpleScriptElements() {
|
|
return simpleScriptElements;
|
|
}
|
|
|
|
|
|
|
|
public enum ScriptOperation {
|
|
|
|
SET_ZERO (0x00),
|
|
SET_ONE (0x01),
|
|
SET_A (0x02),
|
|
SET_B (0x03),
|
|
A_PLUS_B (0x04),
|
|
A_MINUS_B (0x05),
|
|
A_MUL_B (0x06),
|
|
A_DIV_B (0x07),
|
|
A_AND_B (0x08),
|
|
A_OR_B (0x09),
|
|
A_XOR_B (0x0A),
|
|
/* 0x0b..0x0f: frei */
|
|
SET_NOT_A (0x10),
|
|
SET_NOT_B (0x11)
|
|
/* 0x12..0x1f: frei */
|
|
;
|
|
|
|
ScriptOperation(int n){
|
|
this.n = n;
|
|
}
|
|
|
|
static ScriptOperation operations[] = {
|
|
SET_ZERO, // 0x00
|
|
SET_ONE,
|
|
SET_A,
|
|
SET_B,
|
|
A_PLUS_B, // 0x04
|
|
A_MINUS_B,
|
|
A_MUL_B,
|
|
A_DIV_B,
|
|
A_AND_B, // 0x08
|
|
A_OR_B,
|
|
A_XOR_B,
|
|
null,
|
|
null, // 0x0c
|
|
null,
|
|
null,
|
|
null,
|
|
SET_NOT_A, // 0x10
|
|
SET_NOT_B,
|
|
null,
|
|
null,
|
|
null, // 0x14
|
|
null,
|
|
null,
|
|
null,
|
|
null, // 0x18
|
|
null,
|
|
null,
|
|
null,
|
|
null, // 0x1C
|
|
null,
|
|
null,
|
|
null
|
|
};
|
|
|
|
public static ScriptOperation get(int code){
|
|
return operations[code];
|
|
}
|
|
|
|
int n;
|
|
|
|
public int getCode(){
|
|
return this.n;
|
|
}
|
|
|
|
}
|
|
|
|
public enum ScriptCondition {
|
|
NEVER (0x00),
|
|
ALWAYS (0x01),
|
|
A_EQ_ZERO (0x02),
|
|
A_NEQ_ZERO (0x03),
|
|
A_EQ_B (0x04),
|
|
A_NEQ_B (0x05),
|
|
A_LT_B (0x06),
|
|
A_GT_B (0x07)
|
|
;
|
|
|
|
static ScriptCondition scriptConditions[] = {
|
|
NEVER,
|
|
ALWAYS,
|
|
A_EQ_ZERO,
|
|
A_NEQ_ZERO,
|
|
A_EQ_B,
|
|
A_NEQ_B,
|
|
A_LT_B,
|
|
A_GT_B
|
|
};
|
|
|
|
static ScriptCondition get(int code){
|
|
return scriptConditions[code];
|
|
}
|
|
|
|
private int code;
|
|
|
|
ScriptCondition(int code){
|
|
this.code = code;
|
|
}
|
|
|
|
public int getCode(){
|
|
return this.code;
|
|
}
|
|
}
|
|
|
|
public static class SimpleScriptElement{
|
|
private int code;
|
|
|
|
public SimpleScriptElement(){
|
|
code = 0;
|
|
}
|
|
public SimpleScriptElement(int code){
|
|
this.code = code;
|
|
}
|
|
|
|
public SimpleScriptElement(int a,int b,int z,ScriptCondition scriptCondition,ScriptOperation scriptOperation){
|
|
setA(a);
|
|
setB(b);
|
|
setZ(z);
|
|
setScriptCondition(scriptCondition);
|
|
setScriptOperation(scriptOperation);
|
|
}
|
|
|
|
public int getCode() {
|
|
return code;
|
|
}
|
|
public void setCode(int code) {
|
|
this.code = code;
|
|
}
|
|
|
|
@TableColumn(label="A",order=0)
|
|
public int getA(){
|
|
return code & 0xff;
|
|
}
|
|
|
|
@TableColumn(label="B",order=10)
|
|
public int getB(){
|
|
return (code >> 8) & 0xff;
|
|
}
|
|
|
|
@TableColumn(label="Z",order=90)
|
|
public int getZ(){
|
|
return (code >> 16) & 0xff;
|
|
}
|
|
|
|
public int getCondition(){
|
|
return (code >> 24) & 0xff;
|
|
}
|
|
public int getOperation(){
|
|
return (code >> 27) & 0xff;
|
|
}
|
|
|
|
public void setA(int a){
|
|
code &= ~0xff;
|
|
code |= a & 0xff;
|
|
}
|
|
public void setB(int b){
|
|
code &= ~( 0xff << 8 );
|
|
code |= (b & 0xff) << 8;
|
|
}
|
|
public void setZ(int z){
|
|
code &= ~( 0xff << 16 );
|
|
code |= (z & 0xff) << 16;
|
|
}
|
|
public void setCondition(int condition){
|
|
code &= ~( 0x07 << 24 );
|
|
code |= (condition & 0x07) << 24;
|
|
}
|
|
public void setOperation(int operation){
|
|
code &= ~( 0x1f << 27 );
|
|
code |= (operation & 0x1F) << 27;
|
|
}
|
|
|
|
@TableColumn(label="Operation",order=50)
|
|
ScriptOperation getScriptOperation(){
|
|
return ScriptOperation.get(getOperation());
|
|
}
|
|
public void setScriptOperation(ScriptOperation scriptOperation){
|
|
if (scriptOperation == null){
|
|
setOperation(0);
|
|
} else {
|
|
setOperation(scriptOperation.getCode());
|
|
}
|
|
}
|
|
|
|
@TableColumn(label="Bedingung",order=40)
|
|
public ScriptCondition getScriptCondition(){
|
|
return ScriptCondition.get(getCondition());
|
|
}
|
|
public void setScriptCondition(ScriptCondition scriptCondition){
|
|
if (scriptCondition == null){
|
|
setCondition(0);
|
|
} else {
|
|
setCondition(scriptCondition.getCode());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|