aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/api_doc.txt7
-rw-r--r--advtrains/wagons.lua6
-rwxr-xr-xadvtrains_train_steam/init.lua4
3 files changed, 11 insertions, 6 deletions
diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt
index 9ea3cb6..e86f16b 100644
--- a/advtrains/api_doc.txt
+++ b/advtrains/api_doc.txt
@@ -99,8 +99,9 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
^- optional: Execute custom code on every step
custom_on_activate = function(self, dtime_s) end
^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads.
- update_animation = function(self, velocity) end
- ^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed.
+ custom_on_velocity_change = function(self, velocity, old_velocity) end
+ ^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed.
+ ^- for compatibility reasons the name 'update_animation' for this function is still supported.
}
@@ -164,4 +165,4 @@ minetest.register_node(nodename, {
on_train_leave=function(pos, train_id) end
^- called when a train leaves the rail
}
-}) \ No newline at end of file
+})
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 3892813..4306b50 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -502,12 +502,16 @@ function wagon:on_step(dtime)
self.object:setyaw(yaw)
self.updatepct_timer=2
if self.update_animation then
- self:update_animation(gp.velocity)
+ self:update_animation(gp.velocity, self.old_velocity)
+ end
+ if self.custom_on_velocity_change then
+ self:custom_on_velocity_change(gp.velocity, self.old_velocity)
end
end
self.old_velocity_vector=velocityvec
+ self.old_velocity = gp.velocity
self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw
atprintbm("wagon step", t)
diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua
index 315104a..37c63a0 100755
--- a/advtrains_train_steam/init.lua
+++ b/advtrains_train_steam/init.lua
@@ -37,7 +37,7 @@ advtrains.register_wagon("newlocomotive", {
visual_size = {x=1, y=1},
wagon_span=2.3,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
- update_animation=function(self, velocity)
+ custom_on_velocity_change=function(self, velocity)
if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
self.old_anim_velocity=advtrains.abs_ceil(velocity)
@@ -105,7 +105,7 @@ advtrains.register_wagon("detailed_steam_engine", {
visual_size = {x=1, y=1},
wagon_span=2.05,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
- update_animation=function(self, velocity)
+ custom_on_velocity_change=function(self, velocity)
if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
self.old_anim_velocity=advtrains.abs_ceil(velocity)