mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Remove ScriptEvent with only one parameter
The effect is the same when the second parameter is defaulted.
This commit is contained in:
parent
7ccea4ace9
commit
2748a45fc6
4 changed files with 10 additions and 45 deletions
|
|
@ -59,7 +59,6 @@
|
|||
#include <algorithm>
|
||||
#include <js/CallAndConstruct.h>
|
||||
#include <js/Promise.h>
|
||||
#include <js/ValueArray.h>
|
||||
#include <optional>
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_mouse.h>
|
||||
|
|
@ -351,18 +350,8 @@ JSObject* CGUI::TickObjects(const ScriptRequest& rq, Script::StructuredClone ini
|
|||
return sendingPromise;
|
||||
}
|
||||
|
||||
void CGUI::SendEventToAll(const CStr& eventName)
|
||||
{
|
||||
std::unordered_map<CStr, std::vector<IGUIObject*>>::iterator it = m_EventObjects.find(eventName);
|
||||
if (it == m_EventObjects.end())
|
||||
return;
|
||||
|
||||
std::vector<IGUIObject*> copy = it->second;
|
||||
for (IGUIObject* object : copy)
|
||||
object->ScriptEvent(eventName);
|
||||
}
|
||||
|
||||
void CGUI::SendEventToAll(const CStr& eventName, const JS::HandleValueArray& paramData)
|
||||
void CGUI::SendEventToAll(const CStr& eventName,
|
||||
const JS::HandleValueArray paramData /* = JS::HandleValueArray::empty() */)
|
||||
{
|
||||
std::unordered_map<CStr, std::vector<IGUIObject*>>::iterator it = m_EventObjects.find(eventName);
|
||||
if (it == m_EventObjects.end())
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include <js/RootingAPI.h>
|
||||
#include <js/TypeDecls.h>
|
||||
#include <js/ValueArray.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
|
@ -105,20 +106,14 @@ public:
|
|||
JSObject* TickObjects(const ScriptRequest& rq, Script::StructuredClone initData,
|
||||
const std::string_view scriptName);
|
||||
|
||||
/**
|
||||
* Sends a specified script event to every object
|
||||
*
|
||||
* @param eventName String representation of event name
|
||||
*/
|
||||
void SendEventToAll(const CStr& eventName);
|
||||
|
||||
/**
|
||||
* Sends a specified script event to every object
|
||||
*
|
||||
* @param eventName String representation of event name
|
||||
* @param paramData JS::HandleValueArray storing the arguments passed to the event handler.
|
||||
*/
|
||||
void SendEventToAll(const CStr& eventName, const JS::HandleValueArray& paramData);
|
||||
void SendEventToAll(const CStr& eventName,
|
||||
const JS::HandleValueArray paramData = JS::HandleValueArray::empty());
|
||||
|
||||
/**
|
||||
* Displays the whole GUI
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@
|
|||
#include <js/SourceText.h>
|
||||
#include <js/TracingAPI.h>
|
||||
#include <js/Value.h>
|
||||
#include <js/ValueArray.h>
|
||||
#include <jsapi.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
|
@ -447,17 +446,8 @@ InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventNam
|
|||
return msg.skipped ? IN_PASS : IN_HANDLED;
|
||||
}
|
||||
|
||||
bool IGUIObject::ScriptEvent(const CStr& eventName)
|
||||
{
|
||||
if (m_ScriptHandlers.find(eventName) == m_ScriptHandlers.end())
|
||||
return false;
|
||||
|
||||
ScriptRequest rq(m_pGUI.GetScriptInterface());
|
||||
JS::RootedValueVector paramData(rq.cx);
|
||||
return ScriptEvent(eventName, paramData);
|
||||
}
|
||||
|
||||
bool IGUIObject::ScriptEvent(const CStr& eventName, const JS::HandleValueArray& paramData)
|
||||
bool IGUIObject::ScriptEvent(const CStr& eventName,
|
||||
const JS::HandleValueArray& paramData /* = JS::HandleValueArray::empty() */)
|
||||
{
|
||||
std::map<CStr, JS::Heap<JSObject*> >::iterator it = m_ScriptHandlers.find(eventName);
|
||||
if (it == m_ScriptHandlers.end())
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include <js/RootingAPI.h>
|
||||
#include <js/TypeDecls.h>
|
||||
#include <js/ValueArray.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
|
@ -396,17 +397,6 @@ protected:
|
|||
*/
|
||||
CRect m_CachedActualSize;
|
||||
|
||||
/**
|
||||
* Execute the script for a particular action.
|
||||
* Does nothing if no script has been registered for that action.
|
||||
* The mouse coordinates will be passed as the first argument.
|
||||
*
|
||||
* @param eventName Name of action
|
||||
*
|
||||
* @return True if the script returned something truthy.
|
||||
*/
|
||||
bool ScriptEvent(const CStr& eventName);
|
||||
|
||||
/**
|
||||
* Execute the script for a particular action.
|
||||
* Does nothing if no script has been registered for that action.
|
||||
|
|
@ -416,7 +406,8 @@ protected:
|
|||
*
|
||||
* @return True if the script returned something truthy.
|
||||
*/
|
||||
bool ScriptEvent(const CStr& eventName, const JS::HandleValueArray& paramData);
|
||||
bool ScriptEvent(const CStr& eventName,
|
||||
const JS::HandleValueArray& paramData = JS::HandleValueArray::empty());
|
||||
|
||||
/**
|
||||
* Assigns a JS function to the event name.
|
||||
|
|
|
|||
Loading…
Reference in a new issue