-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
// required: client
option for scripts, rewrote keybind event…
…s, fixed some PR issues
- Loading branch information
1 parent
0a700f6
commit 9205ad7
Showing
15 changed files
with
274 additions
and
145 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/dev/latvian/mods/kubejs/bindings/GLFWInputWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dev.latvian.mods.kubejs.bindings; | ||
|
||
import dev.latvian.mods.kubejs.util.Lazy; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public interface GLFWInputWrapper { | ||
Lazy<Map<String, Integer>> MAP = Lazy.of(() -> { | ||
var map = new HashMap<String, Integer>(); | ||
|
||
try { | ||
for (var field : GLFW.class.getDeclaredFields()) { | ||
int mod = field.getModifiers(); | ||
|
||
if (field.getType() == int.class && Modifier.isPublic(mod) && Modifier.isStatic(mod) && Modifier.isFinal(mod)) { | ||
var n = field.getName(); | ||
|
||
if (n.startsWith("GLFW_KEY_") || n.startsWith("GLFW_MOUSE_") || n.startsWith("GLFW_GAMEPAD_") || n.startsWith("GLFW_CURSOR_")) { | ||
map.put(n.substring(5), field.getInt(null)); | ||
} | ||
} | ||
} | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
|
||
return Map.copyOf(map); | ||
}); | ||
|
||
static int get(String name) { | ||
return MAP.get().getOrDefault(name, -1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/latvian/mods/kubejs/bindings/event/KeyBindEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.latvian.mods.kubejs.bindings.event; | ||
|
||
import dev.latvian.mods.kubejs.client.KeybindRegistryKubeEvent; | ||
import dev.latvian.mods.kubejs.client.KubeJSKeybinds; | ||
import dev.latvian.mods.kubejs.event.EventGroup; | ||
import dev.latvian.mods.kubejs.event.EventHandler; | ||
import dev.latvian.mods.kubejs.event.TargetedEventHandler; | ||
|
||
public interface KeyBindEvents { | ||
EventGroup GROUP = EventGroup.of("KeyBindEvents"); | ||
|
||
EventHandler REGISTRY = GROUP.startup("registry", () -> KeybindRegistryKubeEvent.class); | ||
TargetedEventHandler<KubeJSKeybinds.KubeKey> PRESSED = GROUP.client("pressed", () -> KubeJSKeybinds.KeyEvent.class).requiredTarget(KubeJSKeybinds.TARGET); | ||
TargetedEventHandler<KubeJSKeybinds.KubeKey> RELEASED = GROUP.client("released", () -> KubeJSKeybinds.TickingKeyEvent.class).requiredTarget(KubeJSKeybinds.TARGET); | ||
TargetedEventHandler<KubeJSKeybinds.KubeKey> TICK = GROUP.client("tick", () -> KubeJSKeybinds.TickingKeyEvent.class).requiredTarget(KubeJSKeybinds.TARGET); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.