Skip to content

Commit

Permalink
Clean-up undocumented (and unused) eventKeyPressed
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 18, 2023
1 parent 65b202e commit 3d4bc8c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 91 deletions.
64 changes: 1 addition & 63 deletions src/input/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include "../keybind.h"
#include "../keyedit.h"
#include "../display3d.h" // For playerPos
#include "../qtscript.h" // For triggerEventKeyPressed
#include "../main.h" // For KeyMapPath
#include "lib/netplay/nettypes.h" // For NETisReplay()


KeyMappings& InputManager::mappings()
Expand Down Expand Up @@ -299,66 +299,4 @@ void InputManager::processMappings(const bool bAllowMouseWheelEvents)
consumedInputs.insert(keyToProcess.keys.input);
}
}

/* Script callback - find out what meta key was pressed */
int pressedMetaKey = KEY_IGNORE;

/* getLastMetaKey() can't be used here, have to do manually */
if (keyDown(KEY_LCTRL))
{
pressedMetaKey = KEY_LCTRL;
}
else if (keyDown(KEY_RCTRL))
{
pressedMetaKey = KEY_RCTRL;
}
else if (keyDown(KEY_LALT))
{
pressedMetaKey = KEY_LALT;
}
else if (keyDown(KEY_RALT))
{
pressedMetaKey = KEY_RALT;
}
else if (keyDown(KEY_LSHIFT))
{
pressedMetaKey = KEY_LSHIFT;
}
else if (keyDown(KEY_RSHIFT))
{
pressedMetaKey = KEY_RSHIFT;
}
else if (keyDown(KEY_LMETA))
{
pressedMetaKey = KEY_LMETA;
}
else if (keyDown(KEY_RMETA))
{
pressedMetaKey = KEY_RMETA;
}

/* Find out what keys were pressed */
for (int i = 0; i < KEY_MAXSCAN; i++)
{
/* Skip meta keys */
switch (i)
{
case KEY_LCTRL:
case KEY_RCTRL:
case KEY_LALT:
case KEY_RALT:
case KEY_LSHIFT:
case KEY_RSHIFT:
case KEY_LMETA:
case KEY_RMETA:
continue;
break;
}

/* Let scripts process this key if it's pressed */
if (keyPressed((KEY_CODE)i))
{
triggerEventKeyPressed(pressedMetaKey, i);
}
}
}
14 changes: 0 additions & 14 deletions src/qtscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,20 +1695,6 @@ bool triggerEventSyncRequest(int from, int req_id, int x, int y, BASE_OBJECT *ps
return true;
}

//__ ## eventKeyPressed(meta, key)
//__
//__ An event that is called whenever user presses a key in the game, not counting chat
//__ or other pop-up user interfaces. The key values are currently undocumented.
bool triggerEventKeyPressed(int meta, int key)
{
ASSERT(scriptsReady, "Scripts not initialized yet");
for (auto *instance : scripts)
{
instance->handle_eventKeyPressed(meta, key);
}
return true;
}

// ----

#define ALL_PLAYERS -1
Expand Down
1 change: 0 additions & 1 deletion src/qtscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ bool triggerEventSelected();
bool triggerEventPlayerLeft(int player);
bool triggerEventDesignCreated(DROID_TEMPLATE *psTemplate);
bool triggerEventSyncRequest(int from, int req_id, int x, int y, BASE_OBJECT *psObj, BASE_OBJECT *psObj2);
bool triggerEventKeyPressed(int meta, int key);
bool triggerEventAllianceOffer(uint8_t from, uint8_t to);
bool triggerEventAllianceAccepted(uint8_t from, uint8_t to);
bool triggerEventAllianceBroken(uint8_t from, uint8_t to);
Expand Down
7 changes: 0 additions & 7 deletions src/quickjs_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,6 @@ class quickjs_scripting_instance : public wzapi::scripting_instance
//__ cheating!
//__
virtual bool handle_eventSyncRequest(int from, int req_id, int x, int y, const BASE_OBJECT *psObj, const BASE_OBJECT *psObj2) override;

//__ ## eventKeyPressed(meta, key)
//__
//__ An event that is called whenever user presses a key in the game, not counting chat
//__ or other pop-up user interfaces. The key values are currently undocumented.
virtual bool handle_eventKeyPressed(int meta, int key) override;
};

// private QuickJS bureaucracy
Expand Down Expand Up @@ -3036,7 +3030,6 @@ IMPL_EVENT_HANDLER(eventAllianceBroken, uint8_t, uint8_t)

// MARK: Special input events
IMPL_EVENT_HANDLER(eventSyncRequest, int, int, int, int, const BASE_OBJECT *, const BASE_OBJECT *)
IMPL_EVENT_HANDLER(eventKeyPressed, int, int)

// ----------------------------------------------------------------------------------------
// Script functions
Expand Down
6 changes: 0 additions & 6 deletions src/wzapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,6 @@ namespace wzapi
//__ cheating!
//__
virtual bool handle_eventSyncRequest(int from, int req_id, int x, int y, const BASE_OBJECT *psObj, const BASE_OBJECT *psObj2) = 0;

//__ ## eventKeyPressed(meta, key)
//__
//__ An event that is called whenever user presses a key in the game, not counting chat
//__ or other pop-up user interfaces. The key values are currently undocumented.
virtual bool handle_eventKeyPressed(int meta, int key) SCRIPTING_EVENT_NON_REQUIRED
};

enum class GlobalVariableFlags
Expand Down

0 comments on commit 3d4bc8c

Please sign in to comment.