level_editor_api.vala 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
  4. */
  5. namespace Crown
  6. {
  7. namespace LevelEditorAPI
  8. {
  9. public string reset()
  10. {
  11. return "LevelEditor:reset()";
  12. }
  13. public string set_mouse_state(int x, int y, bool left, bool middle, bool right)
  14. {
  15. return "LevelEditor:set_mouse_state(%d,%d,%s,%s,%s)".printf(x
  16. , y
  17. , Lua.bool(left)
  18. , Lua.bool(middle)
  19. , Lua.bool(right)
  20. );
  21. }
  22. public string set_mouse_move(int x, int y, int dx, int dy)
  23. {
  24. return "LevelEditor:set_mouse_move(%d,%d,%d,%d)".printf(x, y, dx, dy);
  25. }
  26. public string set_mouse_wheel(double delta)
  27. {
  28. return "LevelEditor:set_mouse_wheel(%f)".printf(delta);
  29. }
  30. public string set_mouse_down(int x, int y)
  31. {
  32. return "LevelEditor:mouse_down(%d,%d)".printf(x, y);
  33. }
  34. public string set_mouse_up(int x, int y)
  35. {
  36. return "LevelEditor:mouse_up(%d,%d)".printf(x, y);
  37. }
  38. public string set_key_down(string key)
  39. {
  40. return "LevelEditor:key_down(\"%s\")".printf(key);
  41. }
  42. public string set_key_up(string key)
  43. {
  44. return "LevelEditor:key_up(\"%s\")".printf(key);
  45. }
  46. private const string[] _tools =
  47. {
  48. "place_tool",
  49. "move_tool",
  50. "rotate_tool",
  51. "scale_tool"
  52. };
  53. public string set_tool_type(ToolType type)
  54. {
  55. return "LevelEditor:set_tool(LevelEditor.%s)".printf(_tools[(int)type]);
  56. }
  57. public string set_snap_mode(SnapMode sm)
  58. {
  59. return """LevelEditor:set_snap_mode("%s")""".printf(sm == SnapMode.RELATIVE ? "relative" : "absolute");
  60. }
  61. public string set_reference_system(ReferenceSystem rs)
  62. {
  63. return """LevelEditor:set_reference_system("%s")""".printf(rs == ReferenceSystem.LOCAL ? "local" : "world");
  64. }
  65. public string enable_show_grid(bool enabled)
  66. {
  67. return "LevelEditor:enable_show_grid(%s)".printf(Lua.bool(enabled));
  68. }
  69. public string enable_snap_to_grid(bool enabled)
  70. {
  71. return "LevelEditor:enable_snap_to_grid(%s)".printf(Lua.bool(enabled));
  72. }
  73. public string enable_debug_render_world(bool enabled)
  74. {
  75. return "LevelEditor:enable_debug_render_world(%s)".printf(Lua.bool(enabled));
  76. }
  77. public string enable_debug_physics_world(bool enabled)
  78. {
  79. return "LevelEditor:enable_debug_physics_world(%s)".printf(Lua.bool(enabled));
  80. }
  81. public string set_grid_size(double size)
  82. {
  83. return "LevelEditor:set_grid_size(%f)".printf(size);
  84. }
  85. public string set_rotation_snap(double deg)
  86. {
  87. return "LevelEditor:set_rotation_snap(%f)".printf(MathUtils.rad(deg));
  88. }
  89. public string spawn_unit(Guid id, string name, Vector3 pos, Quaternion rot, Vector3 scl)
  90. {
  91. return "LevelEditor:spawn_unit(\"%s\", \"%s\", %s, %s, %s)".printf(id.to_string()
  92. , name
  93. , Lua.vector3(pos)
  94. , Lua.quaternion(rot)
  95. , Lua.vector3(scl)
  96. );
  97. }
  98. public string spawn_empty_unit(Guid id)
  99. {
  100. return "LevelEditor:spawn_empty_unit(\"%s\")".printf(id.to_string());
  101. }
  102. public string spawn_sound(Guid id, Vector3 pos, Quaternion rot, double range, double volume, bool loop)
  103. {
  104. return "LevelEditor:spawn_sound(\"%s\", %s, %s, %f, %f, %s)".printf(id.to_string()
  105. , Lua.vector3(pos)
  106. , Lua.quaternion(rot)
  107. , range
  108. , volume
  109. , Lua.bool(loop)
  110. );
  111. }
  112. public string add_tranform_component(Guid id, Guid component_id, Vector3 pos, Quaternion rot, Vector3 scl)
  113. {
  114. return "LevelEditor:add_transform_component(\"%s\", \"%s\", %s, %s, %s)".printf(id.to_string()
  115. , component_id.to_string()
  116. , Lua.vector3(pos)
  117. , Lua.quaternion(rot)
  118. , Lua.vector3(scl)
  119. );
  120. }
  121. public string add_mesh_component(Guid id, Guid component_id, string mesh_resource, string geometry_name, string material_resource, bool visible)
  122. {
  123. return "LevelEditor:add_mesh_component(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %s)".printf(id.to_string()
  124. , component_id.to_string()
  125. , mesh_resource
  126. , geometry_name
  127. , material_resource
  128. , Lua.bool(visible)
  129. );
  130. }
  131. public string add_light_component(Guid id, Guid component_id, string type, double range, double intensity, double spot_angle, Vector3 color)
  132. {
  133. return "LevelEditor:add_light_component(\"%s\", \"%s\", \"%s\", %f, %f, %f, %s)".printf(id.to_string()
  134. , component_id.to_string()
  135. , type
  136. , range
  137. , intensity
  138. , spot_angle
  139. , Lua.vector3(color)
  140. );
  141. }
  142. public string move_object(Guid id, Vector3 pos, Quaternion rot, Vector3 scl)
  143. {
  144. return @"LevelEditor:move_object(\"%s\", %s, %s, %s)".printf(id.to_string()
  145. , Lua.vector3(pos)
  146. , Lua.quaternion(rot)
  147. , Lua.vector3(scl)
  148. );
  149. }
  150. public string set_placeable(PlaceableType type, string name)
  151. {
  152. return "LevelEditor:set_placeable(\"%s\", \"%s\")".printf((type == PlaceableType.UNIT ? "unit" : "sound"), name);
  153. }
  154. public string set_selected_unit(Guid id)
  155. {
  156. return @"LevelEditor:set_selected_unit(\"%s\")".printf(id.to_string());
  157. }
  158. public string destroy(Guid id)
  159. {
  160. return @"LevelEditor:destroy(\"%s\")".printf(id.to_string());
  161. }
  162. public string set_color(string name, Vector3 color)
  163. {
  164. Quaternion c = Quaternion(color.x, color.y, color.z, 1.0);
  165. return @"Colors.%s = function() return %s end".printf(name, Lua.quaternion(c));
  166. }
  167. }
  168. }