Skip to content

Commit

Permalink
[#2] Sync neutral state in MP.
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnwop committed Sep 11, 2019
1 parent 901c564 commit afe9924
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions ShuttleDriveDirection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function ShuttleDriveDirection.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "setOnNeutral", ShuttleDriveDirection.setOnNeutral)
SpecializationUtil.registerFunction(vehicleType, "isOnNeutral", ShuttleDriveDirection.isOnNeutral)
SpecializationUtil.registerFunction(vehicleType, "toggleShuttleDriveDirection", ShuttleDriveDirection.toggleShuttleDriveDirection)
SpecializationUtil.registerFunction(vehicleType, "setShuttleDriveDirection", ShuttleDriveDirection.setShuttleDriveDirection)
SpecializationUtil.registerFunction(vehicleType, "setIsHoldingBrake", ShuttleDriveDirection.setIsHoldingBrake)
end

Expand Down Expand Up @@ -171,6 +172,7 @@ function ShuttleDriveDirection:onLeaveVehicle()
spec.overlayForwards:setVisible(false)
spec.overlayBackwards:setVisible(false)
end

self:setOnNeutral()
end

Expand All @@ -183,19 +185,25 @@ function ShuttleDriveDirection:getShuttleDriveDirection()
end

function ShuttleDriveDirection:setOnNeutral()
self.spec_shuttleDriveDirection.shuttleDirection = ShuttleDriveDirection.DIR_NEUTRAL
self:setShuttleDriveDirection(ShuttleDriveDirection.DIR_NEUTRAL)
end

function ShuttleDriveDirection:isOnNeutral()
return self.spec_shuttleDriveDirection.shuttleDirection == ShuttleDriveDirection.DIR_NEUTRAL
end

function ShuttleDriveDirection:toggleShuttleDriveDirection()
local spec = self.spec_shuttleDriveDirection
if self:getShuttleDriveDirection() == ShuttleDriveDirection.DIR_NEUTRAL then
self.spec_shuttleDriveDirection.shuttleDirection = ShuttleDriveDirection.DIR_BACKWARDS
local direction = self:getShuttleDriveDirection()
if self:isOnNeutral() then
direction = ShuttleDriveDirection.DIR_BACKWARDS
end

spec.shuttleDirection = -spec.shuttleDirection
self:setShuttleDriveDirection(-direction)
end

function ShuttleDriveDirection:setShuttleDriveDirection(direction)
local spec = self.spec_shuttleDriveDirection
spec.shuttleDirection = direction

if spec.shuttleDirection ~= spec.shuttleDirectionSent then
spec.shuttleDirectionSent = spec.shuttleDirection
Expand Down
4 changes: 2 additions & 2 deletions loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local function inj_actionEventAccelerate(vehicle, superFunc, actionName, inputVa
spec.lastInputValues.axisAccelerate = axisAccelerate

if vehicle.getHasGuidanceSystem ~= nil and vehicle:getHasGuidanceSystem() then
local guidanceSpec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local guidanceSpec = vehicle.spec_globalPositioningSystem
if guidanceSpec.guidanceSteeringIsActive then
guidanceSpec.axisAccelerate = axisAccelerate
end
Expand All @@ -50,7 +50,7 @@ local function inj_actionEventBrake(vehicle, superFunc, actionName, inputValue,
end

if vehicle.getHasGuidanceSystem ~= nil and vehicle:getHasGuidanceSystem() then
local guidanceSpec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local guidanceSpec = vehicle.spec_globalPositioningSystem
if guidanceSpec.guidanceSteeringIsActive then
local guidanceSignAxis = MathUtil.sign(guidanceSpec.axisForward)
if shuttleDirection == guidanceSignAxis or not guidanceSignAxis ~= 0 then
Expand Down

0 comments on commit afe9924

Please sign in to comment.