ScriptManagerBinds.h 27 KB

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