Skip to content

Commit

Permalink
Fix bus mission start + async keys
Browse files Browse the repository at this point in the history
  • Loading branch information
my-name-is-samael committed Oct 23, 2024
1 parent 4ba8045 commit 4d6bf2e
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 57 deletions.
2 changes: 1 addition & 1 deletion BeamJoyCore/BeamJoyCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Contact : https://github.com/my-name-is-samael
]]

BJCVERSION = "1.0.2"
BJCVERSION = "1.0.4"

BJCPluginPath = debug.getinfo(1).source:gsub("\\", "/")
BJCPluginPath = BJCPluginPath:sub(1, (BJCPluginPath:find("BeamJoyCore.lua")) - 2)
Expand Down
8 changes: 5 additions & 3 deletions BeamJoyInterface/lua/ge/extensions/BJI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Contact : https://github.com/my-name-is-samael
]]

BJIVERSION = "1.0.2"
BJIVERSION = "1.0.4"

local managers = {}
function GetBJIManagers()
Expand Down Expand Up @@ -128,7 +128,9 @@ M.onWorldReadyState = function(state)
end

M.onPreRender = function() end
M.onUpdate = BJITick.client
M.onUpdate = function(...)
BJITick.client()
end

commands.dropPlayerAtCamera = function(...)
TriggerBJIEvent("onDropPlayerAtCamera", ...)
Expand All @@ -146,7 +148,7 @@ M.onVehicleResetted = function(gameVehID)
BJIAsync.delayTask(function()
-- delay execution or else vehicle can't be own
TriggerBJIEvent("onVehicleResetted", gameVehID)
end, 100)
end, 100, svar("BJIVehReset{1}", { gameVehID }))
end
M.onVehicleDestroyed = function(...)
TriggerBJIEvent("onVehicleDestroyed", ...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ local function parseCache(cacheType, cacheData, cacheHash)
end
-- update nametags
BJINametags.tryUpdate()
end)
end, "BJICacheFreeroamReady")
elseif cacheType == M.CACHES.GROUPS then
for groupName, group in pairs(cacheData) do
if not BJIPerm.Groups[groupName] then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ end
-- on spawn or reset
local function onVehicleResetted(gameVehID)
if M.type ~= M.TYPES.GHOSTS or
gameVehID == -1 or
not BJIVeh.getVehicleObject(gameVehID) or
BJIAI.isAIVehicle(gameVehID) or
BJIVeh.isUnicycle(gameVehID) then
Expand All @@ -144,13 +145,10 @@ end
local function renderTick(ctxt)
local nextType = BJIScenario.getCollisionsType(ctxt)
if nextType ~= M.type then
if nextType == M.TYPES.FORCED then
setCollisions(true)
M.ghosts = {}
elseif nextType == M.TYPES.DISABLED then
setCollisions(false)
if nextType ~= M.TYPES.GHOSTS then
M.ghosts = {}
elseif nextType == M.TYPES.GHOSTS then
setCollisions(nextType == M.TYPES.FORCED)
else
if M.type == M.TYPES.DISABLED then
setCollisions(not areCloseVehicles(ctxt.isOwner and ctxt.veh:getID() or nil))
else
Expand All @@ -162,15 +160,11 @@ local function renderTick(ctxt)

-- GHOST RULES
if M.type == M.TYPES.GHOSTS then
-- clear invalid ghosts
for g in pairs(M.ghosts) do
if not BJIVeh.getVehicleObject(g) or
BJIAI.isAIVehicle(g) then
M.ghosts[g] = nil
end
end

if ctxt.isOwner then
if M.ghosts[ctxt.veh:getID()] then
-- remove self from ghosts
M.ghosts[ctxt.veh:getID()] = nil
end
if M.state then
if M.selfGhost then
setCollisions(false)
Expand All @@ -195,28 +189,60 @@ local function renderTick(ctxt)
end
end

if ctxt.isOwner and M.alphas[ctxt.veh:getID()] ~= M.playerAlpha then
M.alphas[ctxt.veh:getID()] = M.playerAlpha
for _, veh in pairs(BJIVeh.getMPVehicles()) do
if veh.gameVehicleID ~= -1 then
local alpha = M.playerAlpha
if not M.state then
local isSelf = ctxt.isOwner and veh.gameVehicleID == ctxt.veh:getID()
if not isSelf and ctxt.isOwner then
local target = BJIVeh.getVehicleObject(veh.gameVehicleID)
local posRot = target and BJIVeh.getPositionRotation(target) or nil
if posRot then
local dist = ctxt.vehPosRot.pos:distance(posRot.pos)
local maxDist = getGhostDistance(ctxt.veh, target)
alpha = getAlphaByDistance(dist, maxDist)
end
end
end
if M.alphas[veh.gameVehicleID] ~= alpha then
local targetAlpha = alpha ~= M.playerAlpha and alpha or nil
M.alphas[veh.gameVehicleID] = targetAlpha
setAlpha(veh.gameVehicleID, alpha)
end
end
end
end

local vehs = BJIVeh.getMPVehicles()
for _, vehData in pairs(vehs) do
local alpha = M.playerAlpha
if not M.state then
local isSelf = ctxt.isOwner and vehData.gameVehicleID == ctxt.veh:getID()
if not isSelf and ctxt.isOwner then
local target = BJIVeh.getVehicleObject(vehData.gameVehicleID)
local posRot = target and BJIVeh.getPositionRotation(target) or nil
if posRot then
local dist = ctxt.vehPosRot.pos:distance(posRot.pos)
local maxDist = getGhostDistance(ctxt.veh, target)
alpha = getAlphaByDistance(dist, maxDist)
end
local function slowTick(ctxt)
if M.type == M.TYPES.GHOSTS then
-- clear invalid ghosts
for g in pairs(M.ghosts) do
if not BJIVeh.getVehicleObject(g) or
BJIAI.isAIVehicle(g) then
M.ghosts[g] = nil
end
end
if M.alphas[vehData.gameVehicleID] ~= alpha then
M.alphas[vehData.gameVehicleID] = alpha
setAlpha(vehData.gameVehicleID, alpha)
end

-- invalid alpha target fix
if M.alphas[-1] then
M.alphas[-1] = nil
end

-- clear invalid alphas
for g in pairs(M.alphas) do
if not BJIVeh.getVehicleObject(g) then
M.alphas[g] = nil
end
end

if ctxt.veh then
local vehID = ctxt.veh:getID()
if M.alphas[vehID] ~= M.playerAlpha then
M.alphas[vehID] = nil
setAlpha(vehID, M.playerAlpha)
elseif getVehAlpha(vehID) ~= M.playerAlpha then
setAlpha(vehID, M.playerAlpha)
end
end
end
Expand All @@ -225,6 +251,7 @@ M.onVehicleResetted = onVehicleResetted
M.onVehicleSwitched = onVehicleSwitched

M.renderTick = renderTick
M.slowTick = slowTick

RegisterBJIManager(M)
return M
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ local function renderTick(ctxt) -- render tick
function()
M.Data.fogDensity = oldFog
end,
"bigmapFog"
"BJIBigmapFog"
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ local function initClient()
end,
function()
BJITx.player.lang(lang)
end
end,
"BJILangInit"
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local function onLoad()
-- REPOSITORY
M.baseFunctions.modSubscribe = core_repository.modSubscribe
M.baseFunctions.modUnsubscribe = core_repository.modUnsubscribe
end)
end, "BJIModsInit")
end

local function onUnload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ local function engine(state, gameVehID)
if state then
BJIAsync.delayTask(function()
vehicle:queueLuaCommand('controller.mainController.setStarter(false)')
end, 1000)
end, 1000, "BJIEngineStartDelayStarter")
end
-- vehicle:queueLuaCommand(svar("electrics.horn({1})", { state }))
end
Expand Down
1 change: 1 addition & 0 deletions BeamJoyInterface/lua/ge/extensions/BJI/rx/Controllers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ local function tryFinalizingEvent(id)
end

retrievingEvents[id] = nil
BJIAsync.removeTask(svar("BJIRxEventTimeout-{1}", { id }))
end

local function retrieveEvent(rawData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ local firstMessagesOffset = 0
function ctrl.chat(data)
local event, chatData = data[1], data[2]
chatData.color = chatData.color and RGBA(chatData.color[1], chatData.color[2], chatData.color[3], chatData.color[4]) or
nil
nil

if BJIContext.WorldReadyState ~= 2 then
-- first message
BJIAsync.task(function()
return BJIContext.WorldReadyState == 2
end, function()
BJIAsync.delayTask(function()
BJIChat.onChat(event, chatData)
end, 3000 + firstMessagesOffset)
BJIChat.onChat(event, chatData)
end, 3000 + firstMessagesOffset,
svar("BJIChatReadyDelay{1}", { GetCurrentTimeMillis() }))
firstMessagesOffset = firstMessagesOffset + 10
end)
end, "BJIChatReadyWorld")
else
BJIChat.onChat(event, chatData)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ local function initDrive(ctxt)
local startPosRot = M.line.stops[1]
BJIVeh.replaceOrSpawnVehicle(M.model, M.config, startPosRot)
BJIAsync.task(function(ctxt2)
return ctxt2.isOwner and tdeepcompare(BJIVeh.getFullConfig(ctxt2.veh.partConfig), M.config)
return ctxt2.isOwner and
not BJIVeh.isConfigCustom(ctxt2.veh.partConfig) and
ctxt2.veh.partConfig:find(svar("/{1}.", {M.config}))
end, function()
M.state = M.STATES.DRIVE
updateTarget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ BJIAsync.task(
function()
return BJICache.areBaseCachesFirstLoaded() and BJICache.isFirstLoaded(BJICache.CACHES.MAP)
end,
init
init, "BJIScenarioInit"
)

local function onVehicleSpawned(gameVehID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ local function onStandStop(delayMs, wp, callback)
BJICam.setCamera(ctxt3.camera)
end
end, 100, "BJIRaceCameraCheckAndFreeze")
end, delayMs - 3000)
end, delayMs - 3000, "BJIRacePreStart")

BJIAsync.delayTask(function()
BJIVeh.freeze(false)
Expand All @@ -503,12 +503,12 @@ local function onStandStop(delayMs, wp, callback)
-- delays reset restriction remove
BJIRestrictions.apply(BJIRestrictions.TYPES.Reset, false)
M.dnf.standExempt = false
end, 1000)
end, 1000, "BJIRacePostStart")
end
if type(callback) == "function" then
callback()
end
end, delayMs)
end, delayMs, "BJIRaceStart")
end

local function drawTimeDiff(lap, wp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ local function initDelivery()
if M.previousCamera then
BJIAsync.delayTask(function()
BJICam.setCamera(M.previousCamera, false)
end, 100)
end, 100, "BJIVehDeliveryCamera")
end

BJIGPS.prependWaypoint(BJIGPS.KEYS.DELIVERY_TARGET, M.targetPosition.pos,
Expand Down Expand Up @@ -264,7 +264,7 @@ local function onTargetReached(ctxt)
if BJIScenario.isFreeroam() then
BJIScenario.switchScenario(BJIScenario.TYPES.VEHICLE_DELIVERY, ctxt)
end
end, 3000)
end, 3000, "BJIVehDeliveryLoop")
end

reset()
Expand Down
4 changes: 2 additions & 2 deletions BeamJoyInterface/lua/ge/extensions/BJI/ui/WindowBJI/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ local function getScenarioEntry(ctxt)
onClick = function()
BJIAsync.delayTask(function()
BJIScenario.switchScenario(BJIScenario.TYPES.PACKAGE_DELIVERY, ctxt)
end, 0)
end, 0, "BJIPackageDeliveryStart")
end,
})
elseif BJIScenario.is(BJIScenario.TYPES.PACKAGE_DELIVERY) and
Expand Down Expand Up @@ -286,7 +286,7 @@ local function getScenarioEntry(ctxt)
onClick = function()
BJIAsync.delayTask(function()
BJIScenario.switchScenario(BJIScenario.TYPES.BUS_MISSION, ctxt)
end, 0)
end, 0, "BJIBusMissionStart")
end,
})
elseif BJIScenario.is(BJIScenario.TYPES.BUS_MISSION) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ local function saveRace(callback)
end
end
return false
end, function() end)
end, function() end, "BJIRaceSave")
end
raceEdit.hasRecord = raceEdit.hasRecord and raceEdit.keepRecord
raceEdit.keepRecord = true
Expand Down Expand Up @@ -514,7 +514,7 @@ local function drawStartPositions(vehpos, campos, ctxt)
icon = ICONS.crosshair,
background = BTN_PRESETS.WARNING,
disabled = not vehpos or ctxt.camera == BJICam.CAMERAS.FREE or
raceEdit.processSave,
raceEdit.processSave,
onClick = function()
sp.pos = vehpos.pos
sp.rot = vehpos.rot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ local function onRepair(veh)
BJIVeh.engine(wasEngine, veh.vehGameID)
BJICam.resetForceCamera()
BJIContext.User.stationProcess = false
end, 5000)
end, 5000, "BJIStationRefill")
end

local function commonDrawEnergyLines(veh, energyStation)
Expand Down

0 comments on commit 4d6bf2e

Please sign in to comment.