Explorar el Código

Add tools API

Daniele Bartolini hace 9 años
padre
commit
89b41faa39
Se han modificado 4 ficheros con 275 adiciones y 0 borrados
  1. 30 0
      tools/api/engine_api.vala
  2. 191 0
      tools/api/level_editor_api.vala
  3. 33 0
      tools/api/lua.vala
  4. 21 0
      tools/api/unit_preview_api.vala

+ 30 - 0
tools/api/engine_api.vala

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
+ */
+
+namespace Crown
+{
+	namespace EngineAPI
+	{
+		public string compile(string type, string name, string platform)
+		{
+			return "{\"type\":\"compile\",\"resource_type\":\"%s\",\"resource_name\":\"%s\",\"platform\":\"%s\"}".printf(type, name, platform);
+		}
+
+		public string reload(string type, string name)
+		{
+			return "{\"type\":\"reload\",\"resource_type\":\"%s\",\"resource_name\":\"%s\"}".printf(type, name);
+		}
+
+		public string pause()
+		{
+			return "{\"type\":\"pause\"}";
+		}
+
+		public string unpause()
+		{
+			return "{\"type\":\"unpause\"}";
+		}
+	}
+}

+ 191 - 0
tools/api/level_editor_api.vala

@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
+ */
+
+namespace Crown
+{
+	namespace LevelEditorAPI
+	{
+		public string reset()
+		{
+			return "LevelEditor:reset()";
+		}
+
+		public string set_mouse_state(int x, int y, bool left, bool middle, bool right)
+		{
+			return "LevelEditor:set_mouse_state(%d,%d,%s,%s,%s)".printf(x
+				, y
+				, Lua.bool(left)
+				, Lua.bool(middle)
+				, Lua.bool(right)
+				);
+		}
+
+		public string set_mouse_move(int x, int y, int dx, int dy)
+		{
+			return "LevelEditor:set_mouse_move(%d,%d,%d,%d)".printf(x, y, dx, dy);
+		}
+
+		public string set_mouse_wheel(double delta)
+		{
+			return "LevelEditor:set_mouse_wheel(%f)".printf(delta);
+		}
+
+		public string set_mouse_down(int x, int y)
+		{
+			return "LevelEditor:mouse_down(%d,%d)".printf(x, y);
+		}
+
+		public string set_mouse_up(int x, int y)
+		{
+			return "LevelEditor:mouse_up(%d,%d)".printf(x, y);
+		}
+
+		public string set_key_down(string key)
+		{
+			return "LevelEditor:key_down(\"%s\")".printf(key);
+		}
+
+		public string set_key_up(string key)
+		{
+			return "LevelEditor:key_up(\"%s\")".printf(key);
+		}
+
+		private const string[] _tools =
+		{
+			"place_tool",
+			"move_tool",
+			"rotate_tool",
+			"scale_tool"
+		};
+
+		public string set_tool_type(ToolType type)
+		{
+			return "LevelEditor:set_tool(LevelEditor.%s)".printf(_tools[(int)type]);
+		}
+
+		public string set_snap_mode(SnapMode sm)
+		{
+			return """LevelEditor:set_snap_mode("%s")""".printf(sm == SnapMode.Relative ? "relative" : "absolute");
+		}
+
+		public string set_reference_system(ReferenceSystem rs)
+		{
+			return """LevelEditor:set_reference_system("%s")""".printf(rs == ReferenceSystem.Local ? "local" : "world");
+		}
+
+		public string enable_show_grid(bool enabled)
+		{
+			return "LevelEditor:enable_show_grid(%s)".printf(Lua.bool(enabled));
+		}
+
+		public string enable_snap_to_grid(bool enabled)
+		{
+			return "LevelEditor:enable_snap_to_grid(%s)".printf(Lua.bool(enabled));
+		}
+
+		public string enable_debug_render_world(bool enabled)
+		{
+			return "LevelEditor:enable_debug_render_world(%s)".printf(Lua.bool(enabled));
+		}
+
+		public string enable_debug_physics_world(bool enabled)
+		{
+			return "LevelEditor:enable_debug_physics_world(%s)".printf(Lua.bool(enabled));
+		}
+
+		public string set_grid_size(double size)
+		{
+			return "LevelEditor:set_grid_size(%f)".printf(size);
+		}
+
+		public string set_rotation_snap(double deg)
+		{
+			return "LevelEditor:set_rotation_snap(%f)".printf(MathUtils.rad(deg));
+		}
+
+		public string spawn_unit(Guid id, string name, Vector3 pos, Quaternion rot, Vector3 scl)
+		{
+			return "LevelEditor:spawn_unit(\"%s\", \"%s\", %s, %s, %s)".printf(id.to_string()
+				, name
+				, Lua.vector3(pos)
+				, Lua.quaternion(rot)
+				, Lua.vector3(scl)
+				);
+		}
+
+		public string spawn_empty_unit(Guid id)
+		{
+			return "LevelEditor:spawn_empty_unit(\"%s\")".printf(id.to_string());
+		}
+
+		public string spawn_sound(Guid id, Vector3 pos, Quaternion rot, double range, double volume, bool loop)
+		{
+			return "LevelEditor:spawn_sound(\"%s\", %s, %s, %f, %f, %s)".printf(id.to_string()
+				, Lua.vector3(pos)
+				, Lua.quaternion(rot)
+				, range
+				, volume
+				, Lua.bool(loop)
+				);
+		}
+
+		public string add_tranform_component(Guid id, Guid component_id, Vector3 pos, Quaternion rot, Vector3 scl)
+		{
+			return "LevelEditor:add_transform_component(\"%s\", \"%s\", %s, %s, %s)".printf(id.to_string()
+				, component_id.to_string()
+				, Lua.vector3(pos)
+				, Lua.quaternion(rot)
+				, Lua.vector3(scl)
+				);
+		}
+
+		public string add_mesh_component(Guid id, Guid component_id, string mesh_resource, string geometry_name, string material_resource, bool visible)
+		{
+			return "LevelEditor:add_mesh_component(\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %s)".printf(id.to_string()
+				, component_id.to_string()
+				, mesh_resource
+				, geometry_name
+				, material_resource
+				, Lua.bool(visible)
+				);
+		}
+
+		public string add_light_component(Guid id, Guid component_id, string type, double range, double intensity, double spot_angle, Vector3 color)
+		{
+			return "LevelEditor:add_light_component(\"%s\", \"%s\", \"%s\", %f, %f, %f, %s)".printf(id.to_string()
+				, component_id.to_string()
+				, type
+				, range
+				, intensity
+				, spot_angle
+				, Lua.vector3(color)
+				);
+		}
+
+		public string move_object(Guid id, Vector3 pos, Quaternion rot, Vector3 scl)
+		{
+			return @"LevelEditor:move_object(\"%s\", %s, %s, %s)".printf(id.to_string()
+				, Lua.vector3(pos)
+				, Lua.quaternion(rot)
+				, Lua.vector3(scl)
+				);
+		}
+
+		public string set_placeable(PlaceableType type, string name)
+		{
+			return "LevelEditor:set_placeable(\"%s\", \"%s\")".printf((type == PlaceableType.Unit ? "unit" : "sound"), name);
+		}
+
+		public string set_selected_unit(Guid id)
+		{
+			return @"LevelEditor:set_selected_unit(\"%s\")".printf(id.to_string());
+		}
+
+		public string destroy(Guid id)
+		{
+			return @"LevelEditor:destroy(\"%s\")".printf(id.to_string());
+		}
+	}
+}

+ 33 - 0
tools/api/lua.vala

@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
+ */
+
+namespace Crown
+{
+	/// <summary>
+	/// Functions to encode Vala types to Lua.
+	/// </summary>
+	namespace Lua
+	{
+		public string bool(bool b)
+		{
+			return b == true ? "true" : "false";
+		}
+
+		public string vector2(Vector2 v)
+		{
+			return "Vector2(%f, %f)".printf(v.x, v.y);
+		}
+
+		public string vector3(Vector3 v)
+		{
+			return "Vector3(%f, %f, %f)".printf(v.x, v.y, v.z);
+		}
+
+		public string quaternion(Quaternion q)
+		{
+			return "Quaternion.from_elements(%f, %f, %f, %f)".printf(q.x, q.y, q.z, q.w);
+		}
+	}
+}

+ 21 - 0
tools/api/unit_preview_api.vala

@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE-GPLv2
+ */
+
+namespace Crown
+{
+	namespace UnitPreviewAPI
+	{
+		const string[] _placeables =
+		{
+			"unknown",
+			"core/units/sound",
+		};
+
+		public string set_preview_unit(PlaceableType placeable_type, string name)
+		{
+			return "UnitPreview:set_preview_unit(\"%s\")".printf(placeable_type == PlaceableType.Unit ? name : _placeables[(int)placeable_type]);
+		}
+	}
+}