Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
1ed46df6
Commit
1ed46df6
authored
Apr 29, 2022
by
Melledy
Browse files
Move script constants to globals
parent
3f76ac4c
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
1ed46df6
package
emu.grasscutter.scripts
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -23,6 +24,7 @@ import emu.grasscutter.data.def.WorldLevelData;
import
emu.grasscutter.game.entity.EntityGadget
;
import
emu.grasscutter.game.entity.EntityMonster
;
import
emu.grasscutter.game.entity.GameEntity
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.scripts.constants.EventType
;
import
emu.grasscutter.scripts.constants.ScriptGadgetState
;
...
...
@@ -134,9 +136,6 @@ public class SceneScriptManager {
bindings
=
ScriptLoader
.
getEngine
().
createBindings
();
// Set variables
bindings
.
put
(
"EventType"
,
new
EventType
());
// TODO - make static class to avoid instantiating a new class every scene
bindings
.
put
(
"GadgetState"
,
new
ScriptGadgetState
());
bindings
.
put
(
"RegionShape"
,
new
ScriptRegionShape
());
bindings
.
put
(
"ScriptLib"
,
getScriptLib
());
// Eval script
...
...
src/main/java/emu/grasscutter/scripts/ScriptLoader.java
View file @
1ed46df6
...
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -13,11 +14,17 @@ import javax.script.ScriptEngine;
import
javax.script.ScriptEngineFactory
;
import
javax.script.ScriptEngineManager
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaValue
;
import
org.luaj.vm2.lib.OneArgFunction
;
import
org.luaj.vm2.lib.jse.CoerceJavaToLua
;
import
org.luaj.vm2.script.LuajContext
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.props.EntityType
;
import
emu.grasscutter.scripts.constants.EventType
;
import
emu.grasscutter.scripts.constants.ScriptGadgetState
;
import
emu.grasscutter.scripts.constants.ScriptRegionShape
;
import
emu.grasscutter.scripts.serializer.LuaSerializer
;
import
emu.grasscutter.scripts.serializer.Serializer
;
...
...
@@ -52,6 +59,14 @@ public class ScriptLoader {
return
LuaValue
.
ZERO
;
}
});
LuaTable
table
=
new
LuaTable
();
Arrays
.
stream
(
EntityType
.
values
()).
forEach
(
e
->
table
.
set
(
e
.
name
().
toUpperCase
(),
e
.
getValue
()));
ctx
.
globals
.
set
(
"EntityType"
,
table
);
ctx
.
globals
.
set
(
"EventType"
,
CoerceJavaToLua
.
coerce
(
new
EventType
()));
// TODO - make static class to avoid instantiating a new class every scene
ctx
.
globals
.
set
(
"GadgetState"
,
CoerceJavaToLua
.
coerce
(
new
ScriptGadgetState
()));
ctx
.
globals
.
set
(
"RegionShape"
,
CoerceJavaToLua
.
coerce
(
new
ScriptRegionShape
()));
}
public
static
ScriptEngine
getEngine
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment