V-Gears 0
Free Final Fantasy VII engine.
ScriptManager Class Reference

#include <ScriptManager.h>

Inheritance diagram for ScriptManager:
Collaboration diagram for ScriptManager:

Public Types

enum  Type { SYSTEM , ENTITY , UI , BATTLE }
 Script types. More...
 
- Public Types inherited from Manager
enum  Module { FIELD = 0 , BATTLE = 1 , WORLD = 2 }
 The modules the entity manager can handle. More...
 

Public Member Functions

 ScriptManager ()
 Constructor. More...
 
virtual ~ScriptManager ()
 Destructor. More...
 
void Input (const VGears::Event &event) override
 Handles an input event. More...
 
void Update (const Type type)
 Updates the state of all scripts of a given type. More...
 
void UpdateDebug () override
 Updates the script in the manager with debug information. More...
 
void OnResize () override
 Handles resizing events. More...
 
void ClearField () override
 Clears all field information in the script manager. More...
 
void ClearBattle () override
 Clears all battle information in the script manager. More...
 
void ClearWorld () override
 Clears all world map information in the script manager. More...
 
void RunString (const Ogre::String &lua)
 Runs a lua command string. More...
 
void RunFile (const Ogre::String &file)
 Runs a lua file. More...
 
void InitBinds ()
 Initializes Lua binds. More...
 
void InitCmd ()
 Initializes command bindings. More...
 
void AddEntity (const Type type, const Ogre::String &entity_name, Entity *entity)
 Adds an entity to the manager. More...
 
void RemoveEntity (const Type type, const Ogre::String &entity_name)
 Deletes an entity from the manager. More...
 
void AddEntityScript (const Ogre::String &entity_name, const Ogre::String &function_name, int priority)
 Adds an script to an entity. More...
 
void RemoveEntityTopScript (ScriptEntity &entity)
 Removes the top script of an entity. More...
 
luabind::object GetTableByEntityName (const ScriptManager::Type type, const Ogre::String &name, lua_State *state) const
 Retrieves a table. More...
 
QueueScriptGetScriptByScriptId (const ScriptId &script) const
 Retrieves a script from it's ID. More...
 
ScriptEntityGetScriptEntityByName (const Type type, const Ogre::String &entity_name) const
 Retrieves a script entity by it's name and type. More...
 
const ScriptId GetCurrentScriptId () const
 Retrieves the current script ID. More...
 
void ContinueScriptExecution (const ScriptId &script)
 continues the execution of a script. More...
 
int ScriptWait (const float seconds)
 Makes an script wait. More...
 
void ScriptRequest (const Type type, const char *entity, const char *function, const int priority)
 Request an script execution. More...
 
int ScriptRequestStartSync (const Type type, const char *entity, const char *function, const int priority)
 Request a synchronous script execution to start. More...
 
int ScriptRequestEndSync (const Type type, const char *entity, const char *function, const int priority)
 Request a synchronous script execution to end. More...
 
bool ScriptRequest (ScriptEntity *script_entity, const Ogre::String &function, const int priority, const Ogre::String &argument1, const Ogre::String &argument2, bool start_sync, bool end_sync)
 Request a script execution. More...
 
void AddValueToStack (const float value)
 Adds a script to the stack. More...
 
- Public Member Functions inherited from Manager
 Manager ()
 Constructor. More...
 
virtual ~Manager ()
 Destructor. More...
 
Module GetModule () const
 Retrieves the currently selected module. More...
 
bool IsModule (const Module module) const
 Checks the currently selected module. More...
 
bool IsFieldModule () const
 Checks if the currently selected module is the field module. More...
 
bool IsBattleModule () const
 Checks if the currently selected module is the battle module. More...
 
bool IsWorldModule () const
 Checks if the currently selected module is the world module. More...
 
void SetModule (const Module module)
 Sets the current module for the entity manager. More...
 
void SetFieldModule ()
 Sets the current module to the field mode. More...
 
void SetBattleModule ()
 Sets the current module to the battle mode. More...
 
void SetWorldModule ()
 Sets the current module to the world map mode. More...
 
void SetPreviousModule ()
 Sets the module that was loaded before a battle. More...
 
virtual void Input (const VGears::Event &event)=0
 Handles an input event. More...
 
void Update ()
 Called every frame, performs an update on the things controlled by the manager. More...
 
virtual void UpdateDebug ()=0
 Called every frame, performs an update on the things controlled by the manager. More...
 
virtual void OnResize ()=0
 Handles resizing events. More...
 
void Clear ()
 Clears the manager. More...
 
void Clear (const Module module)
 Clears the manager. More...
 
virtual void ClearField ()=0
 Clear all field information in the manager. More...
 
virtual void ClearBattle ()=0
 Clear all battle information in the manager. More...
 
virtual void ClearWorld ()=0
 Clear all world map information in the manager. More...
 
void ClearAll ()
 Clears the manager. More...
 
void ScriptSetPaused (const bool paused)
 Handles game pausing. More...
 

Private Member Functions

void UpdateField () override
 Updates the script while in a field. More...
 
void UpdateBattle () override
 Updates the scripts during a battle. More...
 
void UpdateWorld () override
 Updates the scripts while on the world map. More...
 

Private Attributes

lua_State * lua_state_
 Lua state. More...
 
Ogre::String system_table_name_
 The system script table name. More...
 
Ogre::String entity_table_name_
 The entity script table name. More...
 
Ogre::String battle_table_name_
 The battle entity script table name. More...
 
Ogre::String ui_table_name_
 The UI script table name. More...
 
std::vector< ScriptEntityscript_entity_
 The list of map entity scripts. More...
 
ScriptId current_script_id_
 The current script ID. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Manager
virtual void UpdateField ()=0
 Updates the field entities in the manager. More...
 
virtual void UpdateBattle ()=0
 Updates the battle entities in the manager. More...
 
virtual void UpdateWorld ()=0
 Updates the world map entities in the manager. More...
 
void Update (Module module)
 Updates the entities of one module in the manager. More...
 
- Protected Attributes inherited from Manager
Module module_
 The currently selected module. More...
 
Module prev_module_
 The previous module. More...
 
bool paused_
 Indicates if the game is paused. More...
 

Member Enumeration Documentation

◆ Type

Script types.

Enumerator
SYSTEM 

System script.

The script is triggered by a system event.

ENTITY 

A field or world map entity script.

The script belongs to any of the entities on a map.

UI 

A UI element script.

The script is triggered by a UI element (menu, cursor...)

BATTLE 

A battle entity script.

The script belongs to any of the entities on the battle.

Constructor & Destructor Documentation

◆ ScriptManager()

ScriptManager::ScriptManager ( )

Constructor.

◆ ~ScriptManager()

ScriptManager::~ScriptManager ( )
virtual

Destructor.

Member Function Documentation

◆ AddEntity()

void ScriptManager::AddEntity ( const Type  type,
const Ogre::String &  entity_name,
Entity entity 
)

Adds an entity to the manager.

Usage depends on the currently active module. The entity will be added to the list of entities of the module.

Parameters
[in]typeType of entity to add.
[in]entity_nameThe entity name.
[in]entityThe entity to add.

◆ AddEntityScript()

void ScriptManager::AddEntityScript ( const Ogre::String &  entity_name,
const Ogre::String &  function_name,
int  priority 
)

Adds an script to an entity.

Usage depends on the currently active module. The script will be added to the list of scripts of the module.

Parameters
[in]entity_nameName of the entity to add a script to.
[in]function_nameName of the script to add.
[in]priorityScript priority. Lower numbers have higher priority.

◆ AddValueToStack()

void ScriptManager::AddValueToStack ( const float  value)

Adds a script to the stack.

Parameters
[in]valueID of the script to add.
Todo:
Verify this documentation.

◆ ClearBattle()

void ScriptManager::ClearBattle ( )
overridevirtual

Clears all battle information in the script manager.

Implements Manager.

◆ ClearField()

void ScriptManager::ClearField ( )
overridevirtual

Clears all field information in the script manager.

Implements Manager.

◆ ClearWorld()

void ScriptManager::ClearWorld ( )
overridevirtual

Clears all world map information in the script manager.

Implements Manager.

◆ ContinueScriptExecution()

void ScriptManager::ContinueScriptExecution ( const ScriptId script)

continues the execution of a script.

Parameters
[in]scriptThe ID of the script to resume.

◆ GetCurrentScriptId()

const ScriptId ScriptManager::GetCurrentScriptId ( ) const

Retrieves the current script ID.

Returns
The currently executing script ID.

◆ GetScriptByScriptId()

QueueScript * ScriptManager::GetScriptByScriptId ( const ScriptId script) const

Retrieves a script from it's ID.

Parameters
[in]scriptScript ID.
Returns
The script with the corresponding ID, or nullptr if there is none.

◆ GetScriptEntityByName()

ScriptEntity * ScriptManager::GetScriptEntityByName ( const Type  type,
const Ogre::String &  entity_name 
) const

Retrieves a script entity by it's name and type.

Usage depends on the currently active module. The entity will be searched among the entities of the currently active module.

Parameters
[in]typeEntity type.
[in]entity_nameThe entity name.
Returns
The entity by that type and name, or nullptr if there is no one that matches.

◆ GetTableByEntityName()

luabind::object ScriptManager::GetTableByEntityName ( const ScriptManager::Type  type,
const Ogre::String &  name,
lua_State *  state 
) const

Retrieves a table.

The retrieved table depends on the currently active module.

Parameters
[in]typeType of script.
[in]nameScript name.
[in]stateInitial script state.
Returns
The table.
Todo:
Understand and document.

◆ InitBinds()

void ScriptManager::InitBinds ( )

Initializes Lua binds.

It relates the command available in the field maps to C++ functions.

◆ InitCmd()

void ScriptManager::InitCmd ( )

Initializes command bindings.

◆ Input()

void ScriptManager::Input ( const VGears::Event event)
overridevirtual

Handles an input event.

Parameters
[in]eventThe event to handle.

Implements Manager.

◆ OnResize()

void ScriptManager::OnResize ( )
overridevirtual

Handles resizing events.

Implements Manager.

◆ RemoveEntity()

void ScriptManager::RemoveEntity ( const Type  type,
const Ogre::String &  entity_name 
)

Deletes an entity from the manager.

Usage depends on the currently active module. The entity will be removed from the list of entities of the module. If there is no entity with name ENTITY_NAME and type TYPE, nothing will be done.

Parameters
[in]typeType of the entity to remove.
[in]entity_nameName of the entity to remove.

◆ RemoveEntityTopScript()

void ScriptManager::RemoveEntityTopScript ( ScriptEntity entity)

Removes the top script of an entity.

The entity must be in one of the currently active modules for it's script to be removed.

Parameters
[in]entityEntity whose first script to remove.

◆ RunFile()

void ScriptManager::RunFile ( const Ogre::String &  file)

Runs a lua file.

No errors are handled, and nothing is returned

Parameters
[in]filePath to the lua file to run (relative to the data directory).

◆ RunString()

void ScriptManager::RunString ( const Ogre::String &  lua)

Runs a lua command string.

No errors are handled, and nothing is returned

Parameters
[in]luaLua string to run.

◆ ScriptRequest() [1/2]

void ScriptManager::ScriptRequest ( const Type  type,
const char *  entity,
const char *  function,
const int  priority 
)

Request an script execution.

The script will execute only if it's not already being executed.

Parameters
[in]typeScript type.
[in]entityEntity the scripts belong to.
[in]functionName of the function of the selected entity to execute.
[in]priorityExecution priority.

◆ ScriptRequest() [2/2]

bool ScriptManager::ScriptRequest ( ScriptEntity script_entity,
const Ogre::String &  function,
const int  priority,
const Ogre::String &  argument1,
const Ogre::String &  argument2,
bool  start_sync,
bool  end_sync 
)

Request a script execution.

Parameters
[in]script_entityEntity the scripts belong to.
[in]functionName of the function of the selected entity to execute.
[in]priorityExecution priority.
[in]argument1First argument for the script.
[in]argument2Second argument for the script.
[in]start_syncIf true, the script will be started synchronously.
[in]end_sync
Todo:
Understand and document.
Returns
True on success, false on error (i.e. if the entity or the script don't exist)

◆ ScriptRequestEndSync()

int ScriptManager::ScriptRequestEndSync ( const Type  type,
const char *  entity,
const char *  function,
const int  priority 
)

Request a synchronous script execution to end.

Parameters
[in]typeScript type.
[in]entityEntity the scripts belong to.
[in]functionName of the function of the selected entity to execute.
[in]priorityExecution priority.
Returns
-1 if the execution stops or if the script was not running, 1 if the entity or the script don't exist.

◆ ScriptRequestStartSync()

int ScriptManager::ScriptRequestStartSync ( const Type  type,
const char *  entity,
const char *  function,
const int  priority 
)

Request a synchronous script execution to start.

Parameters
[in]typeScript type.
[in]entityEntity the scripts belong to.
[in]functionName of the function of the selected entity to execute.
[in]priorityExecution priority.
Returns
-1 on success, 1 if the entity or the script don't exist.

◆ ScriptWait()

int ScriptManager::ScriptWait ( const float  seconds)

Makes an script wait.

Parameters
[in]secondsNumber of seconds to wait.
Todo:
Does it refer to the current script?

◆ Update()

void ScriptManager::Update ( const Type  type)

Updates the state of all scripts of a given type.

Parameters
[in]typeType of the scripts to update.

◆ UpdateBattle()

void ScriptManager::UpdateBattle ( )
overrideprivatevirtual

Updates the scripts during a battle.

Implements Manager.

◆ UpdateDebug()

void ScriptManager::UpdateDebug ( )
overridevirtual

Updates the script in the manager with debug information.

Implements Manager.

◆ UpdateField()

void ScriptManager::UpdateField ( )
overrideprivatevirtual

Updates the script while in a field.

Implements Manager.

◆ UpdateWorld()

void ScriptManager::UpdateWorld ( )
overrideprivatevirtual

Updates the scripts while on the world map.

Implements Manager.

Member Data Documentation

◆ battle_table_name_

Ogre::String ScriptManager::battle_table_name_
private

The battle entity script table name.

◆ current_script_id_

ScriptId ScriptManager::current_script_id_
private

The current script ID.

◆ entity_table_name_

Ogre::String ScriptManager::entity_table_name_
private

The entity script table name.

◆ lua_state_

lua_State* ScriptManager::lua_state_
private

Lua state.

◆ script_entity_

std::vector<ScriptEntity> ScriptManager::script_entity_
private

The list of map entity scripts.

◆ system_table_name_

Ogre::String ScriptManager::system_table_name_
private

The system script table name.

◆ ui_table_name_

Ogre::String ScriptManager::ui_table_name_
private

The UI script table name.


The documentation for this class was generated from the following files: