mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 08:36:38 +00:00
Fix bad casting exceptions with scene garbages objects
This commit is contained in:
parent
3feb98f08b
commit
5f8cc47e87
@ -599,6 +599,7 @@ public class Scene {
|
||||
.map(g -> scriptManager.createGadget(group.id, group.block_id, g)).toList());
|
||||
entities.addAll(suiteData.sceneMonsters.stream()
|
||||
.map(mob -> scriptManager.createMonster(group.id, group.block_id, mob)).toList());
|
||||
|
||||
suite++;
|
||||
} while (suite < group.init_config.end_suite);
|
||||
}
|
||||
|
@ -164,7 +164,10 @@ public class SceneScriptManager {
|
||||
public void loadGroupFromScript(SceneGroup group) {
|
||||
group.load(getScene().getId());
|
||||
|
||||
if (group.variables != null) {
|
||||
group.variables.forEach(var -> this.getVariables().put(var.name, var.value));
|
||||
}
|
||||
|
||||
this.sceneGroups.put(group.id, group);
|
||||
|
||||
if(group.regions != null){
|
||||
|
28
src/main/java/emu/grasscutter/scripts/ScriptUtils.java
Normal file
28
src/main/java/emu/grasscutter/scripts/ScriptUtils.java
Normal file
@ -0,0 +1,28 @@
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
|
||||
public class ScriptUtils {
|
||||
|
||||
public static HashMap<Object, Object> toMap(LuaTable table) {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
LuaValue[] rootKeys = table.keys();
|
||||
for (LuaValue k : rootKeys) {
|
||||
if (table.get(k).istable()) {
|
||||
map.put(k, toMap(table.get(k).checktable()));
|
||||
} else {
|
||||
map.put(k, table.get(k));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void print(LuaTable table) {
|
||||
Grasscutter.getLogger().info(toMap(table).toString());
|
||||
}
|
||||
}
|
@ -9,6 +9,10 @@ import lombok.ToString;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -106,9 +110,17 @@ public class SceneGroup {
|
||||
|
||||
suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
|
||||
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions"));
|
||||
garbages = ScriptLoader.getSerializer().toObject(SceneGarbage.class, bindings.get("garbages"));
|
||||
init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
|
||||
|
||||
// Garbages TODO fix properly later
|
||||
Object garbagesValue = bindings.get("garbages");
|
||||
if (garbagesValue != null && garbagesValue instanceof LuaValue garbagesTable) {
|
||||
garbages = new SceneGarbage();
|
||||
if (garbagesTable.checktable().get("gadgets") != LuaValue.NIL) {
|
||||
garbages.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, garbagesTable.checktable().get("gadgets").checktable());
|
||||
}
|
||||
}
|
||||
|
||||
// Add variables to suite
|
||||
variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
|
||||
|
||||
|
@ -2,6 +2,9 @@ package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import com.esotericsoftware.reflectasm.ConstructorAccess;
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.scripts.ScriptUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@ -9,6 +12,8 @@ import lombok.experimental.FieldDefaults;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -31,6 +36,10 @@ public class LuaSerializer implements Serializer {
|
||||
public <T> List<T> serializeList(Class<T> type, LuaTable table) {
|
||||
List<T> list = new ArrayList<>();
|
||||
|
||||
if (table == null) {
|
||||
return list;
|
||||
}
|
||||
|
||||
try {
|
||||
LuaValue[] keys = table.keys();
|
||||
for (LuaValue k : keys) {
|
||||
@ -90,6 +99,7 @@ public class LuaSerializer implements Serializer {
|
||||
if (table == null) {
|
||||
return object;
|
||||
}
|
||||
|
||||
LuaValue[] keys = table.keys();
|
||||
for (LuaValue k : keys) {
|
||||
try {
|
||||
@ -117,6 +127,7 @@ public class LuaSerializer implements Serializer {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().info(ScriptUtils.toMap(table).toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user