ScriptManagerBinds.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 "SavemapHandler.h"
  26. #include "Timer.h"
  27. #include "UiManager.h"
  28. #include "UiWidget.h"
  29. #include "XmlMapFile.h"
  30. #include "XmlMapsFile.h"
  31. #include "DialogsManager.h"
  32. #include "TextHandler.h"
  33. /**
  34. * Prints to the game console.
  35. *
  36. * @param[in] text The text to be printed.
  37. */
  38. void ScriptPrint(const char* text){
  39. std::cout << "[SCRIPT] " << text << std::endl;
  40. Console::getSingleton().AddTextToOutput(text);
  41. }
  42. /**
  43. * Changes the current map.
  44. *
  45. * Reads the data for the next map, initializes all it's entities, scripts, etc
  46. * and loads it.
  47. *
  48. * @param[in] text The new map name.
  49. */
  50. void ScriptMap(const char* text){
  51. VGears::WorldmapModule::getSingleton().Suspend();
  52. EntityManager::getSingleton().SetFieldModule();
  53. EntityManager::getSingleton().Clear();
  54. XmlMapsFile xml("./data/fields/_fields.xml");
  55. Ogre::String file_name = xml.GetMapFileNameByName(text);
  56. XmlMapFile xml_map("./data/fields/" + file_name);
  57. xml_map.LoadMap();
  58. }
  59. void ScriptWorldMap(const int map, const unsigned int x, const unsigned int y){
  60. EntityManager::getSingleton().Clear();
  61. XmlMapFile xml_map("./data/fields/wm" + std::to_string(map) + ".xml");
  62. xml_map.LoadMap();
  63. }
  64. /**
  65. * Executes a script in the game console.
  66. *
  67. * It should not be related to the game itself. The script output will be
  68. * written to the game console.
  69. *
  70. * @param[in] text The script command to execute.
  71. */
  72. void ScriptConsole(const char* text){
  73. Console::getSingleton().ExecuteCommand(text);
  74. }
  75. /**
  76. * Binds a yielding member function to a class table.
  77. *
  78. * sol2 v2.20.6 function wrappers don't understand sol::yielding_t, so
  79. * sol::yielding can't be used with new_usertype or set_function. The raw
  80. * stack pusher does support it, so the yielding closure is pushed manually
  81. * and set as a field of the class table.
  82. *
  83. * @param[in,out] table The class table to bind the function to.
  84. * @param[in] name Function name for scripts.
  85. * @param[in] function The member function to bind.
  86. */
  87. template <typename F>
  88. void BindYielding(sol::table& table, const char* name, F function){
  89. table.push();
  90. sol::stack::push(table.lua_state(), sol::yielding(function));
  91. lua_setfield(table.lua_state(), -2, name);
  92. lua_pop(table.lua_state(), 1);
  93. }
  94. void ScriptManager::InitBinds(){
  95. sol::state_view lua_view(lua_state_);
  96. sol::table lua = lua_view.globals();
  97. // Global functions.
  98. lua.set_function("print", &ScriptPrint);
  99. lua.set_function("map", &ScriptMap);
  100. lua.set_function("console", &ScriptConsole);
  101. // Individual entity commands.
  102. lua.new_usertype<Entity>(
  103. "Entity",
  104. "set_position", &Entity::ScriptSetPosition,
  105. "move_by", &Entity::ScriptMoveBy,
  106. "get_position", &Entity::ScriptGetPosition,
  107. "get_name", &Entity::GetName,
  108. "set_rotation", &Entity::ScriptSetRotation,
  109. "get_rotation", &Entity::ScriptGetRotation,
  110. "set_solid_radius", &Entity::SetSolidRadius,
  111. "get_solid_radius", &Entity::GetSolidRadius,
  112. "set_solid", &Entity::SetSolid,
  113. "is_solid", &Entity::IsSolid,
  114. "set_talk_radius", &Entity::SetTalkRadius,
  115. "get_talk_radius", &Entity::GetTalkRadius,
  116. // Some old test script use this, its just an alias for SetTalkable:
  117. "set_interactable", &Entity::SetTalkable,
  118. "set_talkable", &Entity::SetTalkable,
  119. "is_talkable", &Entity::IsTalkable,
  120. "set_visible", &Entity::SetVisible,
  121. "is_visible", &Entity::IsVisible,
  122. "set_move_auto_speed", &Entity::SetMoveAutoSpeed,
  123. "get_move_auto_speed", &Entity::GetMoveAutoSpeed,
  124. "get_move_triangle_id", &Entity::GetMoveTriangleId,
  125. "set_move_triangle_id", &Entity::SetMoveTriangleId,
  126. "move_auto_rotation", &Entity::SetMoveAutoRotation,
  127. "move_auto_animation", &Entity::SetMoveAutoAnimation,
  128. "set_move_animations", &Entity::SetMoveAnimations,
  129. "move_to_position", &Entity::ScriptMoveToPosition,
  130. "move_to_entity", &Entity::ScriptMoveToEntity,
  131. "linear_to_position", &Entity::ScriptLinearToPosition,
  132. "jump_to_position", &Entity::ScriptJumpToPosition,
  133. "offset_to_position", &Entity::ScriptOffsetToPosition,
  134. "turn_to_entity", &Entity::ScriptTurnToEntity,
  135. "face_entity", &Entity::ScriptFaceEntity,
  136. "turn_to_direction", &Entity::ScriptTurnToDirection,
  137. "set_animation_speed", &Entity::ScriptSetAnimationSpeed,
  138. "play_animation", sol::overload(
  139. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimation),
  140. sol::resolve<void(const char*, const float, const float)>(&Entity::ScriptPlayAnimation)
  141. ),
  142. "play_animation_stop", sol::overload(
  143. sol::resolve<void(const char*)>(&Entity::ScriptPlayAnimationStop),
  144. sol::resolve<void(const char*, const float, const float)>(
  145. &Entity::ScriptPlayAnimationStop
  146. )
  147. ),
  148. "set_default_animation", &Entity::ScriptSetDefaultAnimation
  149. );
  150. sol::table entity_type = lua["Entity"];
  151. BindYielding(entity_type, "move_sync", &Entity::ScriptMoveSync);
  152. BindYielding(entity_type, "linear_sync", &Entity::ScriptLinearSync);
  153. BindYielding(entity_type, "jump_sync", &Entity::ScriptJumpSync);
  154. BindYielding(entity_type, "offset_sync", &Entity::ScriptOffsetSync);
  155. BindYielding(entity_type, "turn_sync", &Entity::ScriptTurnSync);
  156. BindYielding(entity_type, "animation_sync", &Entity::ScriptAnimationSync);
  157. entity_type["NONE"] = AT_NONE;
  158. entity_type["LINEAR"] = AT_LINEAR;
  159. entity_type["SMOOTH"] = AT_SMOOTH;
  160. entity_type["CLOCKWISE"] = TD_CLOCKWISE;
  161. entity_type["ANTICLOCKWISE"] = TD_ANTICLOCKWISE;
  162. entity_type["CLOSEST"] = TD_CLOSEST;
  163. entity_type["UP_TO_DOWN"] = LM_UP_TO_DOWN;
  164. entity_type["DOWN_TO_UP"] = LM_DOWN_TO_UP;
  165. entity_type["LEFT_TO_RIGHT"] = LM_LEFT_TO_RIGHT;
  166. entity_type["RIGHT_TO_LEFT"] = LM_RIGHT_TO_LEFT;
  167. // Entity individual point commands
  168. lua.new_usertype<EntityPoint>(
  169. "EntityPoint",
  170. "get_position", &EntityPoint::ScriptGetPosition,
  171. "get_rotation", &EntityPoint::ScriptGetRotation
  172. );
  173. // Commands for the entity manager, not related to any particular entity.
  174. lua.new_usertype<EntityManager>(
  175. "EntityManager",
  176. "set_paused", &EntityManager::ScriptSetPaused,
  177. "add_entity", &EntityManager::ScriptAddEntity,
  178. "add_entity_script", &EntityManager::ScriptAddEntityScript,
  179. "get_entity", &EntityManager::ScriptGetEntity,
  180. "get_entity_from_index", &EntityManager::GetEntityFromIndex,
  181. "get_entity_from_character_id", &EntityManager::GetEntityFromCharacterId,
  182. "get_entity_point", &EntityManager::ScriptGetEntityPoint,
  183. "set_player_entity", &EntityManager::ScriptSetPlayerEntity,
  184. "place_player_at_field_entry", &EntityManager::ScriptPlacePlayerAtFieldEntry,
  185. "get_player_entity", &EntityManager::ScriptGetPlayerEntity,
  186. "unset_player_entity", &EntityManager::ScriptUnsetPlayerEntity,
  187. "player_lock", &EntityManager::ScriptPlayerLock,
  188. "random_encounters_on", &EntityManager::SetRandomEncounters,
  189. "is_key_on", &EntityManager::IsKeyOn,
  190. "is_key_off", &EntityManager::IsKeyOff,
  191. "set_entity_to_character", &EntityManager::SetEntityToCharacter
  192. );
  193. // Commands for the battle manager.
  194. lua.new_usertype<BattleManager>(
  195. "BattleManager",
  196. "start_battle", &BattleManager::StartBattle,
  197. "end_battle", &BattleManager::EndBattle,
  198. "get_enemy_count", &BattleManager::ScriptGetEnemyCount,
  199. "get_enemy", &BattleManager::ScriptGetEnemy,
  200. "add_attack_model", &BattleManager::ScriptAddAttackModel
  201. );
  202. // Commands for enemy handling.
  203. lua.new_usertype<Enemy>(
  204. "Enemy",
  205. "get_id", &Enemy::GetId,
  206. "get_name", &Enemy::GetName,
  207. "get_level", &Enemy::GetLevel,
  208. "get_ap", &Enemy::GetAp,
  209. "get_exp", &Enemy::GetExp,
  210. "get_money", &Enemy::GetMoney,
  211. "get_str", &Enemy::GetStr,
  212. "get_def", &Enemy::GetDef,
  213. "get_mag", &Enemy::GetMag,
  214. "get_spr", &Enemy::GetSpr,
  215. "get_dex", &Enemy::GetDex,
  216. "get_lck", &Enemy::GetLck,
  217. "get_eva", &Enemy::GetEva,
  218. "get_meva", &Enemy::GetMeva,
  219. "get_hp", &Enemy::GetHp,
  220. "get_hp_max", &Enemy::GetHpMax,
  221. "get_mp", &Enemy::GetMp,
  222. "get_mp_max", &Enemy::GetMpMax,
  223. "get_position", &Enemy::ScriptGetPos,
  224. "is_front", &Enemy::IsFront,
  225. "is_visible", &Enemy::IsVisible,
  226. "is_targeteable", &Enemy::IsTargeteable,
  227. "is_active", &Enemy::IsActive,
  228. "get_attack_count", &Enemy::ScriptGetAttackCount,
  229. "get_attack", &Enemy::ScriptGetAttack,
  230. "get_camera_for_attack", &Enemy::ScriptGetCameraForAttack
  231. // TODO: Implement cover flags.
  232. // TODO: Implement immunities
  233. // TODO: Implement elements
  234. // TODO: Implement item drops
  235. // TODO: Implement stealable items
  236. // TODO: Implement manipulability status and attacks.
  237. // TODO: Implement morph item
  238. );
  239. // Commands for the audio manager.
  240. lua.new_usertype<AudioManager>(
  241. "AudioManager",
  242. "play_music", &AudioManager::ScriptPlayMusic,
  243. "play_sound", sol::overload(
  244. sol::resolve<void(const char*)>(&AudioManager::ScriptPlaySound),
  245. sol::resolve<void(const char*, const int)>(&AudioManager::ScriptPlaySound)
  246. ),
  247. "play_sounds", &AudioManager::ScriptPlaySounds,
  248. "get_track_id", &AudioManager::ScriptGetTrack,
  249. "get_battle_track_id", &AudioManager::ScriptGetBattleTrack,
  250. "set_battle_track_id", &AudioManager::ScriptSetBattleTrack
  251. );
  252. // Commands for the camera manager.
  253. lua.new_usertype<CameraManager>(
  254. "CameraManager",
  255. "set_camera", &CameraManager::ScriptSetCamera
  256. );
  257. // Commands for the savemap handler.
  258. lua.new_usertype<SavemapHandler>(
  259. "SavemapHandler",
  260. "release", &SavemapHandler::Release,
  261. "get_current_savemap", &SavemapHandler::GetCurrentSavemap,
  262. "get_savemap", &SavemapHandler::GetSavemap,
  263. "set_data", &SavemapHandler::SetData,
  264. "set_control_key", &SavemapHandler::SetControlKey,
  265. "set_window_colours", &SavemapHandler::SetWindowColours,
  266. "set_money", &SavemapHandler::SetMoney,
  267. "set_game_time", &SavemapHandler::SetGameTime,
  268. "set_countdown_time", &SavemapHandler::SetCountdownTime,
  269. "set_key_item", &SavemapHandler::SetKeyItem,
  270. "set_party", &SavemapHandler::SetParty,
  271. "set_item", &SavemapHandler::SetItem,
  272. "set_materia", &SavemapHandler::SetMateria,
  273. "set_e_skill_materia", &SavemapHandler::SetESkillMateria,
  274. "set_materia_stash", &SavemapHandler::SetMateriaStash,
  275. "set_e_skill_materia_stash", &SavemapHandler::SetESkillMateriaStash,
  276. "set_location", &SavemapHandler::SetLocation,
  277. "set_setting", &SavemapHandler::SetSetting,
  278. "set_character_info", &SavemapHandler::SetCharacterInfo,
  279. "set_character_stat", &SavemapHandler::SetCharacterStat,
  280. "set_character_limit_learned", &SavemapHandler::SetCharacterLimitLearned,
  281. "set_character_materia", &SavemapHandler::SetCharacterMateria,
  282. "set_character_e_skill_materia", &SavemapHandler::SetCharacterESkillMateria,
  283. "set_character_status", &SavemapHandler::SetCharacterStatus,
  284. "save", sol::resolve<bool(unsigned int, bool)>(&SavemapHandler::Save),
  285. "is_slot_empty", &SavemapHandler::IsSlotEmpty,
  286. "get_slot_control_key", sol::overload(
  287. &SavemapHandler::GetSlotControlKey,
  288. // Registered under the same name in the original bindings.
  289. &SavemapHandler::GetSlotWindowCornerColourComponent
  290. ),
  291. "get_slot_money", &SavemapHandler::GetSlotMoney,
  292. "get_slot_game_time", &SavemapHandler::GetSlotGameTime,
  293. "get_slot_countdown_time", &SavemapHandler::GetSlotCountdownTime,
  294. "get_slot_party_member", &SavemapHandler::GetSlotPartyMember,
  295. "get_slot_item_at_pos_id", &SavemapHandler::GetSlotItemAtPosId,
  296. "get_slot_item_at_pos_qty", &SavemapHandler::GetSlotItemAtPosQty,
  297. "get_slot_key_item", &SavemapHandler::GetSlotKeyItem,
  298. "get_slot_materia_at_pos_id", &SavemapHandler::GetSlotMateriaAtPosId,
  299. "get_slot_materia_at_pos_ap", &SavemapHandler::GetSlotMateriaAtPosAp,
  300. "is_slot_materia_at_pos_e_skill", &SavemapHandler::IsSlotMateriaAtPosESkill,
  301. "is_slot_materia_at_pos_e_skill_learned",
  302. &SavemapHandler::IsSlotMateriaAtPosESkillLearned,
  303. "get_slot_stash_at_pos_id", &SavemapHandler::GetSlotStashAtPosId,
  304. "get_slot_stash_at_pos_ap", &SavemapHandler::GetSlotStashAtPosAp,
  305. "is_slot_stash_at_pos_e_skill", &SavemapHandler::IsSlotStashAtPosESkill,
  306. "is_slot_stash_at_pos_e_skill_learned",
  307. &SavemapHandler::IsSlotStashAtPosESkillLearned,
  308. "get_slot_location_x", &SavemapHandler::GetSlotLocationX,
  309. "get_slot_location_y", &SavemapHandler::GetSlotLocationY,
  310. "get_slot_location_z", &SavemapHandler::GetSlotLocationZ,
  311. "get_slot_location_triangle", &SavemapHandler::GetSlotLocationTriangle,
  312. "get_slot_location_angle", &SavemapHandler::GetSlotLocationAngle,
  313. "get_slot_location_field", &SavemapHandler::GetSlotLocationField,
  314. "get_slot_location_name", &SavemapHandler::GetSlotLocationName,
  315. "get_slot_setting", &SavemapHandler::GetSlotSetting,
  316. "get_slot_character_char_id", &SavemapHandler::GetSlotCharacterCharId,
  317. "get_slot_character_name", &SavemapHandler::GetSlotCharacterName,
  318. "get_slot_character_level", &SavemapHandler::GetSlotCharacterLevel,
  319. "get_slot_character_kills", &SavemapHandler::GetSlotCharacterKills,
  320. "is_slot_character_enabled", &SavemapHandler::IsSlotCharacterEnabled,
  321. "is_slot_character_locked", &SavemapHandler::IsSlotCharacterLocked,
  322. "is_slot_character_back_row", &SavemapHandler::IsSlotCharacterBackRow,
  323. "get_slot_character_exp", &SavemapHandler::GetSlotCharacterExp,
  324. "get_slot_character_exp_to_next", &SavemapHandler::GetSlotCharacterExpToNext,
  325. "get_slot_character_limit_level", &SavemapHandler::GetSlotCharacterLimitLevel,
  326. "get_slot_character_limit_bar", &SavemapHandler::GetSlotCharacterLimitBar,
  327. "get_slot_character_weapon_id", &SavemapHandler::GetSlotCharacterWeaponId,
  328. "get_slot_character_armor_id", &SavemapHandler::GetSlotCharacterArmorId,
  329. "get_slot_character_accessory_id", &SavemapHandler::GetSlotCharacterAccessoryId,
  330. "get_slot_character_stat_base", &SavemapHandler::GetSlotCharacterStatBase,
  331. "get_slot_character_stat_extra", &SavemapHandler::GetSlotCharacterStatExtra,
  332. "get_slot_character_limit_uses", &SavemapHandler::GetSlotCharacterLimitUses,
  333. "is_slot_character_limit_learned", &SavemapHandler::IsSlotCharacterLimitLearned,
  334. "get_slot_character_materia_id", &SavemapHandler::GetSlotCharacterMateriaId,
  335. "get_slot_character_materia_ap", &SavemapHandler::GetSlotCharacterMateriaAp,
  336. "get_slot_character_materia_e_skill", &SavemapHandler::IsSlotCharacterMateriaESkill,
  337. "get_slot_character_materia_e_skill_learned",
  338. &SavemapHandler::IsSlotCharacterMateriaESkillLearned,
  339. "get_slot_data", &SavemapHandler::GetSlotData
  340. );
  341. // 2D background and camera commands
  342. lua.new_usertype<Background2D>(
  343. "Background2D",
  344. "autoscroll_to_entity", &Background2D::ScriptAutoScrollToEntity,
  345. "scroll_to_player", &Background2D::ScriptScrollToPlayer,
  346. "scroll_to_entity", &Background2D::ScriptScrollToEntity,
  347. "scroll_to_position", &Background2D::ScriptScrollToPosition,
  348. "offset", &Background2D::ScriptOffset,
  349. "area_on", &Background2D::ScriptAreaOn,
  350. "area_off", &Background2D::ScriptAreaOff,
  351. "area_clear", &Background2D::ScriptAreaClear,
  352. "shake", &Background2D::ScriptShake,
  353. "play_animation_looped", &Background2D::ScriptPlayAnimationLooped,
  354. "play_animation_once", &Background2D::ScriptPlayAnimationOnce
  355. );
  356. // Coloured fades of the screen
  357. lua.new_usertype<ScreenFade>(
  358. "ScreenFade",
  359. "fade", &ScreenFade::ScriptFade,
  360. "nfade", &ScreenFade::ScriptNFade
  361. );
  362. sol::table screen_fade_type = lua["ScreenFade"];
  363. BindYielding(screen_fade_type, "wait", &ScreenFade::ScriptWait);
  364. sol::table background_type = lua["Background2D"];
  365. BindYielding(background_type, "scroll_sync", &Background2D::ScriptScrollSync);
  366. BindYielding(background_type, "animation_sync", &Background2D::ScriptAnimationSync);
  367. background_type["NONE"] = AT_NONE;
  368. background_type["LINEAR"] = AT_LINEAR;
  369. background_type["SMOOTH"] = AT_SMOOTH;
  370. // Walkmesh commands
  371. lua.new_usertype<Walkmesh>(
  372. "Walkmesh",
  373. "lock_walkmesh", &Walkmesh::LockWalkmesh,
  374. "is_locked", &Walkmesh::IsLocked
  375. );
  376. // Text handler commands
  377. lua.new_usertype<TextHandler>(
  378. "TextHandler",
  379. "set_character_name", &TextHandler::SetCharacterName,
  380. "set_party", &TextHandler::SetParty
  381. );
  382. // Dialog commands
  383. lua.new_usertype<DialogsManager>(
  384. "Dialog",
  385. "dialog_open", &DialogsManager::OpenDialog,
  386. "set_numeric", &DialogsManager::SetNumeric,
  387. "update_timer", &DialogsManager::UpdateTimer,
  388. "set_mode", &DialogsManager::SetMode,
  389. "dialog_set_text", &DialogsManager::SetText,
  390. "show_message", &DialogsManager::ShowScriptMessage,
  391. "dialog_close", &DialogsManager::Hide,
  392. "set_variable", &DialogsManager::SetVariable,
  393. "set_clickable", &DialogsManager::SetClickable,
  394. "set_cursor", &DialogsManager::SetCursor,
  395. "get_cursor", &DialogsManager::GetCursor,
  396. "set_map_name", &DialogsManager::ScriptSetMapName,
  397. "get_map_name", &DialogsManager::GetMapName
  398. );
  399. sol::table dialog_type = lua["Dialog"];
  400. BindYielding(dialog_type, "dialog_wait_for_close", &DialogsManager::Sync);
  401. dialog_type["SOLID"] = MSL_SOLID;
  402. dialog_type["TRANSPARENT"] = MSL_TRANSPARENT;
  403. dialog_type["NONE"] = MSL_NONE;
  404. // UI widget commands
  405. lua.new_usertype<UiWidget>(
  406. "UiWidget",
  407. "set_visible", &UiWidget::SetVisible,
  408. "is_visible", &UiWidget::IsVisible,
  409. "play_animation", sol::overload(
  410. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimation),
  411. sol::resolve<void(const char*, const float, const float)>(
  412. &UiWidget::ScriptPlayAnimation
  413. )
  414. ),
  415. "play_animation_stop", sol::overload(
  416. sol::resolve<void(const char*)>(&UiWidget::ScriptPlayAnimationStop),
  417. sol::resolve<void(const char*, const float, const float)>(
  418. &UiWidget::ScriptPlayAnimationStop
  419. )
  420. ),
  421. "set_default_animation", &UiWidget::ScriptSetDefaultAnimation,
  422. "set_colour", &UiWidget::SetColour,
  423. "set_alpha", &UiWidget::SetAlpha,
  424. "set_x", &UiWidget::SetX,
  425. "set_y", &UiWidget::SetY,
  426. "set_z", &UiWidget::SetZ,
  427. "get_width", &UiWidget::ScriptGetWidth,
  428. "set_width", sol::overload(&UiWidget::ScriptSetWidth, &UiWidget::SetWidth),
  429. "get_height", &UiWidget::ScriptGetHeight,
  430. "set_height", sol::overload(&UiWidget::ScriptSetHeight, &UiWidget::SetHeight),
  431. "set_text", &UiWidget::SetText,
  432. "set_image", &UiWidget::SetImage
  433. );
  434. sol::table ui_widget_type = lua["UiWidget"];
  435. BindYielding(ui_widget_type, "animation_sync", &UiWidget::ScriptAnimationSync);
  436. // UI manager commands. Use to get a specific widget.
  437. lua.new_usertype<UiManager>(
  438. "UiManager",
  439. "get_widget", &UiManager::ScriptGetWidget
  440. );
  441. // Timer command. To show a in-game timer.
  442. lua.new_usertype<Timer>(
  443. "Timer",
  444. "get_game_time_total", &Timer::GetGameTimeTotal,
  445. "set_timer", &Timer::SetGameTimer,
  446. "get_timer", &Timer::GetGameTimer
  447. );
  448. // Commands that control script execution
  449. lua.new_usertype<ScriptManager>(
  450. "Script",
  451. "request", sol::resolve<void(
  452. const ScriptManager::Type, const char*, const char*, const int
  453. )>(&ScriptManager::ScriptRequest)
  454. );
  455. sol::table script_type = lua["Script"];
  456. BindYielding(script_type, "wait", &ScriptManager::ScriptWait);
  457. BindYielding(script_type, "request_start_sync", &ScriptManager::ScriptRequestStartSync);
  458. BindYielding(script_type, "request_end_sync", &ScriptManager::ScriptRequestEndSync);
  459. script_type["SYSTEM"] = ScriptManager::SYSTEM;
  460. script_type["ENTITY"] = ScriptManager::ENTITY;
  461. script_type["UI"] = ScriptManager::UI;
  462. // Commands to initiate modules
  463. lua.new_usertype<VGears::WorldmapModule>(
  464. "world_map_module",
  465. "init", &VGears::WorldmapModule::Init,
  466. "suspend", &VGears::WorldmapModule::Suspend,
  467. "clear_vehicle_terrains", &VGears::WorldmapModule::ClearVehicleTerrains,
  468. "add_vehicle_terrain", &VGears::WorldmapModule::AddVehicleTerrain,
  469. "get_terrain_type_under_entity", &VGears::WorldmapModule::GetTerrainTypeUnderEntity,
  470. "get_terrain_triangle_under_entity", &VGears::WorldmapModule::GetTerrainTriangleUnderEntity,
  471. "unboard_vehicle", &VGears::WorldmapModule::UnboardVehicle
  472. );
  473. // Register all command handlers
  474. lua["camera_manager"] = CameraManager::getSingletonPtr();
  475. lua["entity_manager"] = EntityManager::getSingletonPtr();
  476. lua["battle_manager"] = BattleManager::getSingletonPtr();
  477. lua["audio_manager"] = AudioManager::getSingletonPtr();
  478. lua["savemap_manager"] = SavemapHandler::getSingletonPtr();
  479. lua["background2d"] = EntityManager::getSingletonPtr()->GetBackground2D();
  480. lua["screen_fade"] = EntityManager::getSingletonPtr()->GetScreenFade();
  481. lua["walkmesh"] = EntityManager::getSingletonPtr()->GetWalkmesh();
  482. lua["text_manager"] = TextHandler::getSingletonPtr();
  483. lua["dialog"] = DialogsManager::getSingletonPtr();
  484. lua["ui_manager"] = UiManager::getSingletonPtr();
  485. lua["world_map_module"] = VGears::WorldmapModule::getSingletonPtr();
  486. lua["timer"] = Timer::getSingletonPtr();
  487. lua["script"] = this;
  488. }