Browse Source

world: do not break existing scripts

Daniele Bartolini 4 tháng trước cách đây
mục cha
commit
018bdade02

+ 0 - 1
docs/changelog.rst

@@ -22,7 +22,6 @@ Changelog
 * Runtime: the sound subsystem now uses a more realistic attenuation model based on inverse distance of sounds from the listener.
 * Runtime: added the ability to play mono sounds as 2d sounds (i.e. without attenuation nor spatialization).
 * Lua: changed the order of arguments of ``World.play_sound()`` to support 2d sounds playback with a single API.
-* Lua: swapped the order of the `units` and `world` parameters in ``spawned`` and ``unspawned`` callbacks in unit scripts.
 * Lua: removed 'pose' parameter from the following component creation functions:
 
 	- ``World.camera_create()``

+ 2 - 2
docs/gameplay/unit_interaction.rst

@@ -58,7 +58,7 @@ Crown will create a new Unit script similar to the following:
 
 	local data = MyScript.data
 
-	function MyScript.spawned(units, world)
+	function MyScript.spawned(world, units)
 		if data[world] == nil then data[world] = {} end
 
 		for uu = 1, #units do
@@ -77,7 +77,7 @@ Crown will create a new Unit script similar to the following:
 		-- Called once per frame.
 	end
 
-	function MyScript.unspawned(units, world)
+	function MyScript.unspawned(world, units)
 		-- Cleanup.
 		for uu = 1, #units do
 			if data[world][units] then

+ 2 - 2
samples/02-animation/units/environment/tree.lua

@@ -7,7 +7,7 @@ Tree = Tree or {
 
 local data = Tree.data
 
-function Tree.spawned(units, world)
+function Tree.spawned(world, units)
 	if data[world] == nil then
 		data[world] = {}
 	end
@@ -31,7 +31,7 @@ function Tree.spawned(units, world)
 	end
 end
 
-function Tree.unspawned(units, world)
+function Tree.unspawned(world, units)
 	-- Cleanup.
 	for uu = 1, #units do
 		if data[world][units] then

+ 2 - 2
samples/core/components/noop.lua

@@ -3,10 +3,10 @@
 
 local Behavior = Behavior or {}
 
-function Behavior.spawned(units, world)
+function Behavior.spawned(world, units)
 end
 
-function Behavior.unspawned(units, world)
+function Behavior.unspawned(world, units)
 end
 
 function Behavior.update(world, dt)

+ 2 - 2
samples/core/units/common.lua

@@ -3,7 +3,7 @@
 
 local Behavior = Behavior or {}
 
-function Behavior.spawned(units, world)
+function Behavior.spawned(world, units)
 	for uu = 1, #units do
 		local unit = units[uu]
 
@@ -19,7 +19,7 @@ end
 function Behavior.update(world, dt)
 end
 
-function Behavior.unspawned(units, world)
+function Behavior.unspawned(world, units)
 end
 
 return Behavior

+ 2 - 2
src/world/script_world.cpp

@@ -220,6 +220,8 @@ namespace script_world
 		lua_rawgeti(stack.L, LUA_REGISTRYINDEX, index[0].module_ref);
 		lua_getfield(stack.L, -1, function_name);
 
+		stack.push_args(arg_types, args, num_args);
+
 		stack.push_table(num_indices);
 		for (u32 i = 0; i < num_indices; ++i) {
 			stack.push_key_begin(1 + i);
@@ -227,8 +229,6 @@ namespace script_world
 			stack.push_key_end();
 		}
 
-		stack.push_args(arg_types, args, num_args);
-
 		int status = sw._lua_environment->call(1 + num_args, 0);
 		if (status != LUA_OK) {
 			report(stack.L, status);

+ 2 - 2
tools/level_editor/project.vala

@@ -321,7 +321,7 @@ public class Project
 					+ "\n"
 					+ "\nlocal data = Behavior.data"
 					+ "\n"
-					+ "\nfunction Behavior.spawned(units, world)"
+					+ "\nfunction Behavior.spawned(world, units)"
 					+ "\n	if data[world] == nil then"
 					+ "\n		data[world] = {}"
 					+ "\n	end"
@@ -342,7 +342,7 @@ public class Project
 					+ "\n	-- Called once per frame."
 					+ "\nend"
 					+ "\n"
-					+ "\nfunction Behavior.unspawned(units, world)"
+					+ "\nfunction Behavior.unspawned(world, units)"
 					+ "\n	-- Cleanup."
 					+ "\n	for uu = 1, #units do"
 					+ "\n		if data[world][units] then"