ScriptManagerBinds.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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 "engine/ui/Console.h"
  18. #include "common/Logger.h"
  19. #include "engine/graphics/CameraManager.h"
  20. #include "core/Enemy.h"
  21. #include "engine/entity/Entity.h"
  22. #include "engine/entity/EntityManager.h"
  23. #include "core/BattleManager.h"
  24. #include "engine/audio/AudioManager.h"
  25. #include "engine/input/InputManager.h"
  26. #include "core/SavemapHandler.h"
  27. #include "core/Timer.h"
  28. #include "engine/ui/UiManager.h"
  29. #include "engine/ui/UiWidget.h"
  30. #include "core/XmlMapFile.h"
  31. #include "core/XmlMapsFile.h"
  32. #include "engine/ui/DialogsManager.h"
  33. #include "engine/ui/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. "get_bone_end", &Entity::ScriptGetBoneEnd,
  133. "attach_model", sol::overload(
  134. [](Entity& entity, const char* model, const int bone){
  135. return entity.ScriptAttachModel(model, bone, 0.0f, 0.0f, 0.0f);
  136. },
  137. &Entity::ScriptAttachModel
  138. ),
  139. "is_visible", &Entity::IsVisible,
  140. "set_move_auto_speed", &Entity::SetMoveAutoSpeed,
  141. "get_move_auto_speed", &Entity::GetMoveAutoSpeed,
  142. "get_move_triangle_id", &Entity::GetMoveTriangleId,
  143. "set_move_triangle_id", &Entity::SetMoveTriangleId,
  144. "move_auto_rotation", &Entity::SetMoveAutoRotation,
  145. "move_auto_animation", &Entity::SetMoveAutoAnimation,
  146. "set_move_animations", &Entity::SetMoveAnimations,
  147. "move_to_position", &Entity::ScriptMoveToPosition,
  148. "move_to_entity", &Entity::ScriptMoveToEntity,
  149. "linear_to_position", &Entity::ScriptLinearToPosition,
  150. "jump_to_position", &Entity::ScriptJumpToPosition,
  151. "offset_to_position", &Entity::ScriptOffsetToPosition,
  152. "turn_to_entity", &Entity::ScriptTurnToEntity,
  153. "face_entity", &Entity::ScriptFaceEntity,
  154. "turn_to_direction", &Entity::ScriptTurnToDirection,
  155. "set_animation_speed", &Entity::ScriptSetAnimationSpeed,
  156. "play_animation", sol::overload(
  157. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimation),
  158. sol::resolve<void(const char*, const float, const float)>(&Entity::ScriptPlayAnimation)
  159. ),
  160. "play_animation_stop", sol::overload(
  161. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimationStop),
  162. sol::resolve<void(const char*, const float, const float)>(
  163. &Entity::ScriptPlayAnimationStop
  164. )
  165. ),
  166. "get_animation_length", &Entity::ScriptGetAnimationLength,
  167. "get_animation_count", &Entity::GetAnimationCount,
  168. "get_animation_name", &Entity::GetAnimationName,
  169. "play_animation_index", &Entity::ScriptPlayAnimationIndex,
  170. "set_default_animation", &Entity::ScriptSetDefaultAnimation,
  171. "set_default_animation_index", &Entity::ScriptSetDefaultAnimationIndex
  172. );
  173. sol::table entity_type = lua["Entity"];
  174. BindYielding(entity_type, "move_sync", &Entity::ScriptMoveSync);
  175. BindYielding(entity_type, "linear_sync", &Entity::ScriptLinearSync);
  176. BindYielding(entity_type, "jump_sync", &Entity::ScriptJumpSync);
  177. BindYielding(entity_type, "offset_sync", &Entity::ScriptOffsetSync);
  178. BindYielding(entity_type, "turn_sync", &Entity::ScriptTurnSync);
  179. BindYielding(entity_type, "animation_sync", &Entity::ScriptAnimationSync);
  180. entity_type["BLEND_NORMAL"] = Entity::BLEND_NORMAL;
  181. entity_type["BLEND_ADDITIVE"] = Entity::BLEND_ADDITIVE;
  182. entity_type["BLEND_ALPHA"] = Entity::BLEND_ALPHA;
  183. entity_type["NONE"] = AT_NONE;
  184. entity_type["LINEAR"] = AT_LINEAR;
  185. entity_type["SMOOTH"] = AT_SMOOTH;
  186. entity_type["CLOCKWISE"] = TD_CLOCKWISE;
  187. entity_type["ANTICLOCKWISE"] = TD_ANTICLOCKWISE;
  188. entity_type["CLOSEST"] = TD_CLOSEST;
  189. entity_type["UP_TO_DOWN"] = LM_UP_TO_DOWN;
  190. entity_type["DOWN_TO_UP"] = LM_DOWN_TO_UP;
  191. entity_type["LEFT_TO_RIGHT"] = LM_LEFT_TO_RIGHT;
  192. entity_type["RIGHT_TO_LEFT"] = LM_RIGHT_TO_LEFT;
  193. // Entity individual point commands
  194. lua.new_usertype<EntityPoint>(
  195. "EntityPoint",
  196. "get_position", &EntityPoint::ScriptGetPosition,
  197. "get_rotation", &EntityPoint::ScriptGetRotation
  198. );
  199. // Commands for the entity manager, not related to any particular entity.
  200. lua.new_usertype<EntityManager>(
  201. "EntityManager",
  202. "set_paused", &EntityManager::ScriptSetPaused,
  203. "add_entity", &EntityManager::ScriptAddEntity,
  204. "add_entity_script", &EntityManager::ScriptAddEntityScript,
  205. "get_entity", &EntityManager::ScriptGetEntity,
  206. "get_entity_from_index", &EntityManager::GetEntityFromIndex,
  207. "get_entity_from_character_id", &EntityManager::GetEntityFromCharacterId,
  208. "get_entity_point", &EntityManager::ScriptGetEntityPoint,
  209. "set_player_entity", &EntityManager::ScriptSetPlayerEntity,
  210. "place_player_at_field_entry", &EntityManager::ScriptPlacePlayerAtFieldEntry,
  211. "get_player_entity", &EntityManager::ScriptGetPlayerEntity,
  212. "unset_player_entity", &EntityManager::ScriptUnsetPlayerEntity,
  213. "player_lock", &EntityManager::ScriptPlayerLock,
  214. "set_player_slip", &EntityManager::ScriptSetPlayerSlip,
  215. "is_player_locked", &EntityManager::IsPlayerLocked,
  216. "set_player_default_run", &EntityManager::SetPlayerDefaultRun,
  217. "random_encounters_on", &EntityManager::SetRandomEncounters,
  218. "set_encounter_table", &EntityManager::ScriptSetEncounterTable,
  219. "roll_encounter_battle", &EntityManager::ScriptRollEncounterBattle,
  220. "is_key_on", &EntityManager::IsKeyOn,
  221. "is_key_off", &EntityManager::IsKeyOff,
  222. "is_start_key_read", &EntityManager::IsStartKeyRead,
  223. "set_line", &EntityManager::ScriptSetLine,
  224. "set_entity_to_character", &EntityManager::SetEntityToCharacter
  225. );
  226. // Commands for the battle manager.
  227. lua.new_usertype<BattleManager>(
  228. "BattleManager",
  229. "start_battle", &BattleManager::StartBattle,
  230. "end_battle", &BattleManager::EndBattle,
  231. "get_enemy_count", &BattleManager::ScriptGetEnemyCount,
  232. "get_enemy", &BattleManager::ScriptGetEnemy,
  233. "add_attack_model", &BattleManager::ScriptAddAttackModel,
  234. "add_effect_model", &BattleManager::ScriptAddEffectModel,
  235. "remove_effect_model", &BattleManager::ScriptRemoveEffectModel,
  236. "has_attack", &BattleManager::HasAttackData,
  237. "set_camera", &BattleManager::ScriptSetCamera,
  238. "set_camera_position", &BattleManager::ScriptSetCameraPosition,
  239. "get_camera", &BattleManager::ScriptGetCamera,
  240. "create_dynamic_mesh", &BattleManager::ScriptCreateDynamicMesh,
  241. "set_dynamic_mesh", &BattleManager::ScriptSetDynamicMesh,
  242. "remove_dynamic_mesh", &BattleManager::ScriptRemoveDynamicMesh,
  243. "get_layout", &BattleManager::ScriptGetLayout,
  244. "get_intro_camera", &BattleManager::ScriptGetIntroCamera,
  245. "get_attack", [](BattleManager& manager, const int id, sol::this_state state) -> sol::object{
  246. sol::state_view view(state);
  247. const AttackData* attack = manager.GetAttackData(id);
  248. if (attack == nullptr) return sol::make_object(view, sol::nil);
  249. sol::table result = view.create_table();
  250. result["id"] = attack->id;
  251. result["name"] = attack->name;
  252. result["mp"] = attack->mp;
  253. result["reflectable"] = attack->reflectable;
  254. sol::table damage = view.create_table();
  255. for (const auto& p : attack->damage) damage[p.first] = p.second;
  256. result["damage"] = damage;
  257. sol::table target = view.create_table();
  258. for (const auto& p : attack->target) target[p.first] = p.second;
  259. result["target"] = target;
  260. sol::table animation = view.create_table();
  261. for (const auto& p : attack->animation) animation[p.first] = p.second;
  262. result["animation"] = animation;
  263. sol::table effects = view.create_table();
  264. int e = 1;
  265. for (const auto& effect : attack->effects){
  266. sol::table entry = view.create_table();
  267. entry["id"] = effect.id;
  268. entry["chance"] = effect.chance;
  269. entry["mode"] = effect.mode;
  270. effects[e ++] = entry;
  271. }
  272. result["effects"] = effects;
  273. sol::table elements = view.create_table();
  274. int n = 1;
  275. for (int element : attack->elements) elements[n ++] = element;
  276. result["elements"] = elements;
  277. return result;
  278. },
  279. "get_next_formation_id", &BattleManager::GetNextFormationId,
  280. "set_mode", &BattleManager::ScriptSetMode,
  281. "get_mode", &BattleManager::GetMode,
  282. "get_formation_id", &BattleManager::GetFormationId,
  283. "get_escape_difficulty", &BattleManager::GetEscapeDifficulty,
  284. "is_preemptive_allowed", &BattleManager::IsPreemptiveAllowed,
  285. "show_victory_pose", &BattleManager::ShowVictoryPose,
  286. "show_spoils", &BattleManager::ShowSpoils,
  287. "set_enemy_visible", &BattleManager::ScriptSetEnemyVisible,
  288. "get_enemy_entity_name", &BattleManager::ScriptGetEnemyEntityName,
  289. "get_party_entity_name", &BattleManager::ScriptGetPartyEntityName,
  290. "get_party_animation_prefix", &BattleManager::ScriptGetPartyAnimationPrefix,
  291. "get_party_model_name", &BattleManager::ScriptGetPartyModelName
  292. );
  293. // Commands for enemy handling.
  294. lua.new_usertype<Enemy>(
  295. "Enemy",
  296. "get_id", &Enemy::GetId,
  297. "get_name", &Enemy::GetName,
  298. "get_level", &Enemy::GetLevel,
  299. "get_ap", &Enemy::GetAp,
  300. "get_exp", &Enemy::GetExp,
  301. "get_money", &Enemy::GetMoney,
  302. "get_str", &Enemy::GetStr,
  303. "get_def", &Enemy::GetDef,
  304. "get_mag", &Enemy::GetMag,
  305. "get_spr", &Enemy::GetSpr,
  306. "get_dex", &Enemy::GetDex,
  307. "get_lck", &Enemy::GetLck,
  308. "get_eva", &Enemy::GetEva,
  309. "get_meva", &Enemy::GetMeva,
  310. "get_hp", &Enemy::GetHp,
  311. "get_hp_max", &Enemy::GetHpMax,
  312. "get_mp", &Enemy::GetMp,
  313. "get_mp_max", &Enemy::GetMpMax,
  314. "get_position", &Enemy::ScriptGetPos,
  315. "is_front", &Enemy::IsFront,
  316. "is_visible", &Enemy::IsVisible,
  317. "is_targeteable", &Enemy::IsTargeteable,
  318. "is_active", &Enemy::IsActive,
  319. "get_attack_count", &Enemy::ScriptGetAttackCount,
  320. "get_attack", &Enemy::ScriptGetAttack,
  321. "get_camera_for_attack", &Enemy::ScriptGetCameraForAttack,
  322. "get_drop_count", &Enemy::ScriptGetDropCount,
  323. "get_animation_count", &Enemy::ScriptGetAnimationCount,
  324. "get_attack_animation", &Enemy::ScriptGetAttackAnimation,
  325. "get_element_count", &Enemy::ScriptGetElementCount,
  326. "get_ai_script", &Enemy::ScriptGetAiScript,
  327. "get_immunity_count", &Enemy::ScriptGetImmunityCount,
  328. "get_immunity", &Enemy::ScriptGetImmunity,
  329. "get_immunity_rate", &Enemy::ScriptGetImmunityRate,
  330. "get_element", &Enemy::ScriptGetElement,
  331. "get_element_factor", &Enemy::ScriptGetElementFactor,
  332. "get_animation", &Enemy::ScriptGetAnimation,
  333. "get_model_prefix", &Enemy::ScriptGetModelPrefix,
  334. "get_model", &Enemy::GetModel,
  335. "get_drop_id", &Enemy::ScriptGetDropId,
  336. "get_drop_rate", &Enemy::ScriptGetDropRate,
  337. "get_steal_count", &Enemy::ScriptGetStealCount,
  338. "get_steal_id", &Enemy::ScriptGetStealId,
  339. "get_steal_rate", &Enemy::ScriptGetStealRate,
  340. "get_morph", [](const Enemy& enemy){return static_cast<int>(enemy.GetMorph());},
  341. "get_manip_count", [](const Enemy& enemy){return static_cast<int>(enemy.GetManipulateAttacks().size());},
  342. "get_manip_attack", [](const Enemy& enemy, const int index){
  343. const std::vector<unsigned int> attacks = enemy.GetManipulateAttacks();
  344. if (index < 0 || index >= static_cast<int>(attacks.size())) return -1;
  345. return static_cast<int>(attacks[index]);
  346. }
  347. // TODO: Implement cover flags.
  348. // TODO: Implement immunities
  349. // TODO: Implement elements
  350. // TODO: Implement stealable items
  351. // TODO: Implement manipulability status and attacks.
  352. );
  353. // Commands for the audio manager.
  354. lua.new_usertype<AudioManager>(
  355. "AudioManager",
  356. "play_music", &AudioManager::ScriptPlayMusic,
  357. "play_sound", sol::overload(
  358. sol::resolve<void(const char*)>(&AudioManager::ScriptPlaySound),
  359. sol::resolve<void(const char*, const int)>(&AudioManager::ScriptPlaySound)
  360. ),
  361. // The scripts pass nil for the sounds the opcode doesn't use.
  362. "play_sounds", [](
  363. AudioManager& audio, sol::optional<std::string> name1, sol::optional<std::string> name2,
  364. sol::optional<std::string> name3, sol::optional<std::string> name4
  365. ){
  366. if (name1) audio.ScriptPlaySounds(
  367. name1->c_str(), name2 ? name2->c_str() : "", name3 ? name3->c_str() : "",
  368. name4 ? name4->c_str() : ""
  369. );
  370. },
  371. "get_track_id", &AudioManager::ScriptGetTrack,
  372. "get_battle_track_id", &AudioManager::ScriptGetBattleTrack,
  373. "set_battle_track_id", &AudioManager::ScriptSetBattleTrack,
  374. "play_music_once", &AudioManager::ScriptPlayMusicOnce,
  375. "stop_music", &AudioManager::MusicStop,
  376. "is_music_playing", &AudioManager::ScriptIsMusicPlaying,
  377. "set_music_volume", &AudioManager::ScriptSetMusicVolume,
  378. "set_sound_volume", &AudioManager::ScriptSetSoundVolume
  379. );
  380. // Commands for the input manager (controller settings).
  381. lua.new_usertype<InputManager>(
  382. "InputManager",
  383. "set_game_event_keys", &InputManager::ScriptSetGameEventKeys,
  384. "get_game_event_keys", &InputManager::ScriptGetGameEventKeys,
  385. "get_default_game_event_keys", &InputManager::ScriptGetDefaultGameEventKeys,
  386. "capture_next_key", &InputManager::ScriptCaptureNextKey
  387. );
  388. // Commands for the camera manager.
  389. lua.new_usertype<CameraManager>(
  390. "CameraManager",
  391. "set_camera", &CameraManager::ScriptSetCamera,
  392. "project_to_ui", &CameraManager::ScriptProjectToUi
  393. );
  394. // Commands for the savemap handler.
  395. lua.new_usertype<SavemapHandler>(
  396. "SavemapHandler",
  397. "release", &SavemapHandler::Release,
  398. "get_current_savemap", &SavemapHandler::GetCurrentSavemap,
  399. "get_savemap", &SavemapHandler::GetSavemap,
  400. "set_data", &SavemapHandler::SetData,
  401. "set_control_key", &SavemapHandler::SetControlKey,
  402. "set_window_colours", &SavemapHandler::SetWindowColours,
  403. "set_money", &SavemapHandler::SetMoney,
  404. "set_game_time", &SavemapHandler::SetGameTime,
  405. "set_countdown_time", &SavemapHandler::SetCountdownTime,
  406. "set_key_item", &SavemapHandler::SetKeyItem,
  407. "set_party", &SavemapHandler::SetParty,
  408. "set_item", &SavemapHandler::SetItem,
  409. "set_materia", &SavemapHandler::SetMateria,
  410. "set_e_skill_materia", &SavemapHandler::SetESkillMateria,
  411. "set_materia_stash", &SavemapHandler::SetMateriaStash,
  412. "set_e_skill_materia_stash", &SavemapHandler::SetESkillMateriaStash,
  413. "set_location", &SavemapHandler::SetLocation,
  414. "set_setting", &SavemapHandler::SetSetting,
  415. "set_character_info", &SavemapHandler::SetCharacterInfo,
  416. "set_character_stat", &SavemapHandler::SetCharacterStat,
  417. "set_character_limit_learned", &SavemapHandler::SetCharacterLimitLearned,
  418. "set_character_materia", &SavemapHandler::SetCharacterMateria,
  419. "set_character_e_skill_materia", &SavemapHandler::SetCharacterESkillMateria,
  420. "set_character_status", &SavemapHandler::SetCharacterStatus,
  421. "save", sol::resolve<bool(unsigned int, bool)>(&SavemapHandler::Save),
  422. "is_slot_empty", &SavemapHandler::IsSlotEmpty,
  423. "get_slot_control_key", sol::overload(
  424. &SavemapHandler::GetSlotControlKey,
  425. // Registered under the same name in the original bindings.
  426. &SavemapHandler::GetSlotWindowCornerColourComponent
  427. ),
  428. "get_slot_window_colour", &SavemapHandler::GetSlotWindowCornerColourComponent,
  429. "is_slot_setting_set", &SavemapHandler::IsSlotSettingSet,
  430. "get_slot_setting", &SavemapHandler::GetSlotSetting,
  431. "get_slot_money", &SavemapHandler::GetSlotMoney,
  432. "get_slot_game_time", &SavemapHandler::GetSlotGameTime,
  433. "get_slot_countdown_time", &SavemapHandler::GetSlotCountdownTime,
  434. "get_slot_party_member", &SavemapHandler::GetSlotPartyMember,
  435. "get_slot_item_at_pos_id", &SavemapHandler::GetSlotItemAtPosId,
  436. "get_slot_item_at_pos_qty", &SavemapHandler::GetSlotItemAtPosQty,
  437. "get_slot_key_item", &SavemapHandler::GetSlotKeyItem,
  438. "get_slot_materia_at_pos_id", &SavemapHandler::GetSlotMateriaAtPosId,
  439. "get_slot_materia_at_pos_ap", &SavemapHandler::GetSlotMateriaAtPosAp,
  440. "is_slot_materia_at_pos_e_skill", &SavemapHandler::IsSlotMateriaAtPosESkill,
  441. "is_slot_materia_at_pos_e_skill_learned",
  442. &SavemapHandler::IsSlotMateriaAtPosESkillLearned,
  443. "get_slot_stash_at_pos_id", &SavemapHandler::GetSlotStashAtPosId,
  444. "get_slot_stash_at_pos_ap", &SavemapHandler::GetSlotStashAtPosAp,
  445. "is_slot_stash_at_pos_e_skill", &SavemapHandler::IsSlotStashAtPosESkill,
  446. "is_slot_stash_at_pos_e_skill_learned",
  447. &SavemapHandler::IsSlotStashAtPosESkillLearned,
  448. "get_slot_location_x", &SavemapHandler::GetSlotLocationX,
  449. "get_slot_location_y", &SavemapHandler::GetSlotLocationY,
  450. "get_slot_location_z", &SavemapHandler::GetSlotLocationZ,
  451. "get_slot_location_triangle", &SavemapHandler::GetSlotLocationTriangle,
  452. "get_slot_location_angle", &SavemapHandler::GetSlotLocationAngle,
  453. "get_slot_location_field", &SavemapHandler::GetSlotLocationField,
  454. "get_slot_location_name", &SavemapHandler::GetSlotLocationName,
  455. "get_slot_character_char_id", &SavemapHandler::GetSlotCharacterCharId,
  456. "get_slot_character_name", &SavemapHandler::GetSlotCharacterName,
  457. "get_slot_character_level", &SavemapHandler::GetSlotCharacterLevel,
  458. "get_slot_character_kills", &SavemapHandler::GetSlotCharacterKills,
  459. "is_slot_character_enabled", &SavemapHandler::IsSlotCharacterEnabled,
  460. "is_slot_character_locked", &SavemapHandler::IsSlotCharacterLocked,
  461. "is_slot_character_back_row", &SavemapHandler::IsSlotCharacterBackRow,
  462. "get_slot_character_exp", &SavemapHandler::GetSlotCharacterExp,
  463. "get_slot_character_exp_to_next", &SavemapHandler::GetSlotCharacterExpToNext,
  464. "get_slot_character_limit_level", &SavemapHandler::GetSlotCharacterLimitLevel,
  465. "get_slot_character_limit_bar", &SavemapHandler::GetSlotCharacterLimitBar,
  466. "get_slot_character_weapon_id", &SavemapHandler::GetSlotCharacterWeaponId,
  467. "get_slot_character_armor_id", &SavemapHandler::GetSlotCharacterArmorId,
  468. "get_slot_character_accessory_id", &SavemapHandler::GetSlotCharacterAccessoryId,
  469. "get_slot_character_stat_base", &SavemapHandler::GetSlotCharacterStatBase,
  470. "get_slot_character_stat_extra", &SavemapHandler::GetSlotCharacterStatExtra,
  471. "get_slot_character_limit_uses", &SavemapHandler::GetSlotCharacterLimitUses,
  472. "is_slot_character_limit_learned", &SavemapHandler::IsSlotCharacterLimitLearned,
  473. "get_slot_character_materia_id", &SavemapHandler::GetSlotCharacterMateriaId,
  474. "get_slot_character_materia_ap", &SavemapHandler::GetSlotCharacterMateriaAp,
  475. "get_slot_character_materia_e_skill", &SavemapHandler::IsSlotCharacterMateriaESkill,
  476. "get_slot_character_materia_e_skill_learned",
  477. &SavemapHandler::IsSlotCharacterMateriaESkillLearned,
  478. "get_slot_data", &SavemapHandler::GetSlotData
  479. );
  480. // 2D background and camera commands
  481. lua.new_usertype<Background2D>(
  482. "Background2D",
  483. "autoscroll_to_entity", &Background2D::ScriptAutoScrollToEntity,
  484. "scroll_to_player", &Background2D::ScriptScrollToPlayer,
  485. "scroll_to_entity", &Background2D::ScriptScrollToEntity,
  486. "scroll_to_position", &Background2D::ScriptScrollToPosition,
  487. "offset", &Background2D::ScriptOffset,
  488. "area_on", &Background2D::ScriptAreaOn,
  489. "area_off", &Background2D::ScriptAreaOff,
  490. "area_clear", &Background2D::ScriptAreaClear,
  491. "palette_store", &Background2D::ScriptPaletteStore,
  492. "palette_load", &Background2D::ScriptPaletteLoad,
  493. "palette_copy", &Background2D::ScriptPaletteCopy,
  494. "palette_multiply", &Background2D::ScriptPaletteMultiply,
  495. "palette_add", &Background2D::ScriptPaletteAdd,
  496. "shake", &Background2D::ScriptShake,
  497. "set_layer_parallax", &Background2D::ScriptSetLayerParallax,
  498. "set_layer_scroll", &Background2D::ScriptSetLayerScroll,
  499. "play_animation_looped", &Background2D::ScriptPlayAnimationLooped,
  500. "play_animation_once", &Background2D::ScriptPlayAnimationOnce
  501. );
  502. // Coloured fades of the screen
  503. lua.new_usertype<ScreenFade>(
  504. "ScreenFade",
  505. "fade", &ScreenFade::ScriptFade,
  506. "nfade", &ScreenFade::ScriptNFade
  507. );
  508. // Movies
  509. lua.new_usertype<MoviePlayer>(
  510. "MoviePlayer",
  511. "set", &MoviePlayer::ScriptSet,
  512. "stop", &MoviePlayer::ScriptStop,
  513. "use_movie_camera", &MoviePlayer::ScriptUseMovieCamera,
  514. "get_frame", &MoviePlayer::ScriptGetFrame,
  515. "is_playing", &MoviePlayer::ScriptIsPlaying
  516. );
  517. sol::table movie_player_type = lua["MoviePlayer"];
  518. BindYielding(movie_player_type, "play", &MoviePlayer::ScriptPlay);
  519. sol::table screen_fade_type = lua["ScreenFade"];
  520. BindYielding(screen_fade_type, "wait", &ScreenFade::ScriptWait);
  521. sol::table background_type = lua["Background2D"];
  522. BindYielding(background_type, "scroll_sync", &Background2D::ScriptScrollSync);
  523. BindYielding(background_type, "animation_sync", &Background2D::ScriptAnimationSync);
  524. background_type["NONE"] = AT_NONE;
  525. background_type["LINEAR"] = AT_LINEAR;
  526. background_type["SMOOTH"] = AT_SMOOTH;
  527. // Walkmesh commands
  528. lua.new_usertype<Walkmesh>(
  529. "Walkmesh",
  530. "lock_walkmesh", &Walkmesh::LockWalkmesh,
  531. "is_locked", &Walkmesh::IsLocked
  532. );
  533. // Text handler commands
  534. lua.new_usertype<TextHandler>(
  535. "TextHandler",
  536. "set_character_name", &TextHandler::SetCharacterName,
  537. "set_party", &TextHandler::SetParty
  538. );
  539. // Dialog commands
  540. lua.new_usertype<DialogsManager>(
  541. "Dialog",
  542. "dialog_open", &DialogsManager::OpenDialog,
  543. "set_numeric", &DialogsManager::SetNumeric,
  544. "set_number", &DialogsManager::SetNumber,
  545. "update_timer", &DialogsManager::UpdateTimer,
  546. "set_mode", &DialogsManager::SetMode,
  547. "dialog_set_text", &DialogsManager::SetText,
  548. "show_message", &DialogsManager::ShowScriptMessage,
  549. "dialog_close", &DialogsManager::Hide,
  550. "set_variable", &DialogsManager::SetVariable,
  551. "set_clickable", &DialogsManager::SetClickable,
  552. "set_cursor", &DialogsManager::SetCursor,
  553. "get_cursor", &DialogsManager::GetCursor,
  554. "set_map_name", &DialogsManager::ScriptSetMapName,
  555. "get_map_name", &DialogsManager::GetMapName
  556. );
  557. sol::table dialog_type = lua["Dialog"];
  558. BindYielding(dialog_type, "dialog_wait_for_close", &DialogsManager::Sync);
  559. dialog_type["SOLID"] = MSL_SOLID;
  560. dialog_type["TRANSPARENT"] = MSL_TRANSPARENT;
  561. dialog_type["NONE"] = MSL_NONE;
  562. // UI widget commands
  563. lua.new_usertype<UiWidget>(
  564. "UiWidget",
  565. "set_visible", &UiWidget::SetVisible,
  566. "is_visible", &UiWidget::IsVisible,
  567. "play_animation", sol::overload(
  568. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimation),
  569. sol::resolve<void(const char*, const float, const float)>(
  570. &UiWidget::ScriptPlayAnimation
  571. )
  572. ),
  573. "play_animation_stop", sol::overload(
  574. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimationStop),
  575. sol::resolve<void(const char*, const float, const float)>(
  576. &UiWidget::ScriptPlayAnimationStop
  577. )
  578. ),
  579. "set_default_animation", &UiWidget::ScriptSetDefaultAnimation,
  580. "set_colour", &UiWidget::SetColour,
  581. "set_colours", &UiWidget::SetColours,
  582. "set_alpha", &UiWidget::SetAlpha,
  583. "set_x", &UiWidget::SetX,
  584. "set_y", &UiWidget::SetY,
  585. "set_z", &UiWidget::SetZ,
  586. "get_width", &UiWidget::ScriptGetWidth,
  587. "set_width", sol::overload(&UiWidget::ScriptSetWidth, &UiWidget::SetWidth),
  588. "get_height", &UiWidget::ScriptGetHeight,
  589. "set_height", sol::overload(&UiWidget::ScriptSetHeight, &UiWidget::SetHeight),
  590. "set_text", &UiWidget::SetText,
  591. "set_image", &UiWidget::SetImage,
  592. "set_image_region", &UiWidget::SetImageRegion,
  593. "set_additive", &UiWidget::SetAdditive
  594. );
  595. sol::table ui_widget_type = lua["UiWidget"];
  596. BindYielding(ui_widget_type, "animation_sync", &UiWidget::ScriptAnimationSync);
  597. // UI manager commands. Use to get a specific widget.
  598. lua.new_usertype<UiManager>(
  599. "UiManager",
  600. "get_widget", &UiManager::ScriptGetWidget,
  601. "set_window_colours", &UiManager::SetWindowColours
  602. );
  603. // Timer command. To show a in-game timer.
  604. lua.new_usertype<Timer>(
  605. "Timer",
  606. "get_game_time_total", &Timer::GetGameTimeTotal,
  607. "set_timer", &Timer::SetGameTimer,
  608. "get_timer", &Timer::GetGameTimer
  609. );
  610. // Commands that control script execution
  611. lua.new_usertype<ScriptManager>(
  612. "Script",
  613. "request", sol::resolve<void(
  614. const ScriptManager::Type, const char*, const char*, const int
  615. )>(&ScriptManager::ScriptRequest)
  616. );
  617. sol::table script_type = lua["Script"];
  618. BindYielding(script_type, "wait", &ScriptManager::ScriptWait);
  619. BindYielding(script_type, "request_start_sync", &ScriptManager::ScriptRequestStartSync);
  620. BindYielding(script_type, "request_end_sync", &ScriptManager::ScriptRequestEndSync);
  621. script_type["SYSTEM"] = ScriptManager::SYSTEM;
  622. script_type["ENTITY"] = ScriptManager::ENTITY;
  623. script_type["UI"] = ScriptManager::UI;
  624. // Commands to initiate modules
  625. lua.new_usertype<VGears::WorldmapModule>(
  626. "world_map_module",
  627. "init", sol::overload(
  628. [](VGears::WorldmapModule& module){module.Init(0);},
  629. [](VGears::WorldmapModule& module, const int map_id){module.Init(map_id);}
  630. ),
  631. "suspend", &VGears::WorldmapModule::Suspend,
  632. "clear_vehicle_terrains", &VGears::WorldmapModule::ClearVehicleTerrains,
  633. "add_vehicle_terrain", &VGears::WorldmapModule::AddVehicleTerrain,
  634. "get_terrain_type_under_entity", &VGears::WorldmapModule::GetTerrainTypeUnderEntity,
  635. "get_terrain_triangle_under_entity", &VGears::WorldmapModule::GetTerrainTriangleUnderEntity,
  636. "unboard_vehicle", &VGears::WorldmapModule::UnboardVehicle,
  637. "set_encounters_locked", &VGears::WorldmapModule::SetEncountersLocked,
  638. "set_model_orientation", &VGears::WorldmapModule::SetModelOrientation,
  639. "set_model_heading", &VGears::WorldmapModule::SetModelHeading,
  640. "get_model_heading", &VGears::WorldmapModule::GetModelHeading,
  641. "set_model_offset", &VGears::WorldmapModule::SetModelOffset,
  642. "set_entity_altitude", &VGears::WorldmapModule::SetEntityAltitude,
  643. "enter", &VGears::WorldmapModule::Enter,
  644. "set_spawn", &VGears::WorldmapModule::SetSpawn,
  645. "set_speed", &VGears::WorldmapModule::SetSpeed,
  646. "set_camera", &VGears::WorldmapModule::SetCamera,
  647. "set_vehicle_hidden", &VGears::WorldmapModule::SetVehicleHidden,
  648. "add_world_model", &VGears::WorldmapModule::AddWorldModelFromScript
  649. );
  650. // Register all command handlers
  651. lua["input_manager"] = InputManager::getSingletonPtr();
  652. lua["camera_manager"] = CameraManager::getSingletonPtr();
  653. lua["entity_manager"] = EntityManager::getSingletonPtr();
  654. lua["battle_manager"] = BattleManager::getSingletonPtr();
  655. lua["audio_manager"] = AudioManager::getSingletonPtr();
  656. lua["savemap_manager"] = SavemapHandler::getSingletonPtr();
  657. lua["background2d"] = EntityManager::getSingletonPtr()->GetBackground2D();
  658. lua["screen_fade"] = EntityManager::getSingletonPtr()->GetScreenFade();
  659. lua["movie_player"] = EntityManager::getSingletonPtr()->GetMoviePlayer();
  660. lua["walkmesh"] = EntityManager::getSingletonPtr()->GetWalkmesh();
  661. lua["text_manager"] = TextHandler::getSingletonPtr();
  662. lua["dialog"] = DialogsManager::getSingletonPtr();
  663. lua["ui_manager"] = UiManager::getSingletonPtr();
  664. lua["world_map_module"] = VGears::WorldmapModule::getSingletonPtr();
  665. lua["timer"] = Timer::getSingletonPtr();
  666. lua["script"] = this;
  667. }