ScriptManagerBinds.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <iostream>
  16. #include "../modules/worldmap/WorldmapModule.h"
  17. #include "Console.h"
  18. #include "Logger.h"
  19. #include "CameraManager.h"
  20. #include "Enemy.h"
  21. #include "Entity.h"
  22. #include "EntityManager.h"
  23. #include "BattleManager.h"
  24. #include "AudioManager.h"
  25. #include "InputManager.h"
  26. #include "SavemapHandler.h"
  27. #include "Timer.h"
  28. #include "UiManager.h"
  29. #include "UiWidget.h"
  30. #include "XmlMapFile.h"
  31. #include "XmlMapsFile.h"
  32. #include "DialogsManager.h"
  33. #include "TextHandler.h"
  34. /**
  35. * Prints to the game console.
  36. *
  37. * @param[in] text The text to be printed.
  38. */
  39. void ScriptPrint(const char* text){
  40. std::cout << "[SCRIPT] " << text << std::endl;
  41. Console::getSingleton().AddTextToOutput(text);
  42. }
  43. /**
  44. * Changes the current map.
  45. *
  46. * Reads the data for the next map, initializes all it's entities, scripts, etc
  47. * and loads it.
  48. *
  49. * @param[in] text The new map name.
  50. */
  51. void ScriptMap(const char* text){
  52. VGears::WorldmapModule::getSingleton().Suspend();
  53. EntityManager::getSingleton().SetFieldModule();
  54. EntityManager::getSingleton().Clear();
  55. // The battle music and mode are set by the scripts of each field.
  56. AudioManager::getSingleton().ScriptSetBattleTrack(-1);
  57. BattleManager::getSingleton().ScriptSetMode(0);
  58. XmlMapsFile xml("./data/fields/_fields.xml");
  59. Ogre::String file_name = xml.GetMapFileNameByName(text);
  60. XmlMapFile xml_map("./data/fields/" + file_name);
  61. xml_map.LoadMap();
  62. }
  63. void ScriptWorldMap(const int map, const unsigned int x, const unsigned int y){
  64. EntityManager::getSingleton().Clear();
  65. XmlMapFile xml_map("./data/fields/wm" + std::to_string(map) + ".xml");
  66. xml_map.LoadMap();
  67. }
  68. /**
  69. * Executes a script in the game console.
  70. *
  71. * It should not be related to the game itself. The script output will be
  72. * written to the game console.
  73. *
  74. * @param[in] text The script command to execute.
  75. */
  76. void ScriptConsole(const char* text){
  77. Console::getSingleton().ExecuteCommand(text);
  78. }
  79. /**
  80. * Binds a yielding member function to a class table.
  81. *
  82. * sol2 v2.20.6 function wrappers don't understand sol::yielding_t, so
  83. * sol::yielding can't be used with new_usertype or set_function. The raw
  84. * stack pusher does support it, so the yielding closure is pushed manually
  85. * and set as a field of the class table.
  86. *
  87. * @param[in,out] table The class table to bind the function to.
  88. * @param[in] name Function name for scripts.
  89. * @param[in] function The member function to bind.
  90. */
  91. template <typename F>
  92. void BindYielding(sol::table& table, const char* name, F function){
  93. table.push();
  94. sol::stack::push(table.lua_state(), sol::yielding(function));
  95. lua_setfield(table.lua_state(), -2, name);
  96. lua_pop(table.lua_state(), 1);
  97. }
  98. void ScriptManager::InitBinds(){
  99. sol::state_view lua_view(lua_state_);
  100. sol::table lua = lua_view.globals();
  101. // Global functions.
  102. lua.set_function("print", &ScriptPrint);
  103. lua.set_function("map", &ScriptMap);
  104. lua.set_function("console", &ScriptConsole);
  105. // Individual entity commands.
  106. lua.new_usertype<Entity>(
  107. "Entity",
  108. "set_position", &Entity::ScriptSetPosition,
  109. "set_position_xy", &Entity::ScriptSetPositionXY,
  110. "move_by", &Entity::ScriptMoveBy,
  111. "get_position", &Entity::ScriptGetPosition,
  112. "get_name", &Entity::GetName,
  113. "set_rotation", &Entity::ScriptSetRotation,
  114. "get_rotation", &Entity::ScriptGetRotation,
  115. "set_solid_radius", &Entity::SetSolidRadius,
  116. "get_solid_radius", &Entity::GetSolidRadius,
  117. "set_solid", &Entity::SetSolid,
  118. "is_solid", &Entity::IsSolid,
  119. "set_talk_radius", &Entity::SetTalkRadius,
  120. "get_talk_radius", &Entity::GetTalkRadius,
  121. // Some old test script use this, its just an alias for SetTalkable:
  122. "set_interactable", &Entity::SetTalkable,
  123. "set_talkable", &Entity::SetTalkable,
  124. "is_talkable", &Entity::IsTalkable,
  125. "set_visible", &Entity::SetVisible,
  126. "set_scale", &Entity::ScriptSetScale,
  127. "set_model_rotation", &Entity::ScriptSetModelRotation,
  128. "set_blend", &Entity::ScriptSetBlend,
  129. "set_alpha", &Entity::ScriptSetAlpha,
  130. "set_texture", &Entity::ScriptSetTexture,
  131. "get_bone_position", &Entity::ScriptGetBonePosition,
  132. "attach_model", sol::overload(
  133. [](Entity& entity, const char* model, const int bone){
  134. return entity.ScriptAttachModel(model, bone, 0.0f, 0.0f, 0.0f);
  135. },
  136. &Entity::ScriptAttachModel
  137. ),
  138. "is_visible", &Entity::IsVisible,
  139. "set_move_auto_speed", &Entity::SetMoveAutoSpeed,
  140. "get_move_auto_speed", &Entity::GetMoveAutoSpeed,
  141. "get_move_triangle_id", &Entity::GetMoveTriangleId,
  142. "set_move_triangle_id", &Entity::SetMoveTriangleId,
  143. "move_auto_rotation", &Entity::SetMoveAutoRotation,
  144. "move_auto_animation", &Entity::SetMoveAutoAnimation,
  145. "set_move_animations", &Entity::SetMoveAnimations,
  146. "move_to_position", &Entity::ScriptMoveToPosition,
  147. "move_to_entity", &Entity::ScriptMoveToEntity,
  148. "linear_to_position", &Entity::ScriptLinearToPosition,
  149. "jump_to_position", &Entity::ScriptJumpToPosition,
  150. "offset_to_position", &Entity::ScriptOffsetToPosition,
  151. "turn_to_entity", &Entity::ScriptTurnToEntity,
  152. "face_entity", &Entity::ScriptFaceEntity,
  153. "turn_to_direction", &Entity::ScriptTurnToDirection,
  154. "set_animation_speed", &Entity::ScriptSetAnimationSpeed,
  155. "play_animation", sol::overload(
  156. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimation),
  157. sol::resolve<void(const char*, const float, const float)>(&Entity::ScriptPlayAnimation)
  158. ),
  159. "play_animation_stop", sol::overload(
  160. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimationStop),
  161. sol::resolve<void(const char*, const float, const float)>(
  162. &Entity::ScriptPlayAnimationStop
  163. )
  164. ),
  165. "get_animation_length", &Entity::ScriptGetAnimationLength,
  166. "get_animation_count", &Entity::GetAnimationCount,
  167. "set_default_animation", &Entity::ScriptSetDefaultAnimation
  168. );
  169. sol::table entity_type = lua["Entity"];
  170. BindYielding(entity_type, "move_sync", &Entity::ScriptMoveSync);
  171. BindYielding(entity_type, "linear_sync", &Entity::ScriptLinearSync);
  172. BindYielding(entity_type, "jump_sync", &Entity::ScriptJumpSync);
  173. BindYielding(entity_type, "offset_sync", &Entity::ScriptOffsetSync);
  174. BindYielding(entity_type, "turn_sync", &Entity::ScriptTurnSync);
  175. BindYielding(entity_type, "animation_sync", &Entity::ScriptAnimationSync);
  176. entity_type["BLEND_NORMAL"] = Entity::BLEND_NORMAL;
  177. entity_type["BLEND_ADDITIVE"] = Entity::BLEND_ADDITIVE;
  178. entity_type["BLEND_ALPHA"] = Entity::BLEND_ALPHA;
  179. entity_type["NONE"] = AT_NONE;
  180. entity_type["LINEAR"] = AT_LINEAR;
  181. entity_type["SMOOTH"] = AT_SMOOTH;
  182. entity_type["CLOCKWISE"] = TD_CLOCKWISE;
  183. entity_type["ANTICLOCKWISE"] = TD_ANTICLOCKWISE;
  184. entity_type["CLOSEST"] = TD_CLOSEST;
  185. entity_type["UP_TO_DOWN"] = LM_UP_TO_DOWN;
  186. entity_type["DOWN_TO_UP"] = LM_DOWN_TO_UP;
  187. entity_type["LEFT_TO_RIGHT"] = LM_LEFT_TO_RIGHT;
  188. entity_type["RIGHT_TO_LEFT"] = LM_RIGHT_TO_LEFT;
  189. // Entity individual point commands
  190. lua.new_usertype<EntityPoint>(
  191. "EntityPoint",
  192. "get_position", &EntityPoint::ScriptGetPosition,
  193. "get_rotation", &EntityPoint::ScriptGetRotation
  194. );
  195. // Commands for the entity manager, not related to any particular entity.
  196. lua.new_usertype<EntityManager>(
  197. "EntityManager",
  198. "set_paused", &EntityManager::ScriptSetPaused,
  199. "add_entity", &EntityManager::ScriptAddEntity,
  200. "add_entity_script", &EntityManager::ScriptAddEntityScript,
  201. "get_entity", &EntityManager::ScriptGetEntity,
  202. "get_entity_from_index", &EntityManager::GetEntityFromIndex,
  203. "get_entity_from_character_id", &EntityManager::GetEntityFromCharacterId,
  204. "get_entity_point", &EntityManager::ScriptGetEntityPoint,
  205. "set_player_entity", &EntityManager::ScriptSetPlayerEntity,
  206. "place_player_at_field_entry", &EntityManager::ScriptPlacePlayerAtFieldEntry,
  207. "get_player_entity", &EntityManager::ScriptGetPlayerEntity,
  208. "unset_player_entity", &EntityManager::ScriptUnsetPlayerEntity,
  209. "player_lock", &EntityManager::ScriptPlayerLock,
  210. "is_player_locked", &EntityManager::IsPlayerLocked,
  211. "set_player_default_run", &EntityManager::SetPlayerDefaultRun,
  212. "random_encounters_on", &EntityManager::SetRandomEncounters,
  213. "set_encounter_table", &EntityManager::ScriptSetEncounterTable,
  214. "roll_encounter_battle", &EntityManager::ScriptRollEncounterBattle,
  215. "is_key_on", &EntityManager::IsKeyOn,
  216. "is_key_off", &EntityManager::IsKeyOff,
  217. "set_entity_to_character", &EntityManager::SetEntityToCharacter
  218. );
  219. // Commands for the battle manager.
  220. lua.new_usertype<BattleManager>(
  221. "BattleManager",
  222. "start_battle", &BattleManager::StartBattle,
  223. "end_battle", &BattleManager::EndBattle,
  224. "get_enemy_count", &BattleManager::ScriptGetEnemyCount,
  225. "get_enemy", &BattleManager::ScriptGetEnemy,
  226. "add_attack_model", &BattleManager::ScriptAddAttackModel,
  227. "add_effect_model", &BattleManager::ScriptAddEffectModel,
  228. "remove_effect_model", &BattleManager::ScriptRemoveEffectModel,
  229. "has_attack", &BattleManager::HasAttackData,
  230. "set_camera", &BattleManager::ScriptSetCamera,
  231. "set_camera_position", &BattleManager::ScriptSetCameraPosition,
  232. "get_camera", &BattleManager::ScriptGetCamera,
  233. "create_dynamic_mesh", &BattleManager::ScriptCreateDynamicMesh,
  234. "set_dynamic_mesh", &BattleManager::ScriptSetDynamicMesh,
  235. "remove_dynamic_mesh", &BattleManager::ScriptRemoveDynamicMesh,
  236. "get_layout", &BattleManager::ScriptGetLayout,
  237. "get_attack", [](BattleManager& manager, const int id, sol::this_state state) -> sol::object{
  238. sol::state_view view(state);
  239. const AttackData* attack = manager.GetAttackData(id);
  240. if (attack == nullptr) return sol::make_object(view, sol::nil);
  241. sol::table result = view.create_table();
  242. result["id"] = attack->id;
  243. result["name"] = attack->name;
  244. result["mp"] = attack->mp;
  245. result["reflectable"] = attack->reflectable;
  246. sol::table damage = view.create_table();
  247. for (const auto& p : attack->damage) damage[p.first] = p.second;
  248. result["damage"] = damage;
  249. sol::table target = view.create_table();
  250. for (const auto& p : attack->target) target[p.first] = p.second;
  251. result["target"] = target;
  252. sol::table animation = view.create_table();
  253. for (const auto& p : attack->animation) animation[p.first] = p.second;
  254. result["animation"] = animation;
  255. sol::table effects = view.create_table();
  256. int e = 1;
  257. for (const auto& effect : attack->effects){
  258. sol::table entry = view.create_table();
  259. entry["id"] = effect.id;
  260. entry["chance"] = effect.chance;
  261. entry["mode"] = effect.mode;
  262. effects[e ++] = entry;
  263. }
  264. result["effects"] = effects;
  265. sol::table elements = view.create_table();
  266. int n = 1;
  267. for (int element : attack->elements) elements[n ++] = element;
  268. result["elements"] = elements;
  269. return result;
  270. },
  271. "get_next_formation_id", &BattleManager::GetNextFormationId,
  272. "set_mode", &BattleManager::ScriptSetMode,
  273. "get_mode", &BattleManager::GetMode,
  274. "get_formation_id", &BattleManager::GetFormationId,
  275. "get_escape_difficulty", &BattleManager::GetEscapeDifficulty,
  276. "is_preemptive_allowed", &BattleManager::IsPreemptiveAllowed,
  277. "show_victory_pose", &BattleManager::ShowVictoryPose,
  278. "show_spoils", &BattleManager::ShowSpoils,
  279. "set_enemy_visible", &BattleManager::ScriptSetEnemyVisible,
  280. "get_enemy_entity_name", &BattleManager::ScriptGetEnemyEntityName,
  281. "get_party_entity_name", &BattleManager::ScriptGetPartyEntityName,
  282. "get_party_animation_prefix", &BattleManager::ScriptGetPartyAnimationPrefix,
  283. "get_party_model_name", &BattleManager::ScriptGetPartyModelName
  284. );
  285. // Commands for enemy handling.
  286. lua.new_usertype<Enemy>(
  287. "Enemy",
  288. "get_id", &Enemy::GetId,
  289. "get_name", &Enemy::GetName,
  290. "get_level", &Enemy::GetLevel,
  291. "get_ap", &Enemy::GetAp,
  292. "get_exp", &Enemy::GetExp,
  293. "get_money", &Enemy::GetMoney,
  294. "get_str", &Enemy::GetStr,
  295. "get_def", &Enemy::GetDef,
  296. "get_mag", &Enemy::GetMag,
  297. "get_spr", &Enemy::GetSpr,
  298. "get_dex", &Enemy::GetDex,
  299. "get_lck", &Enemy::GetLck,
  300. "get_eva", &Enemy::GetEva,
  301. "get_meva", &Enemy::GetMeva,
  302. "get_hp", &Enemy::GetHp,
  303. "get_hp_max", &Enemy::GetHpMax,
  304. "get_mp", &Enemy::GetMp,
  305. "get_mp_max", &Enemy::GetMpMax,
  306. "get_position", &Enemy::ScriptGetPos,
  307. "is_front", &Enemy::IsFront,
  308. "is_visible", &Enemy::IsVisible,
  309. "is_targeteable", &Enemy::IsTargeteable,
  310. "is_active", &Enemy::IsActive,
  311. "get_attack_count", &Enemy::ScriptGetAttackCount,
  312. "get_attack", &Enemy::ScriptGetAttack,
  313. "get_camera_for_attack", &Enemy::ScriptGetCameraForAttack,
  314. "get_drop_count", &Enemy::ScriptGetDropCount,
  315. "get_animation_count", &Enemy::ScriptGetAnimationCount,
  316. "get_attack_animation", &Enemy::ScriptGetAttackAnimation,
  317. "get_element_count", &Enemy::ScriptGetElementCount,
  318. "get_ai_script", &Enemy::ScriptGetAiScript,
  319. "get_immunity_count", &Enemy::ScriptGetImmunityCount,
  320. "get_immunity", &Enemy::ScriptGetImmunity,
  321. "get_immunity_rate", &Enemy::ScriptGetImmunityRate,
  322. "get_element", &Enemy::ScriptGetElement,
  323. "get_element_factor", &Enemy::ScriptGetElementFactor,
  324. "get_animation", &Enemy::ScriptGetAnimation,
  325. "get_model_prefix", &Enemy::ScriptGetModelPrefix,
  326. "get_model", &Enemy::GetModel,
  327. "get_drop_id", &Enemy::ScriptGetDropId,
  328. "get_drop_rate", &Enemy::ScriptGetDropRate,
  329. "get_steal_count", &Enemy::ScriptGetStealCount,
  330. "get_steal_id", &Enemy::ScriptGetStealId,
  331. "get_steal_rate", &Enemy::ScriptGetStealRate,
  332. "get_morph", [](const Enemy& enemy){return static_cast<int>(enemy.GetMorph());},
  333. "get_manip_count", [](const Enemy& enemy){return static_cast<int>(enemy.GetManipulateAttacks().size());},
  334. "get_manip_attack", [](const Enemy& enemy, const int index){
  335. const std::vector<unsigned int> attacks = enemy.GetManipulateAttacks();
  336. if (index < 0 || index >= static_cast<int>(attacks.size())) return -1;
  337. return static_cast<int>(attacks[index]);
  338. }
  339. // TODO: Implement cover flags.
  340. // TODO: Implement immunities
  341. // TODO: Implement elements
  342. // TODO: Implement stealable items
  343. // TODO: Implement manipulability status and attacks.
  344. );
  345. // Commands for the audio manager.
  346. lua.new_usertype<AudioManager>(
  347. "AudioManager",
  348. "play_music", &AudioManager::ScriptPlayMusic,
  349. "play_sound", sol::overload(
  350. sol::resolve<void(const char*)>(&AudioManager::ScriptPlaySound),
  351. sol::resolve<void(const char*, const int)>(&AudioManager::ScriptPlaySound)
  352. ),
  353. "play_sounds", &AudioManager::ScriptPlaySounds,
  354. "get_track_id", &AudioManager::ScriptGetTrack,
  355. "get_battle_track_id", &AudioManager::ScriptGetBattleTrack,
  356. "set_battle_track_id", &AudioManager::ScriptSetBattleTrack,
  357. "play_music_once", &AudioManager::ScriptPlayMusicOnce,
  358. "set_music_volume", &AudioManager::ScriptSetMusicVolume,
  359. "set_sound_volume", &AudioManager::ScriptSetSoundVolume
  360. );
  361. // Commands for the input manager (controller settings).
  362. lua.new_usertype<InputManager>(
  363. "InputManager",
  364. "set_game_event_keys", &InputManager::ScriptSetGameEventKeys,
  365. "get_game_event_keys", &InputManager::ScriptGetGameEventKeys,
  366. "get_default_game_event_keys", &InputManager::ScriptGetDefaultGameEventKeys,
  367. "capture_next_key", &InputManager::ScriptCaptureNextKey
  368. );
  369. // Commands for the camera manager.
  370. lua.new_usertype<CameraManager>(
  371. "CameraManager",
  372. "set_camera", &CameraManager::ScriptSetCamera,
  373. "project_to_ui", &CameraManager::ScriptProjectToUi
  374. );
  375. // Commands for the savemap handler.
  376. lua.new_usertype<SavemapHandler>(
  377. "SavemapHandler",
  378. "release", &SavemapHandler::Release,
  379. "get_current_savemap", &SavemapHandler::GetCurrentSavemap,
  380. "get_savemap", &SavemapHandler::GetSavemap,
  381. "set_data", &SavemapHandler::SetData,
  382. "set_control_key", &SavemapHandler::SetControlKey,
  383. "set_window_colours", &SavemapHandler::SetWindowColours,
  384. "set_money", &SavemapHandler::SetMoney,
  385. "set_game_time", &SavemapHandler::SetGameTime,
  386. "set_countdown_time", &SavemapHandler::SetCountdownTime,
  387. "set_key_item", &SavemapHandler::SetKeyItem,
  388. "set_party", &SavemapHandler::SetParty,
  389. "set_item", &SavemapHandler::SetItem,
  390. "set_materia", &SavemapHandler::SetMateria,
  391. "set_e_skill_materia", &SavemapHandler::SetESkillMateria,
  392. "set_materia_stash", &SavemapHandler::SetMateriaStash,
  393. "set_e_skill_materia_stash", &SavemapHandler::SetESkillMateriaStash,
  394. "set_location", &SavemapHandler::SetLocation,
  395. "set_setting", &SavemapHandler::SetSetting,
  396. "set_character_info", &SavemapHandler::SetCharacterInfo,
  397. "set_character_stat", &SavemapHandler::SetCharacterStat,
  398. "set_character_limit_learned", &SavemapHandler::SetCharacterLimitLearned,
  399. "set_character_materia", &SavemapHandler::SetCharacterMateria,
  400. "set_character_e_skill_materia", &SavemapHandler::SetCharacterESkillMateria,
  401. "set_character_status", &SavemapHandler::SetCharacterStatus,
  402. "save", sol::resolve<bool(unsigned int, bool)>(&SavemapHandler::Save),
  403. "is_slot_empty", &SavemapHandler::IsSlotEmpty,
  404. "get_slot_control_key", sol::overload(
  405. &SavemapHandler::GetSlotControlKey,
  406. // Registered under the same name in the original bindings.
  407. &SavemapHandler::GetSlotWindowCornerColourComponent
  408. ),
  409. "get_slot_window_colour", &SavemapHandler::GetSlotWindowCornerColourComponent,
  410. "is_slot_setting_set", &SavemapHandler::IsSlotSettingSet,
  411. "get_slot_setting", &SavemapHandler::GetSlotSetting,
  412. "get_slot_money", &SavemapHandler::GetSlotMoney,
  413. "get_slot_game_time", &SavemapHandler::GetSlotGameTime,
  414. "get_slot_countdown_time", &SavemapHandler::GetSlotCountdownTime,
  415. "get_slot_party_member", &SavemapHandler::GetSlotPartyMember,
  416. "get_slot_item_at_pos_id", &SavemapHandler::GetSlotItemAtPosId,
  417. "get_slot_item_at_pos_qty", &SavemapHandler::GetSlotItemAtPosQty,
  418. "get_slot_key_item", &SavemapHandler::GetSlotKeyItem,
  419. "get_slot_materia_at_pos_id", &SavemapHandler::GetSlotMateriaAtPosId,
  420. "get_slot_materia_at_pos_ap", &SavemapHandler::GetSlotMateriaAtPosAp,
  421. "is_slot_materia_at_pos_e_skill", &SavemapHandler::IsSlotMateriaAtPosESkill,
  422. "is_slot_materia_at_pos_e_skill_learned",
  423. &SavemapHandler::IsSlotMateriaAtPosESkillLearned,
  424. "get_slot_stash_at_pos_id", &SavemapHandler::GetSlotStashAtPosId,
  425. "get_slot_stash_at_pos_ap", &SavemapHandler::GetSlotStashAtPosAp,
  426. "is_slot_stash_at_pos_e_skill", &SavemapHandler::IsSlotStashAtPosESkill,
  427. "is_slot_stash_at_pos_e_skill_learned",
  428. &SavemapHandler::IsSlotStashAtPosESkillLearned,
  429. "get_slot_location_x", &SavemapHandler::GetSlotLocationX,
  430. "get_slot_location_y", &SavemapHandler::GetSlotLocationY,
  431. "get_slot_location_z", &SavemapHandler::GetSlotLocationZ,
  432. "get_slot_location_triangle", &SavemapHandler::GetSlotLocationTriangle,
  433. "get_slot_location_angle", &SavemapHandler::GetSlotLocationAngle,
  434. "get_slot_location_field", &SavemapHandler::GetSlotLocationField,
  435. "get_slot_location_name", &SavemapHandler::GetSlotLocationName,
  436. "get_slot_character_char_id", &SavemapHandler::GetSlotCharacterCharId,
  437. "get_slot_character_name", &SavemapHandler::GetSlotCharacterName,
  438. "get_slot_character_level", &SavemapHandler::GetSlotCharacterLevel,
  439. "get_slot_character_kills", &SavemapHandler::GetSlotCharacterKills,
  440. "is_slot_character_enabled", &SavemapHandler::IsSlotCharacterEnabled,
  441. "is_slot_character_locked", &SavemapHandler::IsSlotCharacterLocked,
  442. "is_slot_character_back_row", &SavemapHandler::IsSlotCharacterBackRow,
  443. "get_slot_character_exp", &SavemapHandler::GetSlotCharacterExp,
  444. "get_slot_character_exp_to_next", &SavemapHandler::GetSlotCharacterExpToNext,
  445. "get_slot_character_limit_level", &SavemapHandler::GetSlotCharacterLimitLevel,
  446. "get_slot_character_limit_bar", &SavemapHandler::GetSlotCharacterLimitBar,
  447. "get_slot_character_weapon_id", &SavemapHandler::GetSlotCharacterWeaponId,
  448. "get_slot_character_armor_id", &SavemapHandler::GetSlotCharacterArmorId,
  449. "get_slot_character_accessory_id", &SavemapHandler::GetSlotCharacterAccessoryId,
  450. "get_slot_character_stat_base", &SavemapHandler::GetSlotCharacterStatBase,
  451. "get_slot_character_stat_extra", &SavemapHandler::GetSlotCharacterStatExtra,
  452. "get_slot_character_limit_uses", &SavemapHandler::GetSlotCharacterLimitUses,
  453. "is_slot_character_limit_learned", &SavemapHandler::IsSlotCharacterLimitLearned,
  454. "get_slot_character_materia_id", &SavemapHandler::GetSlotCharacterMateriaId,
  455. "get_slot_character_materia_ap", &SavemapHandler::GetSlotCharacterMateriaAp,
  456. "get_slot_character_materia_e_skill", &SavemapHandler::IsSlotCharacterMateriaESkill,
  457. "get_slot_character_materia_e_skill_learned",
  458. &SavemapHandler::IsSlotCharacterMateriaESkillLearned,
  459. "get_slot_data", &SavemapHandler::GetSlotData
  460. );
  461. // 2D background and camera commands
  462. lua.new_usertype<Background2D>(
  463. "Background2D",
  464. "autoscroll_to_entity", &Background2D::ScriptAutoScrollToEntity,
  465. "scroll_to_player", &Background2D::ScriptScrollToPlayer,
  466. "scroll_to_entity", &Background2D::ScriptScrollToEntity,
  467. "scroll_to_position", &Background2D::ScriptScrollToPosition,
  468. "offset", &Background2D::ScriptOffset,
  469. "area_on", &Background2D::ScriptAreaOn,
  470. "area_off", &Background2D::ScriptAreaOff,
  471. "area_clear", &Background2D::ScriptAreaClear,
  472. "shake", &Background2D::ScriptShake,
  473. "set_layer_parallax", &Background2D::ScriptSetLayerParallax,
  474. "set_layer_scroll", &Background2D::ScriptSetLayerScroll,
  475. "play_animation_looped", &Background2D::ScriptPlayAnimationLooped,
  476. "play_animation_once", &Background2D::ScriptPlayAnimationOnce
  477. );
  478. // Coloured fades of the screen
  479. lua.new_usertype<ScreenFade>(
  480. "ScreenFade",
  481. "fade", &ScreenFade::ScriptFade,
  482. "nfade", &ScreenFade::ScriptNFade
  483. );
  484. // Movies
  485. lua.new_usertype<MoviePlayer>(
  486. "MoviePlayer",
  487. "set", &MoviePlayer::ScriptSet,
  488. "stop", &MoviePlayer::ScriptStop,
  489. "get_frame", &MoviePlayer::ScriptGetFrame,
  490. "is_playing", &MoviePlayer::ScriptIsPlaying
  491. );
  492. sol::table movie_player_type = lua["MoviePlayer"];
  493. BindYielding(movie_player_type, "play", &MoviePlayer::ScriptPlay);
  494. sol::table screen_fade_type = lua["ScreenFade"];
  495. BindYielding(screen_fade_type, "wait", &ScreenFade::ScriptWait);
  496. sol::table background_type = lua["Background2D"];
  497. BindYielding(background_type, "scroll_sync", &Background2D::ScriptScrollSync);
  498. BindYielding(background_type, "animation_sync", &Background2D::ScriptAnimationSync);
  499. background_type["NONE"] = AT_NONE;
  500. background_type["LINEAR"] = AT_LINEAR;
  501. background_type["SMOOTH"] = AT_SMOOTH;
  502. // Walkmesh commands
  503. lua.new_usertype<Walkmesh>(
  504. "Walkmesh",
  505. "lock_walkmesh", &Walkmesh::LockWalkmesh,
  506. "is_locked", &Walkmesh::IsLocked
  507. );
  508. // Text handler commands
  509. lua.new_usertype<TextHandler>(
  510. "TextHandler",
  511. "set_character_name", &TextHandler::SetCharacterName,
  512. "set_party", &TextHandler::SetParty
  513. );
  514. // Dialog commands
  515. lua.new_usertype<DialogsManager>(
  516. "Dialog",
  517. "dialog_open", &DialogsManager::OpenDialog,
  518. "set_numeric", &DialogsManager::SetNumeric,
  519. "update_timer", &DialogsManager::UpdateTimer,
  520. "set_mode", &DialogsManager::SetMode,
  521. "dialog_set_text", &DialogsManager::SetText,
  522. "show_message", &DialogsManager::ShowScriptMessage,
  523. "dialog_close", &DialogsManager::Hide,
  524. "set_variable", &DialogsManager::SetVariable,
  525. "set_clickable", &DialogsManager::SetClickable,
  526. "set_cursor", &DialogsManager::SetCursor,
  527. "get_cursor", &DialogsManager::GetCursor,
  528. "set_map_name", &DialogsManager::ScriptSetMapName,
  529. "get_map_name", &DialogsManager::GetMapName
  530. );
  531. sol::table dialog_type = lua["Dialog"];
  532. BindYielding(dialog_type, "dialog_wait_for_close", &DialogsManager::Sync);
  533. dialog_type["SOLID"] = MSL_SOLID;
  534. dialog_type["TRANSPARENT"] = MSL_TRANSPARENT;
  535. dialog_type["NONE"] = MSL_NONE;
  536. // UI widget commands
  537. lua.new_usertype<UiWidget>(
  538. "UiWidget",
  539. "set_visible", &UiWidget::SetVisible,
  540. "is_visible", &UiWidget::IsVisible,
  541. "play_animation", sol::overload(
  542. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimation),
  543. sol::resolve<void(const char*, const float, const float)>(
  544. &UiWidget::ScriptPlayAnimation
  545. )
  546. ),
  547. "play_animation_stop", sol::overload(
  548. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimationStop),
  549. sol::resolve<void(const char*, const float, const float)>(
  550. &UiWidget::ScriptPlayAnimationStop
  551. )
  552. ),
  553. "set_default_animation", &UiWidget::ScriptSetDefaultAnimation,
  554. "set_colour", &UiWidget::SetColour,
  555. "set_colours", &UiWidget::SetColours,
  556. "set_alpha", &UiWidget::SetAlpha,
  557. "set_x", &UiWidget::SetX,
  558. "set_y", &UiWidget::SetY,
  559. "set_z", &UiWidget::SetZ,
  560. "get_width", &UiWidget::ScriptGetWidth,
  561. "set_width", sol::overload(&UiWidget::ScriptSetWidth, &UiWidget::SetWidth),
  562. "get_height", &UiWidget::ScriptGetHeight,
  563. "set_height", sol::overload(&UiWidget::ScriptSetHeight, &UiWidget::SetHeight),
  564. "set_text", &UiWidget::SetText,
  565. "set_image", &UiWidget::SetImage,
  566. "set_image_region", &UiWidget::SetImageRegion,
  567. "set_additive", &UiWidget::SetAdditive
  568. );
  569. sol::table ui_widget_type = lua["UiWidget"];
  570. BindYielding(ui_widget_type, "animation_sync", &UiWidget::ScriptAnimationSync);
  571. // UI manager commands. Use to get a specific widget.
  572. lua.new_usertype<UiManager>(
  573. "UiManager",
  574. "get_widget", &UiManager::ScriptGetWidget,
  575. "set_window_colours", &UiManager::SetWindowColours
  576. );
  577. // Timer command. To show a in-game timer.
  578. lua.new_usertype<Timer>(
  579. "Timer",
  580. "get_game_time_total", &Timer::GetGameTimeTotal,
  581. "set_timer", &Timer::SetGameTimer,
  582. "get_timer", &Timer::GetGameTimer
  583. );
  584. // Commands that control script execution
  585. lua.new_usertype<ScriptManager>(
  586. "Script",
  587. "request", sol::resolve<void(
  588. const ScriptManager::Type, const char*, const char*, const int
  589. )>(&ScriptManager::ScriptRequest)
  590. );
  591. sol::table script_type = lua["Script"];
  592. BindYielding(script_type, "wait", &ScriptManager::ScriptWait);
  593. BindYielding(script_type, "request_start_sync", &ScriptManager::ScriptRequestStartSync);
  594. BindYielding(script_type, "request_end_sync", &ScriptManager::ScriptRequestEndSync);
  595. script_type["SYSTEM"] = ScriptManager::SYSTEM;
  596. script_type["ENTITY"] = ScriptManager::ENTITY;
  597. script_type["UI"] = ScriptManager::UI;
  598. // Commands to initiate modules
  599. lua.new_usertype<VGears::WorldmapModule>(
  600. "world_map_module",
  601. "init", &VGears::WorldmapModule::Init,
  602. "suspend", &VGears::WorldmapModule::Suspend,
  603. "clear_vehicle_terrains", &VGears::WorldmapModule::ClearVehicleTerrains,
  604. "add_vehicle_terrain", &VGears::WorldmapModule::AddVehicleTerrain,
  605. "get_terrain_type_under_entity", &VGears::WorldmapModule::GetTerrainTypeUnderEntity,
  606. "get_terrain_triangle_under_entity", &VGears::WorldmapModule::GetTerrainTriangleUnderEntity,
  607. "unboard_vehicle", &VGears::WorldmapModule::UnboardVehicle,
  608. "set_encounters_locked", &VGears::WorldmapModule::SetEncountersLocked
  609. );
  610. // Register all command handlers
  611. lua["input_manager"] = InputManager::getSingletonPtr();
  612. lua["camera_manager"] = CameraManager::getSingletonPtr();
  613. lua["entity_manager"] = EntityManager::getSingletonPtr();
  614. lua["battle_manager"] = BattleManager::getSingletonPtr();
  615. lua["audio_manager"] = AudioManager::getSingletonPtr();
  616. lua["savemap_manager"] = SavemapHandler::getSingletonPtr();
  617. lua["background2d"] = EntityManager::getSingletonPtr()->GetBackground2D();
  618. lua["screen_fade"] = EntityManager::getSingletonPtr()->GetScreenFade();
  619. lua["movie_player"] = EntityManager::getSingletonPtr()->GetMoviePlayer();
  620. lua["walkmesh"] = EntityManager::getSingletonPtr()->GetWalkmesh();
  621. lua["text_manager"] = TextHandler::getSingletonPtr();
  622. lua["dialog"] = DialogsManager::getSingletonPtr();
  623. lua["ui_manager"] = UiManager::getSingletonPtr();
  624. lua["world_map_module"] = VGears::WorldmapModule::getSingletonPtr();
  625. lua["timer"] = Timer::getSingletonPtr();
  626. lua["script"] = this;
  627. }