Skip to content

Commit

Permalink
Merge commit '431da081b0546a441cbc464d6cb55056e07cb827' into dev-1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Sep 21, 2023
2 parents 2ee4e00 + 431da08 commit d3e45c5
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 207 deletions.
2 changes: 1 addition & 1 deletion app/assets/css/app.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5319,6 +5319,7 @@ canvas#webgl {
#permanentNotifications {
width: 100vw;
left: 0;
z-index: 0;
}

&:not(.revealed) {
Expand Down
76 changes: 76 additions & 0 deletions src/electron.renderer/App.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class App extends dn.Process {
var requestedCpuEndTime = 0.;
public var pendingUpdate : Null<{ ver:String, github:Bool }>;

public var keyBindings : Array<KeyBinding> = [];

public function new() {
super();

Expand Down Expand Up @@ -178,6 +180,80 @@ class App extends dn.Process {
IpcRenderer.invoke("appReady");
updateBodyClasses();
LOG.flushOnAdd = false;
initKeyBindings();
}


function initKeyBindings() {
keyBindings = [];

// Parse AppCommands meta
var meta = haxe.rtti.Meta.getFields(AppCommand);
var keyNameReg = ~/(ctrl|shift|alt| |-|\+|\[wasd\]|\[zqsd\]|\[arrows\]|\[win\]|\[linux\]|\[mac\])/gi;
for(k in AppCommand.getConstructors()) {
var cmd = AppCommand.createByName(k);
var cmdMeta : Dynamic = Reflect.field(meta, k);
var rawCombos : String = try cmdMeta.k[0] catch(_) null;
if( rawCombos==null )
continue;

rawCombos = rawCombos.toLowerCase();
for(rawCombo in rawCombos.split(",")) {

var rawKey = keyNameReg.replace(rawCombo, "");
var keyCode = switch rawKey {
case "escape": K.ESCAPE;
case "tab": K.TAB;
case "pagedown": K.PGDOWN;
case "pageup": K.PGUP;
case "up": K.UP;
case "down": K.DOWN;
case "left": K.LEFT;
case "right": K.RIGHT;
case "²": K.QWERTY_TILDE;
case "`": K.QWERTY_QUOTE;

case _:
var fnReg = ~/f([0-9]|1[0-2])$/gi;
if( rawKey.length==1 && rawKey>="a" && rawKey<="z" )
K.A + ( rawKey.charCodeAt(0) - "a".code )
else if( rawKey.length==1 && rawKey>="0" && rawKey<="9" )
K.NUMBER_0 + ( rawKey.charCodeAt(0) - "0".code )
else if( fnReg.match(rawKey) )
K.F1 + Std.parseInt( fnReg.matched(1) ) - 1;
else
throw "Unknown key "+rawKey;
}

var navKeys : Null<Settings.NavigationKeys> =
rawCombo.indexOf("[wasd]")>=0 ? Settings.NavigationKeys.Wasd
: rawCombo.indexOf("[zqsd]")>=0 ? Settings.NavigationKeys.Zqsd
: rawCombo.indexOf("[arrows]")>=0 ? Settings.NavigationKeys.Arrows
: null;


var os : Null<String> =
rawCombo.indexOf("[win]")>=0 ? "win"
: rawCombo.indexOf("[linux]")>=0 ? "linux"
: rawCombo.indexOf("[mac]")>=0 ? "mac"
: null;


keyBindings.push({
keyCode: keyCode,
jsKey: rawKey,
ctrl: rawCombo.indexOf("ctrl")>=0,
shift: rawCombo.indexOf("shift")>=0,
alt: rawCombo.indexOf("alt")>=0,
navKeys: navKeys,
os: os,
allowInInputs: Reflect.hasField(cmdMeta, "input"),
command: cmd,
});
}

}
trace(keyBindings);
}


Expand Down
56 changes: 56 additions & 0 deletions src/electron.renderer/EditorTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,60 @@ enum ModalAnchor {
MA_Centered;
MA_JQuery(je:js.jquery.JQuery);
MA_Coords(m:Coords);
}


typedef KeyBinding = {
var keyCode : Int;
var jsKey : String;
var ctrl : Bool;
var shift : Bool;
var alt : Bool;

var navKeys : Null<Settings.NavigationKeys>;
var os : Null<String>;

var allowInInputs : Bool;

var command : AppCommand;
}

enum AppCommand {
@k("ctrl s") @input C_SaveProject;
@k("ctrl shift s") @input C_SaveProjectAs;
@k("ctrl W") @input C_CloseProject;

@k("escape") @input C_Back;
@k("f12") @input C_AppSettings;
@k("ctrl z") C_Undo;
@k("ctrl y") C_Redo;
@k("ctrl a") C_SelectAll;
@k("tab") C_ZenMode;
@k("h") C_ShowHelp;
@k("shift w, ², `, [zqsd] w, [arrows] w") C_ToggleWorldMode;
@k("ctrl r") @input C_RunCommand;
@k("ctrl q") @input C_ExitApp;
@k("pagedown") C_GotoPreviousWorldLayer;
@k("pageup") C_GotoNextWorldLayer;
@k("ctrl pagedown, shift pagedown") C_MoveLevelToPreviousWorldLayer;
@k("ctrl pageup, shift pageup") C_MoveLevelToNextWorldLayer;

@k("p") C_OpenProjectPanel;
@k("l") C_OpenLayerPanel;
@k("e") C_OpenEntityPanel;
@k("u") C_OpenEnumPanel;
@k("t") C_OpenTilesetPanel;
@k("c") C_OpenLevelPanel;

@k("[zqsd] z, [wasd] w, [arrows] up") C_NavUp;
@k("[zqsd] s, [wasd] s, [arrows] down") C_NavDown;
@k("[zqsd] q, [wasd] a, [arrows] left") C_NavLeft;
@k("[zqsd] d, [wasd] d, [arrows] right") C_NavRight;

@k("shift r") C_ToggleAutoLayerRender;
@k("shift e") C_ToggleSelectEmptySpaces;
@k("shift t") C_ToggleTileStacking;
@k("shift a, [zqsd] a, [arrows] a") C_ToggleSingleLayerMode;
@k("[win] ctrl h, [linux] ctrl h, [mac] shift h") C_ToggleDetails;
@k("g") C_ToggleGrid;
}
Loading

0 comments on commit d3e45c5

Please # to comment.