ScriptManagerBinds.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  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 "Entity.h"
  21. #include "EntityManager.h"
  22. #include "BattleManager.h"
  23. #include "AudioManager.h"
  24. #include "SavemapHandler.h"
  25. #include "Timer.h"
  26. #include "UiManager.h"
  27. #include "UiWidget.h"
  28. #include "XmlMapFile.h"
  29. #include "XmlMapsFile.h"
  30. #include "DialogsManager.h"
  31. #include "TextHandler.h"
  32. /*
  33. * TODO:
  34. *
  35. * If I manage to upgrade luabind version (or even better, remove it and use an external one),
  36. * I could pass entire objects to Lua scripts as tables, and this will be waaaaay easier.
  37. */
  38. /**
  39. * Prints to the game console.
  40. *
  41. * @param[in] text The text to be printed.
  42. */
  43. void ScriptPrint(const char* text){
  44. std::cout << "[SCRIPT] " << text << std::endl;
  45. Console::getSingleton().AddTextToOutput(text);
  46. }
  47. /**
  48. * Changes the current map.
  49. *
  50. * Reads the data for the next map, initializes all it's entities, scripts, etc
  51. * and loads it.
  52. *
  53. * @param[in] text The new map name.
  54. */
  55. void ScriptMap(const char* text){
  56. EntityManager::getSingleton().Clear();
  57. XmlMapsFile xml("./data/fields/_fields.xml");
  58. Ogre::String file_name = xml.GetMapFileNameByName(text);
  59. XmlMapFile xml_map("./data/fields/" + file_name);
  60. xml_map.LoadMap();
  61. }
  62. /**
  63. * Executes a script in the game console.
  64. *
  65. * It should not be related to the game itself. The script output will be
  66. * written to the game console.
  67. *
  68. * @param[in] text The script command to execute.
  69. */
  70. void ScriptConsole(const char* text){
  71. Console::getSingleton().ExecuteCommand(text);
  72. }
  73. void ScriptManager::InitBinds(){
  74. // Global functions.
  75. luabind::module(lua_state_)[
  76. luabind::def("print", (void(*)(const char*)) &ScriptPrint),
  77. luabind::def("map", (void(*)(const char*)) &ScriptMap),
  78. luabind::def("console", (void(*)(const char*)) &ScriptConsole)
  79. ];
  80. // Individual entity commands.
  81. luabind::module(lua_state_)[
  82. luabind::class_<Entity>("Entity")
  83. .def(
  84. "set_position",
  85. (void(Entity::*)(const float, const float, const float)) &Entity::ScriptSetPosition
  86. )
  87. // Internally returns 3 values:
  88. .def("get_position", (void(Entity::*)()) &Entity::ScriptGetPosition)
  89. .def("set_rotation", (void(Entity::*)(const float)) &Entity::ScriptSetRotation)
  90. .def("get_rotation", (float(Entity::*)()) &Entity::ScriptGetRotation)
  91. .def("set_solid_radius", (void(Entity::*)(const float)) &Entity::SetSolidRadius)
  92. .def("get_solid_radius", (float(Entity::*)()) &Entity::GetSolidRadius)
  93. .def("set_solid", (void(Entity::*)(const bool)) &Entity::SetSolid)
  94. .def("is_solid", (bool(Entity::*)()) &Entity::IsSolid)
  95. .def("set_talk_radius", (void(Entity::*)(const float)) &Entity::SetTalkRadius)
  96. .def("get_talk_radius", (float(Entity::*)()) &Entity::GetTalkRadius)
  97. // Some old test script use this, its just an alias for SetTalkable:
  98. .def("set_interactable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
  99. .def("set_talkable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
  100. .def("is_talkable", (bool(Entity::*)()) &Entity::IsTalkable)
  101. .def("set_visible", (void(Entity::*)(const bool)) &Entity::SetVisible)
  102. .def("is_visible", (bool(Entity::*)()) &Entity::IsVisible)
  103. .def("set_move_auto_speed", (void(Entity::*)(const float)) &Entity::SetMoveAutoSpeed)
  104. .def("get_move_auto_speed", (float(Entity::*)()) &Entity::GetMoveAutoSpeed)
  105. .def("get_move_triangle_id", (int(Entity::*)()) &Entity::GetMoveTriangleId)
  106. .def("set_move_triangle_id", (void(Entity::*)(const int)) &Entity::SetMoveTriangleId)
  107. .def("move_auto_rotation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoRotation)
  108. .def("move_auto_animation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoAnimation)
  109. .def(
  110. "move_to_position",
  111. (void(Entity::*)(const float, const float)) &Entity::ScriptMoveToPosition
  112. )
  113. .def("move_to_entity", (void(Entity::*)(Entity*)) &Entity::ScriptMoveToEntity)
  114. .def("move_sync", (int(Entity::*)()) &Entity::ScriptMoveSync, luabind::yield)
  115. .def(
  116. "linear_to_position",
  117. (void(Entity::*)(
  118. const float, const float, const float, const LinearMovement,
  119. const char*, const float, const int
  120. )) &Entity::ScriptLinearToPosition
  121. )
  122. .def(
  123. "linear_sync", (int(Entity::*)()) &Entity::ScriptLinearSync, luabind::yield
  124. )
  125. .def(
  126. "jump_to_position",
  127. (void(Entity::*)(const float, const float, const float, const float, const int))
  128. &Entity::ScriptJumpToPosition
  129. )
  130. .def("jump_sync", (int(Entity::*)()) &Entity::ScriptJumpSync, luabind::yield)
  131. .def(
  132. "offset_to_position",
  133. (void(Entity::*)(const float, const float, const float, const ActionType, const float))
  134. &Entity::ScriptOffsetToPosition
  135. )
  136. .def("offset_sync", (int(Entity::*)()) &Entity::ScriptOffsetSync, luabind::yield)
  137. .def(
  138. "turn_to_entity",
  139. (void(Entity::*)(Entity*, const TurnDirection, const float)) &Entity::ScriptTurnToEntity
  140. )
  141. .def(
  142. "turn_to_direction", (
  143. void(Entity::*)(const float, const TurnDirection, const ActionType, const float)
  144. ) &Entity::ScriptTurnToDirection)
  145. .def("turn_sync", (int(Entity::*)()) &Entity::ScriptTurnSync, luabind::yield)
  146. .def(
  147. "set_animation_speed", (void(Entity::*)(const float)) &Entity::ScriptSetAnimationSpeed
  148. )
  149. .def("play_animation", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimation)
  150. .def(
  151. "play_animation_stop", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimationStop
  152. )
  153. .def(
  154. "play_animation",
  155. (void(Entity::*)(const char*, const float, const float)) &Entity::ScriptPlayAnimation
  156. )
  157. .def(
  158. "play_animation_stop",
  159. (void(Entity::*)(const char*, const float, const float))
  160. &Entity::ScriptPlayAnimationStop
  161. )
  162. .def(
  163. "set_default_animation",
  164. (void(Entity::*)(const char*)) &Entity::ScriptSetDefaultAnimation
  165. )
  166. .def("animation_sync", (int(Entity::*)()) &Entity::ScriptAnimationSync, luabind::yield)
  167. .enum_("constants")[
  168. luabind::value("NONE", AT_NONE),
  169. luabind::value("LINEAR", AT_LINEAR),
  170. luabind::value("SMOOTH", AT_SMOOTH),
  171. luabind::value("CLOCKWISE", TD_CLOCKWISE),
  172. luabind::value("ANTICLOCKWISE", TD_ANTICLOCKWISE),
  173. luabind::value("CLOSEST", TD_CLOSEST),
  174. luabind::value("UP_TO_DOWN", LM_UP_TO_DOWN),
  175. luabind::value("DOWN_TO_UP", LM_DOWN_TO_UP),
  176. luabind::value("LEFT_TO_RIGHT", LM_LEFT_TO_RIGHT),
  177. luabind::value("RIGHT_TO_LEFT", LM_RIGHT_TO_LEFT)
  178. ]
  179. ];
  180. // Field commands.
  181. // TODO: Duplicated in group EntityManager, this can probably be deleted
  182. luabind::module(lua_state_)[
  183. luabind::class_<EntityManager>("Field")
  184. .def(
  185. "random_encounters_on",
  186. (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
  187. )
  188. ];
  189. // Entity individual point commands
  190. luabind::module(lua_state_)[
  191. luabind::class_<EntityPoint>("EntityPoint")
  192. // Internally returns 3 values:
  193. .def("get_position", (void(EntityPoint::*)()) &EntityPoint::ScriptGetPosition)
  194. .def("get_rotation", (float(EntityPoint::*)()) &EntityPoint::ScriptGetRotation)
  195. ];
  196. // Commands for the entity manager, not related to any particular entity.
  197. luabind::module(lua_state_)[
  198. luabind::class_<EntityManager>("EntityManager")
  199. .def("set_paused", (void(EntityManager::*)(const bool)) &EntityManager::ScriptSetPaused)
  200. .def(
  201. "add_entity",
  202. (void(EntityManager::*)(
  203. const char*, const char*, const float,const float,
  204. const float, const float, const int
  205. )) &EntityManager::ScriptAddEntity
  206. )
  207. .def(
  208. "add_entity_script",
  209. (void(EntityManager::*)(const char*)) &EntityManager::ScriptAddEntityScript
  210. )
  211. .def(
  212. "get_entity", (Entity*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntity
  213. )
  214. .def(
  215. "get_entity_from_index",
  216. (Entity*(EntityManager::*)(const int)) &EntityManager::GetEntityFromIndex
  217. )
  218. .def(
  219. "get_entity_from_character_id",
  220. (Entity*(EntityManager::*)(const int)) &EntityManager::GetEntityFromCharacterId
  221. )
  222. .def(
  223. "get_entity_point",
  224. (EntityPoint*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntityPoint
  225. )
  226. .def(
  227. "set_player_entity",
  228. (void(EntityManager::*)(const char*)) &EntityManager::ScriptSetPlayerEntity
  229. )
  230. .def(
  231. "get_player_entity",
  232. (Entity*(EntityManager::*)()) &EntityManager::ScriptGetPlayerEntity
  233. )
  234. .def(
  235. "unset_player_entity",
  236. (void(EntityManager::*)()) &EntityManager::ScriptUnsetPlayerEntity
  237. )
  238. .def(
  239. "player_lock", (void(EntityManager::*)(const bool)) &EntityManager::ScriptPlayerLock
  240. )
  241. .def(
  242. "random_encounters_on",
  243. (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
  244. )
  245. .def("is_key_on", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOn)
  246. .def("is_key_off", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOff)
  247. .def(
  248. "set_entity_to_character",
  249. (void(EntityManager::*)(const char*, unsigned int)) &EntityManager::SetEntityToCharacter
  250. )
  251. ];
  252. // Commands for the battle manager.
  253. luabind::module(lua_state_)[
  254. luabind::class_<BattleManager>("BattleManager")
  255. .def(
  256. "start_battle", (void(BattleManager::*)(const unsigned int)) &BattleManager::StartBattle
  257. )
  258. .def("end_battle", (void(BattleManager::*)()) &BattleManager::EndBattle)
  259. ];
  260. // Commands for the audio manager.
  261. luabind::module(lua_state_)[
  262. luabind::class_<AudioManager>("AudioManager")
  263. .def("play_music", (void(AudioManager::*)(const char*)) &AudioManager::ScriptPlayMusic)
  264. .def("play_sound", (void(AudioManager::*)(const char*)) &AudioManager::ScriptPlaySound)
  265. .def(
  266. "play_sound",
  267. (void(AudioManager::*)(const char*, const int)) &AudioManager::ScriptPlaySound
  268. )
  269. .def(
  270. "play_sounds",
  271. (void(AudioManager::*)(const char*, const char*, const char*, const char*))
  272. &AudioManager::ScriptPlaySounds
  273. )
  274. .def("get_track_id", (int(AudioManager::*)(int)) &AudioManager::ScriptGetTrack)
  275. .def("get_battle_track_id", (int(AudioManager::*)()) &AudioManager::ScriptGetBattleTrack)
  276. .def(
  277. "set_battle_track_id", (void(AudioManager::*)(int)) &AudioManager::ScriptSetBattleTrack
  278. )
  279. ];
  280. // Commands for the audio manager.
  281. luabind::module(lua_state_)[
  282. luabind::class_<CameraManager>("CameraManager")
  283. .def("set_camera",
  284. (void(CameraManager::*)(
  285. const int, const int, const int, const int, const int, const int
  286. )) &CameraManager::ScriptSetCamera
  287. )
  288. ];
  289. // Commands for the savemap handelr.
  290. luabind::module(lua_state_)[
  291. luabind::class_<SavemapHandler>("SavemapHandler")
  292. .def(
  293. "release", (void(SavemapHandler::*)()) &SavemapHandler::Release
  294. )
  295. .def(
  296. "get_current_savemap",
  297. (Savemap*(SavemapHandler::*)()) &SavemapHandler::GetCurrentSavemap
  298. )
  299. .def(
  300. "get_savemap",
  301. (Savemap*(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSavemap
  302. )
  303. .def(
  304. "set_data",
  305. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const int))
  306. &SavemapHandler::SetData
  307. )
  308. .def(
  309. "set_control_key", (void(SavemapHandler::*)(const char*)) &SavemapHandler::SetControlKey
  310. )
  311. .def(
  312. "set_window_colours",
  313. (void(SavemapHandler::*)(
  314. const unsigned int, const unsigned int, const unsigned int,
  315. const unsigned int, const unsigned int, const unsigned int,
  316. const unsigned int, const unsigned int, const unsigned int,
  317. const unsigned int, const unsigned int, const unsigned int
  318. )) &SavemapHandler::SetWindowColours
  319. )
  320. .def("set_money", (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetMoney)
  321. .def(
  322. "set_game_time",
  323. (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetGameTime
  324. )
  325. .def(
  326. "set_countdown_time",
  327. (void(SavemapHandler::*)(const unsigned int)) &SavemapHandler::SetCountdownTime
  328. )
  329. .def(
  330. "set_key_item",
  331. (void(SavemapHandler::*)(const unsigned int, const bool)) &SavemapHandler::SetKeyItem
  332. )
  333. .def(
  334. "set_party",
  335. (void(SavemapHandler::*)(const int, const int, const int)) &SavemapHandler::SetParty
  336. )
  337. .def(
  338. "set_item",
  339. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  340. &SavemapHandler::SetItem
  341. )
  342. .def(
  343. "set_materia",
  344. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  345. &SavemapHandler::SetMateria
  346. )
  347. .def(
  348. "set_e_skill_materia",
  349. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  350. &SavemapHandler::SetESkillMateria
  351. )
  352. .def(
  353. "set_materia_stash",
  354. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  355. &SavemapHandler::SetMateriaStash
  356. )
  357. .def(
  358. "set_e_skill_materia_stash",
  359. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  360. &SavemapHandler::SetESkillMateriaStash
  361. )
  362. .def(
  363. "set_location",
  364. (void(SavemapHandler::*)(
  365. const float, const float, const float, const unsigned int, const int,
  366. const char*, const char*
  367. )) &SavemapHandler::SetLocation
  368. )
  369. .def(
  370. "set_setting",
  371. (void(SavemapHandler::*)(const unsigned int, const unsigned int))
  372. &SavemapHandler::SetSetting
  373. )
  374. .def(
  375. "set_character_info",
  376. (void(SavemapHandler::*)(
  377. const unsigned int, const int, const char*, const bool, const bool, const unsigned int,
  378. const unsigned int, const bool, const unsigned int, const unsigned int,
  379. const unsigned int, const unsigned int, const unsigned int, const unsigned int,
  380. const int
  381. )) &SavemapHandler::SetCharacterInfo
  382. )
  383. .def(
  384. "set_character_stat",
  385. (void(SavemapHandler::*)(
  386. const unsigned int, const unsigned int, const unsigned int, const unsigned int
  387. )) &SavemapHandler::SetCharacterStat
  388. )
  389. .def(
  390. "set_character_limit_learned",
  391. (void(SavemapHandler::*)(
  392. const unsigned int, const unsigned int, const unsigned int,
  393. const bool, const unsigned int
  394. )) &SavemapHandler::SetCharacterLimitLearned
  395. )
  396. .def(
  397. "set_character_materia",
  398. (void(SavemapHandler::*)(
  399. const unsigned int, const bool, const unsigned int,
  400. const unsigned int, const unsigned int
  401. )) &SavemapHandler::SetCharacterMateria
  402. )
  403. .def(
  404. "set_character_e_skill_materia",
  405. (void(SavemapHandler::*)(
  406. const unsigned int, const bool, const unsigned int, const unsigned int, const bool
  407. )) &SavemapHandler::SetCharacterESkillMateria
  408. )
  409. .def(
  410. "set_character_status",
  411. (void(SavemapHandler::*)(const unsigned int, const unsigned int, const bool))
  412. &SavemapHandler::SetCharacterStatus
  413. )
  414. .def(
  415. "save", (bool(SavemapHandler::*)(const unsigned int, const bool)) &SavemapHandler::Save
  416. )
  417. .def(
  418. "is_slot_empty",
  419. (bool(SavemapHandler::*)(const unsigned int)) &SavemapHandler::IsSlotEmpty
  420. )
  421. .def(
  422. "get_slot_control_key",
  423. (std::string(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotControlKey
  424. )
  425. .def(
  426. "get_slot_control_key",
  427. (unsigned int(SavemapHandler::*)(
  428. const unsigned int, const unsigned int, const unsigned int
  429. )) &SavemapHandler::GetSlotWindowCornerColourComponent
  430. )
  431. .def(
  432. "get_slot_money",
  433. (unsigned int(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotMoney
  434. )
  435. .def(
  436. "get_slot_game_time",
  437. (unsigned int(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotGameTime
  438. )
  439. .def(
  440. "get_slot_countdown_time",
  441. (unsigned int(SavemapHandler::*)(const unsigned int))
  442. &SavemapHandler::GetSlotCountdownTime
  443. )
  444. .def(
  445. "get_slot_party_member",
  446. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  447. &SavemapHandler::GetSlotPartyMember
  448. )
  449. .def(
  450. "get_slot_item_at_pos_id",
  451. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  452. &SavemapHandler::GetSlotItemAtPosId
  453. )
  454. .def(
  455. "get_slot_item_at_pos_qty",
  456. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  457. &SavemapHandler::GetSlotItemAtPosQty
  458. )
  459. .def(
  460. "get_slot_key_item",
  461. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  462. &SavemapHandler::GetSlotKeyItem
  463. )
  464. .def(
  465. "get_slot_materia_at_pos_id",
  466. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  467. &SavemapHandler::GetSlotMateriaAtPosId
  468. )
  469. .def(
  470. "get_slot_materia_at_pos_ap",
  471. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  472. &SavemapHandler::GetSlotMateriaAtPosAp
  473. )
  474. .def(
  475. "is_slot_materia_at_pos_e_skill",
  476. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  477. &SavemapHandler::IsSlotMateriaAtPosESkill
  478. )
  479. .def(
  480. "is_slot_materia_at_pos_e_skill_learned",
  481. (bool(SavemapHandler::*)(
  482. const unsigned int, const unsigned int, const unsigned int
  483. )) &SavemapHandler::IsSlotMateriaAtPosESkillLearned
  484. )
  485. .def(
  486. "get_slot_stash_at_pos_id",
  487. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  488. &SavemapHandler::GetSlotStashAtPosId
  489. )
  490. .def(
  491. "get_slot_stash_at_pos_ap",
  492. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  493. &SavemapHandler::GetSlotStashAtPosAp
  494. )
  495. .def(
  496. "is_slot_stash_at_pos_e_skill",
  497. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  498. &SavemapHandler::IsSlotStashAtPosESkill
  499. )
  500. .def(
  501. "is_slot_stash_at_pos_e_skill_learned",
  502. (bool(SavemapHandler::*)(
  503. const unsigned int, const unsigned int, const unsigned int
  504. )) &SavemapHandler::IsSlotStashAtPosESkillLearned
  505. )
  506. .def(
  507. "get_slot_location_x",
  508. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationX
  509. )
  510. .def(
  511. "get_slot_location_y",
  512. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationY
  513. )
  514. .def(
  515. "get_slot_location_z",
  516. (float(SavemapHandler::*)(const unsigned int)) &SavemapHandler::GetSlotLocationZ
  517. )
  518. .def(
  519. "get_slot_location_triangle",
  520. (unsigned int(SavemapHandler::*)(const unsigned int))
  521. &SavemapHandler::GetSlotLocationTriangle
  522. )
  523. .def(
  524. "get_slot_location_angle",
  525. (unsigned int(SavemapHandler::*)(const unsigned int))
  526. &SavemapHandler::GetSlotLocationAngle
  527. )
  528. .def(
  529. "get_slot_location_field",
  530. (std::string(SavemapHandler::*)(const unsigned int))
  531. &SavemapHandler::GetSlotLocationField
  532. )
  533. .def(
  534. "get_slot_location_name",
  535. (std::string(SavemapHandler::*)(const unsigned int))
  536. &SavemapHandler::GetSlotLocationName
  537. )
  538. .def(
  539. "get_slot_setting",
  540. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  541. &SavemapHandler::GetSlotSetting
  542. )
  543. .def(
  544. "get_slot_character_char_id",
  545. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  546. &SavemapHandler::GetSlotCharacterCharId
  547. )
  548. .def(
  549. "get_slot_character_name",
  550. (std::string(SavemapHandler::*)(const unsigned int, const unsigned int))
  551. &SavemapHandler::GetSlotCharacterName
  552. )
  553. .def(
  554. "get_slot_character_level",
  555. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  556. &SavemapHandler::GetSlotCharacterLevel
  557. )
  558. .def(
  559. "get_slot_character_kills",
  560. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  561. &SavemapHandler::GetSlotCharacterKills
  562. )
  563. .def(
  564. "is_slot_character_enabled",
  565. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  566. &SavemapHandler::IsSlotCharacterEnabled
  567. )
  568. .def(
  569. "is_slot_character_locked",
  570. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  571. &SavemapHandler::IsSlotCharacterLocked
  572. )
  573. .def(
  574. "is_slot_character_back_row",
  575. (bool(SavemapHandler::*)(const unsigned int, const unsigned int))
  576. &SavemapHandler::IsSlotCharacterBackRow
  577. )
  578. .def(
  579. "get_slot_character_exp",
  580. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  581. &SavemapHandler::GetSlotCharacterExp
  582. )
  583. .def(
  584. "get_slot_character_exp_to_next",
  585. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  586. &SavemapHandler::GetSlotCharacterExpToNext
  587. )
  588. .def(
  589. "get_slot_character_limit_level",
  590. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  591. &SavemapHandler::GetSlotCharacterLimitLevel
  592. )
  593. .def(
  594. "get_slot_character_limit_bar",
  595. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  596. &SavemapHandler::GetSlotCharacterLimitBar
  597. )
  598. .def(
  599. "get_slot_character_weapon_id",
  600. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  601. &SavemapHandler::GetSlotCharacterWeaponId
  602. )
  603. .def(
  604. "get_slot_character_armor_id",
  605. (unsigned int(SavemapHandler::*)(const unsigned int, const unsigned int))
  606. &SavemapHandler::GetSlotCharacterArmorId
  607. )
  608. .def(
  609. "get_slot_character_accessory_id",
  610. (int(SavemapHandler::*)(const unsigned int, const unsigned int))
  611. &SavemapHandler::GetSlotCharacterAccessoryId
  612. )
  613. .def(
  614. "get_slot_character_stat_base",
  615. (unsigned int(SavemapHandler::*)(
  616. const unsigned int, const unsigned int, const unsigned int
  617. )) &SavemapHandler::GetSlotCharacterStatBase
  618. )
  619. .def(
  620. "get_slot_character_stat_extra",
  621. (unsigned int(SavemapHandler::*)(
  622. const unsigned int, const unsigned int, const unsigned int
  623. )) &SavemapHandler::GetSlotCharacterStatExtra
  624. )
  625. .def(
  626. "get_slot_character_limit_uses",
  627. (unsigned int(SavemapHandler::*)(
  628. const unsigned int, const unsigned int, const unsigned int
  629. )) &SavemapHandler::GetSlotCharacterLimitUses
  630. )
  631. .def(
  632. "is_slot_character_limit_learned",
  633. (unsigned int(SavemapHandler::*)(
  634. const unsigned int, const unsigned int, const unsigned int, const unsigned int
  635. )) &SavemapHandler::IsSlotCharacterLimitLearned
  636. )
  637. .def(
  638. "get_slot_character_materia_id",
  639. (int(SavemapHandler::*)(
  640. const unsigned int, const unsigned int, const bool, const unsigned int
  641. )) &SavemapHandler::GetSlotCharacterMateriaId
  642. )
  643. .def(
  644. "get_slot_character_materia_ap",
  645. (unsigned int(SavemapHandler::*)(
  646. const unsigned int, const unsigned int, const bool, const unsigned int
  647. )) &SavemapHandler::GetSlotCharacterMateriaAp
  648. )
  649. .def(
  650. "get_slot_character_materia_e_skill",
  651. (bool(SavemapHandler::*)(
  652. const unsigned int, const unsigned int, const bool,
  653. const unsigned int, const unsigned int
  654. )) &SavemapHandler::IsSlotCharacterMateriaESkill
  655. )
  656. .def(
  657. "get_slot_character_materia_e_skill_learned",
  658. (bool(SavemapHandler::*)(
  659. const unsigned int, const unsigned int, const bool,
  660. const unsigned int, const unsigned int
  661. )) &SavemapHandler::IsSlotCharacterMateriaESkillLearned
  662. )
  663. .def(
  664. "get_slot_data",
  665. (int(SavemapHandler::*)(const unsigned int, const unsigned int, const unsigned int))
  666. &SavemapHandler::GetSlotData
  667. )
  668. ];
  669. // 2D background and camera commands
  670. luabind::module(lua_state_)[
  671. luabind::class_<Background2D>("Background2D")
  672. .def(
  673. "autoscroll_to_entity",
  674. (void(Background2D::*)(Entity*)) &Background2D::ScriptAutoScrollToEntity
  675. )
  676. .def(
  677. "scroll_to_player",
  678. (void(Background2D::*)(const Background2D::SCROLL_TYPE, const unsigned int))
  679. &Background2D::ScriptScrollToPlayer
  680. )
  681. .def(
  682. "scroll_to_position",
  683. (void(Background2D::*)(
  684. const float, const float, const Background2D::SCROLL_TYPE, const float
  685. )) &Background2D::ScriptScrollToPosition
  686. )
  687. .def(
  688. "scroll_sync", (int(Background2D::*)()) &Background2D::ScriptScrollSync, luabind::yield
  689. )
  690. .def(
  691. "offset", (void(Background2D::*)(const float, const float)) &Background2D::ScriptOffset
  692. )
  693. .def(
  694. "play_animation_looped",
  695. (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationLooped
  696. )
  697. .def(
  698. "play_animation_once",
  699. (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationOnce
  700. )
  701. .def(
  702. "animation_sync",
  703. (int(Background2D::*)(const char*)) &Background2D::ScriptAnimationSync,
  704. luabind::yield
  705. )
  706. .enum_("constants")[
  707. luabind::value("NONE", AT_NONE),
  708. luabind::value("LINEAR", AT_LINEAR),
  709. luabind::value("SMOOTH", AT_SMOOTH)
  710. ]
  711. ];
  712. // Walkmesh commands
  713. luabind::module(lua_state_)[
  714. luabind::class_<Walkmesh>("Walkmesh")
  715. .def("lock_walkmesh", (void(Walkmesh ::*)(unsigned int, bool)) &Walkmesh ::LockWalkmesh)
  716. .def("is_locked", (bool(Walkmesh ::*)(unsigned int)) &Walkmesh ::IsLocked)
  717. ];
  718. // Text handler commands
  719. luabind::module(lua_state_)[
  720. luabind::class_<TextHandler>("TextHandler")
  721. .def(
  722. "set_character_name",
  723. (void(TextHandler ::*)(unsigned int, const char*)) &TextHandler::SetCharacterName
  724. )
  725. .def("set_party", (void(TextHandler ::*)(int, int, int)) &TextHandler::SetParty)
  726. ];
  727. // Dialog commands
  728. luabind::module(lua_state_)[
  729. luabind::class_<DialogsManager>("Dialog")
  730. .def(
  731. "dialog_open",
  732. (void(DialogsManager::*)(const char*, int, int, int, int)) &DialogsManager::OpenDialog
  733. )
  734. .def(
  735. "set_numeric",
  736. (void(DialogsManager::*)(const char*, const bool, const bool))
  737. &DialogsManager::SetNumeric
  738. )
  739. .def(
  740. "update_timer",
  741. (void(DialogsManager::*)(const unsigned int)) &DialogsManager::UpdateTimer
  742. )
  743. .def(
  744. "set_mode",
  745. (void(DialogsManager::*)(const char*, const unsigned int, const bool))
  746. &DialogsManager::SetMode
  747. )
  748. .def(
  749. "dialog_set_text",
  750. (void(DialogsManager::*)(const char*, const char*)) &DialogsManager::SetText
  751. )
  752. .def(
  753. "dialog_wait_for_close",
  754. (int(DialogsManager::*)(const char*)) &DialogsManager::Sync,
  755. luabind::yield
  756. )
  757. .def("dialog_close", (void(DialogsManager::*)(const char*)) &DialogsManager::Hide)
  758. .def(
  759. "set_variable",
  760. (void(DialogsManager::*)(const char*, const char*, const char*))
  761. &DialogsManager::SetVariable
  762. )
  763. .def(
  764. "set_clickable",
  765. (void(DialogsManager::*)(const char*, const bool)) &DialogsManager::SetClickable
  766. )
  767. .def(
  768. "set_cursor",
  769. (void(DialogsManager::*)(const char*, const int, const int)) &DialogsManager::SetCursor
  770. )
  771. .def("get_cursor", (int(DialogsManager::*)(const char*)) &DialogsManager::GetCursor)
  772. .enum_("constants")[
  773. luabind::value("SOLID", MSL_SOLID),
  774. luabind::value("TRANSPARENT", MSL_TRANSPARENT),
  775. luabind::value("NONE", MSL_NONE)
  776. ]
  777. .def(
  778. "set_map_name", (void(DialogsManager::*)(const char*)) &DialogsManager::ScriptSetMapName
  779. )
  780. .def(
  781. "get_map_name", (std::string(DialogsManager::*)()) &DialogsManager::GetMapName
  782. )
  783. ];
  784. // UI widget commands
  785. luabind::module(lua_state_)[
  786. luabind::class_<UiWidget>("UiWidget")
  787. .def("set_visible", (void(UiWidget::*)(const bool)) &UiWidget::SetVisible)
  788. .def("is_visible", (bool(UiWidget::*)()) &UiWidget::IsVisible)
  789. .def("play_animation", (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimation)
  790. .def(
  791. "play_animation_stop",
  792. (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimationStop
  793. )
  794. .def(
  795. "play_animation",
  796. (void(UiWidget::*)(const char*, const float, const float))
  797. &UiWidget::ScriptPlayAnimation
  798. )
  799. .def(
  800. "play_animation_stop",
  801. (void(UiWidget::*)(const char*, const float, const float))
  802. &UiWidget::ScriptPlayAnimationStop
  803. )
  804. .def(
  805. "set_default_animation",
  806. (void(UiWidget::*)(const char*)) &UiWidget::ScriptSetDefaultAnimation
  807. )
  808. .def(
  809. "animation_sync", (int(UiWidget::*)()) &UiWidget::ScriptAnimationSync, luabind::yield
  810. )
  811. .def(
  812. "set_colour",
  813. (void(UiWidget::*)(const float, const float, const float)) &UiWidget::SetColour
  814. )
  815. .def("set_alpha", (void(UiWidget::*)(const float)) &UiWidget::SetAlpha)
  816. .def("set_x", (void(UiWidget::*)(const float, const float)) &UiWidget::SetX)
  817. .def("set_y", (void(UiWidget::*)(const float, const float)) &UiWidget::SetY)
  818. .def("set_z", (void(UiWidget::*)(const float)) &UiWidget::SetZ)
  819. .def("get_width", (float(UiWidget::*)()) &UiWidget::ScriptGetWidth)
  820. .def("set_width", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetWidth)
  821. .def("get_height", (float(UiWidget::*)()) &UiWidget::ScriptGetHeight)
  822. .def("set_height", (void(UiWidget::*)(const float)) &UiWidget::ScriptSetHeight)
  823. .def("set_text", (void(UiWidget::*)(const char*)) &UiWidget::SetText)
  824. .def("set_image", (void(UiWidget::*)(const char*)) &UiWidget::SetImage)
  825. ];
  826. // UI manager commands. Use to get a specific widget.
  827. luabind::module(lua_state_)[
  828. luabind::class_<UiManager>("UiManager")
  829. .def("get_widget", (UiWidget*(UiManager::*)(const char*)) &UiManager::ScriptGetWidget)
  830. ];
  831. // Timer command. To show a in-game timer.
  832. luabind::module(lua_state_)[
  833. luabind::class_<Timer>("Timer")
  834. .def("get_game_time_total", (float(Timer::*)()) &Timer::GetGameTimeTotal)
  835. .def("set_timer", (float(Timer::*)(const float)) &Timer::SetGameTimer)
  836. .def("get_timer", (int(Timer::*)()) &Timer::GetGameTimer)
  837. ];
  838. // Commands that control script execution
  839. luabind::module(lua_state_)[
  840. luabind::class_<ScriptManager>("Script")
  841. .def(
  842. "wait", (int(ScriptManager::*)(const float)) &ScriptManager::ScriptWait, luabind::yield
  843. )
  844. .def(
  845. "request",
  846. (void(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int))
  847. &ScriptManager::ScriptRequest
  848. )
  849. .def(
  850. "request_start_sync",
  851. (int(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int))
  852. &ScriptManager::ScriptRequestStartSync,
  853. luabind::yield
  854. )
  855. .def(
  856. "request_end_sync",
  857. (int(ScriptManager::*) (const ScriptManager::Type, const char*, const char*, const int))
  858. &ScriptManager::ScriptRequestEndSync,
  859. luabind::yield
  860. )
  861. .enum_("constants")[
  862. luabind::value("SYSTEM", ScriptManager::SYSTEM),
  863. luabind::value("ENTITY", ScriptManager::ENTITY),
  864. luabind::value("UI", ScriptManager::UI)
  865. ]
  866. ];
  867. // Commnds to initiate modules
  868. luabind::module(lua_state_)[
  869. luabind::class_<VGears::WorldmapModule>("world_map_module")
  870. .def("init", (void(VGears::WorldmapModule::*)()) &VGears::WorldmapModule::Init)
  871. ];
  872. // Register all command handlers
  873. auto a = boost::ref(*(EntityManager::getSingletonPtr()));
  874. luabind::globals(lua_state_);
  875. //auto b = luabind::globals(lua_state_)["entity_manager"];
  876. luabind::globals(lua_state_)["camera_manager"]
  877. = boost::ref(*(CameraManager::getSingletonPtr()));
  878. luabind::globals(lua_state_)["entity_manager"]
  879. = boost::ref(*(EntityManager::getSingletonPtr()));
  880. luabind::globals(lua_state_)["battle_manager"]
  881. = boost::ref(*(BattleManager::getSingletonPtr()));
  882. luabind::globals(lua_state_)["audio_manager"] = boost::ref(*(AudioManager::getSingletonPtr()));
  883. luabind::globals(lua_state_)["savemap_manager"]
  884. = boost::ref(*(SavemapHandler::getSingletonPtr()));
  885. luabind::globals(lua_state_)["background2d"]
  886. = boost::ref(*(EntityManager::getSingletonPtr()->GetBackground2D()));
  887. luabind::globals(lua_state_)["walkmesh"]
  888. = boost::ref(*(EntityManager::getSingletonPtr()->GetWalkmesh()));
  889. luabind::globals(lua_state_)["text_manager"] = boost::ref(*(TextHandler::getSingletonPtr()));
  890. luabind::globals(lua_state_)["dialog"] = boost::ref(*(DialogsManager::getSingletonPtr()));
  891. luabind::globals(lua_state_)["ui_manager"] = boost::ref(*(UiManager::getSingletonPtr()));
  892. luabind::globals(lua_state_)["world_map_module"]
  893. = boost::ref(*(VGears::WorldmapModule::getSingletonPtr()));
  894. luabind::globals(lua_state_)["timer"] = boost::ref(*(Timer::getSingletonPtr()));
  895. luabind::globals(lua_state_)["script"] = boost::ref(*this);
  896. }