Compare commits
No commits in common. "f9f538589f24977a37009a26152a32b4250eec83" and "56930a839d12cd242353341ef9572a1ab3d13f46" have entirely different histories.
f9f538589f
...
56930a839d
6 changed files with 71 additions and 182 deletions
|
@ -1,6 +1,5 @@
|
||||||
package net.pietru.cookie_utils.scripting;
|
package net.pietru.cookie_utils.scripting;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
|
||||||
import net.pietru.cookie_utils.scripting.tokens.*;
|
import net.pietru.cookie_utils.scripting.tokens.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -11,8 +10,6 @@ import java.util.Scanner;
|
||||||
|
|
||||||
public class BaseScript {
|
public class BaseScript {
|
||||||
public static HashMap<String, BaseToken> tokens = new HashMap<>();
|
public static HashMap<String, BaseToken> tokens = new HashMap<>();
|
||||||
public static HashMap<String, Color> colors = new HashMap<>();
|
|
||||||
public static final ExecutionContext dummy = new ExecutionContext(true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,42 +23,6 @@ public class BaseScript {
|
||||||
tokens.put("player", new TokenPlayer());
|
tokens.put("player", new TokenPlayer());
|
||||||
for (String key : TokenMath.valid_tokens)
|
for (String key : TokenMath.valid_tokens)
|
||||||
tokens.put(key, new TokenMath());
|
tokens.put(key, new TokenMath());
|
||||||
|
|
||||||
tokens.put("message", new TokenMessage());
|
|
||||||
|
|
||||||
|
|
||||||
colors.put("light_gray", Color.LIGHT_GRAY);
|
|
||||||
colors.put("gray", Color.GRAY);
|
|
||||||
colors.put("dark_gray", Color.DARK_GRAY);
|
|
||||||
colors.put("black", Color.BLACK);
|
|
||||||
colors.put("blue", Color.BLUE);
|
|
||||||
colors.put("navy", Color.NAVY);
|
|
||||||
colors.put("royal", Color.ROYAL);
|
|
||||||
colors.put("slate", Color.SLATE);
|
|
||||||
colors.put("sky", Color.SKY);
|
|
||||||
colors.put("cyan", Color.CYAN);
|
|
||||||
colors.put("teal", Color.TEAL);
|
|
||||||
colors.put("green", Color.GREEN);
|
|
||||||
colors.put("chartreuse", Color.CHARTREUSE);
|
|
||||||
colors.put("lime", Color.LIME);
|
|
||||||
colors.put("forest", Color.FOREST);
|
|
||||||
colors.put("olive", Color.OLIVE);
|
|
||||||
colors.put("yellow", Color.YELLOW);
|
|
||||||
colors.put("gold", Color.GOLD);
|
|
||||||
colors.put("goldenrod", Color.GOLDENROD);
|
|
||||||
colors.put("orange", Color.ORANGE);
|
|
||||||
colors.put("brown", Color.BROWN);
|
|
||||||
colors.put("tan", Color.TAN);
|
|
||||||
colors.put("firebrick", Color.FIREBRICK);
|
|
||||||
colors.put("red", Color.RED);
|
|
||||||
colors.put("scarlet", Color.SCARLET);
|
|
||||||
colors.put("coral", Color.CORAL);
|
|
||||||
colors.put("salmon", Color.SALMON);
|
|
||||||
colors.put("pink", Color.PINK);
|
|
||||||
colors.put("magenta", Color.MAGENTA);
|
|
||||||
colors.put("purple", Color.PURPLE);
|
|
||||||
colors.put("violet", Color.VIOLET);
|
|
||||||
colors.put("maroon", Color.MAROON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,30 +127,24 @@ public class BaseScript {
|
||||||
public static ArrayList<String> get_string(String[] tokens, int step){
|
public static ArrayList<String> get_string(String[] tokens, int step){
|
||||||
ArrayList<String> text = new ArrayList<>();
|
ArrayList<String> text = new ArrayList<>();
|
||||||
if (tokens[step].startsWith("\"")) {
|
if (tokens[step].startsWith("\"")) {
|
||||||
if (tokens[step].endsWith("\""))
|
text.add(tokens[step]);
|
||||||
text.add(tokens[step].substring(1,tokens[step].length()-1));
|
for (int i = step + 1; i < tokens.length; i++) {
|
||||||
else
|
|
||||||
text.add(tokens[step].substring(1));
|
|
||||||
for (int i = step+1; i < tokens.length; i++) {
|
|
||||||
if (tokens[i].endsWith("\"")){
|
if (tokens[i].endsWith("\"")){
|
||||||
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
text.add(tokens[i]);
|
text.add(tokens[step]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tokens[step].startsWith("'")) {
|
else if (tokens[step].startsWith("'")) {
|
||||||
if (tokens[step].endsWith("'"))
|
|
||||||
text.add(tokens[step].substring(1,tokens[step].length()-1));
|
|
||||||
else
|
|
||||||
text.add(tokens[step].substring(1));
|
text.add(tokens[step].substring(1));
|
||||||
for (int i = step+1; i < tokens.length; i++) {
|
for (int i = step + 1; i < tokens.length; i++) {
|
||||||
if (tokens[i].endsWith("'")) {
|
if (tokens[i].endsWith("'")) {
|
||||||
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
text.add(tokens[i].substring(0,tokens[i].length()-1));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
text.add(tokens[i]);
|
text.add(tokens[step]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -199,33 +154,20 @@ public class BaseScript {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String get_if_variable(String token,ExecutionContext context){
|
public static String get_if_variable(String token,ExecutionContext context){
|
||||||
if (token.startsWith("#") && !context.dummy)
|
if (token.startsWith("#"))
|
||||||
return String.valueOf(context.get_value(token.substring(1)));
|
return String.valueOf(context.get_value(token.substring(1)));
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String,String> get_optional_args(String[] tokens, int step, List<String> valid_args){
|
public static HashMap<String,String> get_optional_args(String[] tokens, int step, List<String> valid_args){
|
||||||
return get_optional_args(tokens, step, valid_args , dummy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HashMap<String,String> get_optional_args(String[] tokens, int step, List<String> valid_args, ExecutionContext context){
|
|
||||||
HashMap<String,String> optional_args = new HashMap<>();
|
HashMap<String,String> optional_args = new HashMap<>();
|
||||||
|
|
||||||
for (int i = step; i < tokens.length-1;) {
|
for (int i = step; i < tokens.length-1; i+=2) {
|
||||||
if (!valid_args.contains(tokens[i])){
|
if (!valid_args.contains(tokens[i])){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ArrayList<String> val = get_string(tokens,i+1);
|
optional_args.put(tokens[i],tokens[i+1]);
|
||||||
optional_args.put(tokens[i],get_if_variable(String.join(" ",val),context));
|
|
||||||
i+=(1+val.size());
|
|
||||||
}
|
}
|
||||||
return optional_args;
|
return optional_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int get_dynamic_tokens(HashMap<String,String> args){
|
|
||||||
int skip = args.size();
|
|
||||||
for (String s : args.values())
|
|
||||||
skip += s.split(" ").length;
|
|
||||||
return skip;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,6 @@ import java.util.Map;
|
||||||
public class ExecutionContext {
|
public class ExecutionContext {
|
||||||
public BaseScript script;
|
public BaseScript script;
|
||||||
public Map<String, Object> variable = new HashMap<>();
|
public Map<String, Object> variable = new HashMap<>();
|
||||||
public final boolean dummy;
|
|
||||||
|
|
||||||
public ExecutionContext(){this.dummy=false;}
|
|
||||||
|
|
||||||
public ExecutionContext(boolean dummy){
|
|
||||||
this.dummy=dummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set_value(String key, Object value){
|
public void set_value(String key, Object value){
|
||||||
variable.remove(key);
|
variable.remove(key);
|
||||||
|
@ -35,8 +28,6 @@ public class ExecutionContext {
|
||||||
|
|
||||||
public void store_player_data(Account account){
|
public void store_player_data(Account account){
|
||||||
variable.put("event_player_id", account.getUniqueId());
|
variable.put("event_player_id", account.getUniqueId());
|
||||||
variable.put("event_player_username", account.getUsername());
|
|
||||||
variable.put("event_player_displayname", account.getDisplayName());
|
|
||||||
Player player = account.getPlayer();
|
Player player = account.getPlayer();
|
||||||
Vector3 pos = player.getPosition();
|
Vector3 pos = player.getPosition();
|
||||||
variable.put("event_player_pos_x", pos.x);
|
variable.put("event_player_pos_x", pos.x);
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
package net.pietru.cookie_utils.scripting.tokens;
|
|
||||||
|
|
||||||
import finalforeach.cosmicreach.GameSingletons;
|
|
||||||
import finalforeach.cosmicreach.entities.player.Player;
|
|
||||||
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
|
||||||
import finalforeach.cosmicreach.networking.packets.ParticleSystemPacket;
|
|
||||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
|
||||||
import finalforeach.cosmicreach.world.Zone;
|
|
||||||
import net.pietru.cookie_utils.scripting.BaseScript;
|
|
||||||
import net.pietru.cookie_utils.scripting.ExecutionContext;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static net.pietru.cookie_utils.utils.player_utils.parseAsPlayer;
|
|
||||||
|
|
||||||
public class TokenMessage implements BaseToken {
|
|
||||||
|
|
||||||
public static final List<String> optional_args = List.of(
|
|
||||||
"player",
|
|
||||||
"zone"
|
|
||||||
);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get_token_checker_id() {
|
|
||||||
return "token_message";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canHandle(String[] tokens, int step) {
|
|
||||||
String token = tokens[step];
|
|
||||||
return token.equals("message") && tokens.length>=step+next_token(tokens,step);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* token_name
|
|
||||||
* message
|
|
||||||
* */
|
|
||||||
@Override
|
|
||||||
public int next_token(String[] tokens, int step) {
|
|
||||||
ArrayList<String> msg_arr = BaseScript.get_string(tokens, step+1);
|
|
||||||
return 1+msg_arr.size()+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
|
||||||
tokens,
|
|
||||||
step+1+msg_arr.size(),
|
|
||||||
optional_args
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(String[] tokens, int step, ExecutionContext executionContext) {
|
|
||||||
String token = tokens[step];
|
|
||||||
if (!token.equals("message"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ArrayList<String> msg_arr = BaseScript.get_string(tokens, step+1);
|
|
||||||
String msg = BaseScript.get_if_variable(String.join(" ", msg_arr),executionContext);
|
|
||||||
|
|
||||||
Map<String,String> args = BaseScript.get_optional_args(
|
|
||||||
tokens,
|
|
||||||
step+1+msg_arr.size(),
|
|
||||||
optional_args,
|
|
||||||
executionContext
|
|
||||||
);
|
|
||||||
|
|
||||||
MessagePacket packet = new MessagePacket(msg);
|
|
||||||
if (args.containsKey("player")) {
|
|
||||||
Player player = parseAsPlayer(BaseScript.get_if_variable(args.get("player"), executionContext));
|
|
||||||
if (player == null) {
|
|
||||||
BaseScript.log_token_error(this, "Failed to parse player.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
packet.setupAndSend(ServerSingletons.getConnection(player));
|
|
||||||
} else {
|
|
||||||
if (args.containsKey("zone")) {
|
|
||||||
String zoneId = BaseScript.get_if_variable(args.get("zone"), executionContext);
|
|
||||||
Zone zone = GameSingletons.world.getZoneIfExists(zoneId);
|
|
||||||
if (zone != null)
|
|
||||||
ServerSingletons.SERVER.broadcast(zone, packet);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (Zone wz : GameSingletons.world.getZones())
|
|
||||||
ServerSingletons.SERVER.broadcast(wz, packet);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -40,7 +40,11 @@ public class TokenParticle implements BaseToken {
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(String[] tokens, int step) {
|
public boolean canHandle(String[] tokens, int step) {
|
||||||
String token = tokens[step];
|
String token = tokens[step];
|
||||||
return token.equals("particle") && tokens.length>=step+next_token(tokens,step);
|
return token.equals("particle") && tokens.length>=step+5+BaseScript.get_optional_args(
|
||||||
|
tokens,
|
||||||
|
step+5,
|
||||||
|
optional_args
|
||||||
|
).size()*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,11 +56,11 @@ public class TokenParticle implements BaseToken {
|
||||||
* */
|
* */
|
||||||
@Override
|
@Override
|
||||||
public int next_token(String[] tokens, int step) {
|
public int next_token(String[] tokens, int step) {
|
||||||
return 5+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
return 5+BaseScript.get_optional_args(
|
||||||
tokens,
|
tokens,
|
||||||
step+5,
|
step+5,
|
||||||
optional_args
|
optional_args
|
||||||
));
|
).size()*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,16 +95,48 @@ public class TokenParticle implements BaseToken {
|
||||||
Map<String,String> args = BaseScript.get_optional_args(
|
Map<String,String> args = BaseScript.get_optional_args(
|
||||||
tokens,
|
tokens,
|
||||||
step+5,
|
step+5,
|
||||||
optional_args,
|
optional_args
|
||||||
executionContext
|
|
||||||
);
|
);
|
||||||
GameParticleSystem system = GameParticleSystem.laserParticleSystem.copy();
|
GameParticleSystem system = GameParticleSystem.laserParticleSystem.copy();
|
||||||
|
|
||||||
String color_key = args.getOrDefault("color","SKY");
|
String color_key = args.getOrDefault("color","SKY");
|
||||||
Color c = new Color();
|
Color c;
|
||||||
if (BaseScript.colors.containsKey(color_key))
|
switch (color_key.toLowerCase()){
|
||||||
c=BaseScript.colors.get(color_key);
|
case "light_gray" -> c = Color.LIGHT_GRAY;
|
||||||
else
|
case "gray" -> c = Color.GRAY;
|
||||||
|
case "dark_gray" -> c = Color.DARK_GRAY;
|
||||||
|
case "black" -> c = Color.BLACK;
|
||||||
|
case "blue" -> c = Color.BLUE;
|
||||||
|
case "navy" -> c = Color.NAVY;
|
||||||
|
case "royal" -> c = Color.ROYAL;
|
||||||
|
case "slate" -> c = Color.SLATE;
|
||||||
|
case "sky" -> c = Color.SKY;
|
||||||
|
case "cyan" -> c = Color.CYAN;
|
||||||
|
case "teal" -> c = Color.TEAL;
|
||||||
|
case "green" -> c = Color.GREEN;
|
||||||
|
case "chartreuse" -> c = Color.CHARTREUSE;
|
||||||
|
case "lime" -> c = Color.LIME;
|
||||||
|
case "forest" -> c = Color.FOREST;
|
||||||
|
case "olive" -> c = Color.OLIVE;
|
||||||
|
case "yellow" -> c = Color.YELLOW;
|
||||||
|
case "gold" -> c = Color.GOLD;
|
||||||
|
case "goldenrod" -> c = Color.GOLDENROD;
|
||||||
|
case "orange" -> c = Color.ORANGE;
|
||||||
|
case "brown" -> c = Color.BROWN;
|
||||||
|
case "tan" -> c = Color.TAN;
|
||||||
|
case "firebrick" -> c = Color.FIREBRICK;
|
||||||
|
case "red" -> c = Color.RED;
|
||||||
|
case "scarlet" -> c = Color.SCARLET;
|
||||||
|
case "coral" -> c = Color.CORAL;
|
||||||
|
case "salmon" -> c = Color.SALMON;
|
||||||
|
case "pink" -> c = Color.PINK;
|
||||||
|
case "magenta" -> c = Color.MAGENTA;
|
||||||
|
case "purple" -> c = Color.PURPLE;
|
||||||
|
case "violet" -> c = Color.VIOLET;
|
||||||
|
case "maroon" -> c = Color.MAROON;
|
||||||
|
default -> c = Color.LIGHT_GRAY;
|
||||||
|
}
|
||||||
|
if (color_key.startsWith("#"))
|
||||||
Color.valueOf(color_key,c);
|
Color.valueOf(color_key,c);
|
||||||
system.startColor.set(c);
|
system.startColor.set(c);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
package net.pietru.cookie_utils.scripting.tokens;
|
package net.pietru.cookie_utils.scripting.tokens;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import finalforeach.cosmicreach.GameSingletons;
|
||||||
import finalforeach.cosmicreach.entities.player.Player;
|
import finalforeach.cosmicreach.entities.player.Player;
|
||||||
|
import finalforeach.cosmicreach.networking.packets.ParticleSystemPacket;
|
||||||
import finalforeach.cosmicreach.networking.packets.entities.MaxHPEntityPacket;
|
import finalforeach.cosmicreach.networking.packets.entities.MaxHPEntityPacket;
|
||||||
|
import finalforeach.cosmicreach.networking.packets.entities.PlayerPositionPacket;
|
||||||
import finalforeach.cosmicreach.networking.server.ServerIdentity;
|
import finalforeach.cosmicreach.networking.server.ServerIdentity;
|
||||||
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
|
import finalforeach.cosmicreach.particles.GameParticleSystem;
|
||||||
|
import finalforeach.cosmicreach.particles.IParticleComponent;
|
||||||
|
import finalforeach.cosmicreach.particles.spawn.GameParticleSpawnSphere;
|
||||||
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
import net.pietru.cookie_utils.scripting.BaseScript;
|
import net.pietru.cookie_utils.scripting.BaseScript;
|
||||||
import net.pietru.cookie_utils.scripting.ExecutionContext;
|
import net.pietru.cookie_utils.scripting.ExecutionContext;
|
||||||
|
import net.pietru.cookie_utils.utils.ParticleUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -30,7 +39,11 @@ public class TokenPlayer implements BaseToken {
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(String[] tokens, int step) {
|
public boolean canHandle(String[] tokens, int step) {
|
||||||
String token = tokens[step];
|
String token = tokens[step];
|
||||||
return token.equals("player") && tokens.length>=step+next_token(tokens,step);
|
return token.equals("player") && tokens.length>=step+2+BaseScript.get_optional_args(
|
||||||
|
tokens,
|
||||||
|
step,
|
||||||
|
optional_args
|
||||||
|
).size()*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +52,11 @@ public class TokenPlayer implements BaseToken {
|
||||||
* */
|
* */
|
||||||
@Override
|
@Override
|
||||||
public int next_token(String[] tokens, int step) {
|
public int next_token(String[] tokens, int step) {
|
||||||
return 2+BaseScript.get_dynamic_tokens(BaseScript.get_optional_args(
|
return 2+BaseScript.get_optional_args(
|
||||||
tokens,
|
tokens,
|
||||||
step+2,
|
step+2,
|
||||||
optional_args
|
optional_args
|
||||||
));
|
).size()*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,8 +76,7 @@ public class TokenPlayer implements BaseToken {
|
||||||
Map<String,String> args = BaseScript.get_optional_args(
|
Map<String,String> args = BaseScript.get_optional_args(
|
||||||
tokens,
|
tokens,
|
||||||
step+2,
|
step+2,
|
||||||
optional_args,
|
optional_args
|
||||||
executionContext
|
|
||||||
);
|
);
|
||||||
if (args.containsKey("velocity_x"))
|
if (args.containsKey("velocity_x"))
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,11 +18,6 @@ public class TokenSet implements BaseToken {
|
||||||
return token.equals("set") && tokens.length>=step+3;
|
return token.equals("set") && tokens.length>=step+3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* token_name
|
|
||||||
* key
|
|
||||||
* value (x)
|
|
||||||
* */
|
|
||||||
@Override
|
@Override
|
||||||
public int next_token(String[] tokens, int step) {
|
public int next_token(String[] tokens, int step) {
|
||||||
return 2+BaseScript.get_string(tokens, step+2).size();
|
return 2+BaseScript.get_string(tokens, step+2).size();
|
||||||
|
|
Loading…
Reference in a new issue