forked from Revolutionary-Games/Thrive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Revolutionary-Games#296 from Revolutionary-Games/2…
…39-keymap-script Keymap scripts for lua keybinding
- Loading branch information
Showing
5 changed files
with
106 additions
and
30 deletions.
There are no files selected for viewing
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,78 @@ | ||
-- Holds the keymap | ||
|
||
kmp = {} | ||
|
||
-- Microbe Editor -- | ||
|
||
kmp.undo = {"ctrl", "U"} | ||
kmp.redo = {"ctrl", "R"} | ||
|
||
kmp.remove = {"R"} | ||
kmp.newmicrobe = {"C"} | ||
|
||
kmp.vacuole = {"S"} | ||
kmp.mitochondrion = {"M"} | ||
kmp.oxytoxyvacuole = {"T"} | ||
kmp.flagellum = {"F"} | ||
kmp.chloroplast = {"P"} | ||
|
||
kmp.togglegrid = {"G"} | ||
|
||
kmp.rename = {"F12"} | ||
kmp.gotostage = {"F2"} | ||
|
||
-- Microbe Stage -- | ||
|
||
kmp.forward = {"W"} | ||
kmp.backward = {"S"} | ||
kmp.leftward = {"A"} | ||
kmp.rightward = {"D"} | ||
|
||
kmp.shootoxytoxy = {"E"} | ||
kmp.reproduce = {"P"} | ||
|
||
kmp.togglemenu = {"ESCAPE"} | ||
kmp.gotoeditor = {"F2"} | ||
kmp.altuniverse = {"F1"} | ||
|
||
-- this is the perfect kind of thing to move into C++ | ||
-- it shouldn't require anything in Lua, it'll just get a table of strings, and do comparisons | ||
function keyCombo(combo) | ||
-- Boolean function, used to check if key combo is pressed | ||
-- doesn't handle modifier keys properly yet (eg, ctrl+R will activate R) | ||
|
||
mods = {} -- holds whether each particular modifier key (left-right-agnostic) is pressed | ||
mods.ctrl = false | ||
mods.alt = false | ||
mods.shift = false | ||
|
||
for _, key in ipairs(combo) do | ||
if key == "ctrl" then | ||
mods.ctrl = true | ||
elseif key == "shift" then | ||
mods.shift = true | ||
elseif key == "alt" then | ||
mods.alt = true | ||
elseif not Engine.keyboard:wasKeyPressed(Keyboard["KC_"..key]) then | ||
return false | ||
end | ||
end | ||
-- fail if any modkey pressed unmatches required mods | ||
|
||
if (Engine.keyboard:isKeyDown(Keyboard.KC_LCONTROL) | ||
or Engine.keyboard:isKeyDown(Keyboard.KC_RCONTROL) | ||
) ~= mods.ctrl then | ||
return false | ||
end | ||
if (Engine.keyboard:isKeyDown(Keyboard.KC_LSHIFT) | ||
or Engine.keyboard:isKeyDown(Keyboard.KC_RSHIFT) | ||
) ~= mods.shift then | ||
return false | ||
end | ||
if (Engine.keyboard:isKeyDown(Keyboard.KC_LMENU) | ||
or Engine.keyboard:isKeyDown(Keyboard.KC_RMENU) | ||
) ~= mods.alt then | ||
return false | ||
end | ||
return true | ||
end |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ constants.lua | |
quick_save.lua | ||
util.lua | ||
|
||
keymap.lua | ||
|
||
main_menu | ||
microbe_stage | ||
microbe_editor | ||
|
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