Skip to content
Permalink
Browse files

Fix errors with KeyCombination access from JS

  • Loading branch information...
iAmGio committed Jul 11, 2019
1 parent 0e0769c commit 76e02c5c7929f3a6e2c62fc00b7620472ec13638
Showing with 31 additions and 30 deletions.
  1. +30 −29 src/assets/js/lib.js
  2. +1 −1 src/org/chorusmc/chorus/addon/Addons.kt
@@ -438,34 +438,6 @@ function File(name, parent) {
return new java.io.File(parent, name);
}

/**
* @param key main key
* @param modifiers array of modifiers (shift, control, alt)
* @return fx.scene.input.KeyCodeCombination
*/
function KeyCombination(key, modifiers) {
var KeyCodeCombination = fx.scene.input.KeyCodeCombination;
var KeyCombination = fx.scene.input.KeyCombination;
var keyCode = fx.scene.input.KeyCode.valueOf(key.toUpperCase());

if(modifiers && !Array.isArray(modifiers)) modifiers = [modifiers]

var keyModifiers = [];

if(modifiers) {
for (i = 0; i < modifiers.length; i++) {
var modifier = modifiers[i].toLowerCase();
keyModifiers.push(
modifier == 'shift' ? KeyCombination.SHIFT_DOWN :
modifier == 'control' || modifier == 'ctrl' ? KeyCombination.CONTROL_DOWN :
modifier == 'alt' ? KeyCombination.ALT_DOWN : null
);
}
}

return new KeyCodeCombination(keyCode, keyModifiers)
}

/**
* Instantiates a Chorus' colored-text parser
* @param string text to parse
@@ -527,4 +499,33 @@ function ImageView(image) {
}

var Alignment = javafx.geometry.Pos;
var TextAlignment = fx.text.TextAlignment;
var TextAlignment = fx.text.TextAlignment;


/**
* @param key main key
* @param modifiers array of modifiers (shift, control, alt)
* @return fx.scene.input.KeyCodeCombination
*/
function KeyCombination(key, modifiers) {
var KeyCodeCombination = fx.input.KeyCodeCombination;
var KeyCombination = fx.input.KeyCombination;
var keyCode = fx.input.KeyCode.valueOf(key.toUpperCase());

if(modifiers && !Array.isArray(modifiers)) modifiers = [modifiers]

var keyModifiers = [];

if(modifiers) {
for (i = 0; i < modifiers.length; i++) {
var modifier = modifiers[i].toLowerCase();
keyModifiers.push(
modifier == 'shift' ? KeyCombination.SHIFT_DOWN :
modifier == 'control' || modifier == 'ctrl' ? KeyCombination.CONTROL_DOWN :
modifier == 'alt' ? KeyCombination.ALT_DOWN : null
);
}
}

return new KeyCodeCombination(keyCode, keyModifiers)
}
@@ -24,7 +24,7 @@ object Addons {

fun invoke(func: String, vararg args: Any) {
addons.forEach {
scriptEngine?.invoke(it, func, args)
scriptEngine?.invoke(it, func, *args)
}
}

0 comments on commit 76e02c5

Please sign in to comment.
You can’t perform that action at this time.