Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
5ca5ce8bac | |||
d245d00706 | |||
17d90c2699 | |||
5929cdff5f | |||
5eaf701f91 | |||
11cad0c721 | |||
014cc7dc20 | |||
0802e82456 |
@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.dependencies = { 'career_modules_inventory', 'freeroam_facilities', "career_vehicleSaveSystem" }
|
M.dependencies = { 'career_modules_inventory', 'freeroam_facilities', "career_vehicleSaveSystem",
|
||||||
|
"career_modules_permissions", 'career_modules_valueCalculator' }
|
||||||
|
|
||||||
local career_modules_inventory_removeVehicleObject
|
local career_modules_inventory_removeVehicleObject
|
||||||
local vehicleObjectsToRemove = {}
|
local vehicleObjectsToRemove = {}
|
||||||
@ -28,31 +29,48 @@ local function spawnVehicle(inventoryId, callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function Retrieve()
|
local function Retrieve(inventoryId)
|
||||||
local fav_veh_id = career_modules_inventory.getFavoriteVehicle()
|
career_vehicleSaveSystem.EnqueueVehicleToSave(inventoryId)
|
||||||
|
if not career_vehicleSaveSystem.SaveVehicle(inventoryId) then
|
||||||
|
career_vehicleSaveSystem.DequeueVehicleToSave(inventoryId)
|
||||||
|
end
|
||||||
|
|
||||||
extensions.core_jobsystem.create(
|
local vehicleValue = career_modules_valueCalculator.getInventoryVehicleValue(inventoryId, true)
|
||||||
function(job)
|
local currentVehicleValue = career_modules_valueCalculator.getInventoryVehicleValue(inventoryId)
|
||||||
spawnVehicle(fav_veh_id, function()
|
|
||||||
local veh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(fav_veh_id))
|
career_vehicleSaveSystem.CheckSavedAsync(function()
|
||||||
local location = { pos = veh:getPosition(), rot = quat(0, 0, 1, 0) * quat(veh:getRefNodeRotation()) }
|
extensions.core_jobsystem.create(
|
||||||
local garage = career_modules_inventory.getClosestGarage(location.pos)
|
function(job)
|
||||||
|
career_vehicleSaveSystem.SetFade(true)
|
||||||
job.sleep(1)
|
job.sleep(1)
|
||||||
career_vehicleSaveSystem.LoadVehicle(fav_veh_id)
|
spawnVehicle(inventoryId, function()
|
||||||
freeroam_facilities.teleportToGarage(garage.id, veh, false)
|
career_vehicleSaveSystem.TeleportVehicle(inventoryId, false)
|
||||||
end)
|
career_vehicleSaveSystem.LoadVehicle(inventoryId, currentVehicleValue < vehicleValue)
|
||||||
end
|
end)
|
||||||
)
|
end
|
||||||
|
)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onComputerAddFunctions(menuData, computerFunctions)
|
local function onComputerAddFunctions(menuData, computerFunctions)
|
||||||
if menuData.computerFacility.functions["vehicleInventory"] then
|
if menuData.computerFacility.functions["vehicleInventory"] then
|
||||||
|
local favouriteVehicleId = career_modules_inventory.getFavoriteVehicle()
|
||||||
|
|
||||||
local computerFunctionData = {
|
local computerFunctionData = {
|
||||||
id = "retrieve_damaged",
|
id = "retrieve_damaged",
|
||||||
label = "Retrieve Favourite Damaged",
|
label = "Retrieve Favourite Damaged",
|
||||||
callback = Retrieve,
|
callback = function() Retrieve(favouriteVehicleId) end,
|
||||||
order = 1
|
order = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local repairPermission = career_modules_permissions.getStatusForTag("vehicleRepair",
|
||||||
|
{ inventoryId = favouriteVehicleId })
|
||||||
|
|
||||||
|
if not repairPermission["allow"] then
|
||||||
|
computerFunctionData.disabled = true
|
||||||
|
computerFunctionData.reason = { type = "text", label = "Vehicle is being repaired." }
|
||||||
|
end
|
||||||
|
|
||||||
if menuData.tutorialPartShoppingActive or menuData.tutorialTuningActive then
|
if menuData.tutorialPartShoppingActive or menuData.tutorialTuningActive then
|
||||||
computerFunctionData.disabled = true
|
computerFunctionData.disabled = true
|
||||||
computerFunctionData.reason = career_modules_computer.reasons.tutorialActive
|
computerFunctionData.reason = career_modules_computer.reasons.tutorialActive
|
||||||
@ -63,7 +81,7 @@ end
|
|||||||
|
|
||||||
local function RemoveVehicleObject(inventoryId)
|
local function RemoveVehicleObject(inventoryId)
|
||||||
table.insert(vehicleObjectsToRemove, inventoryId)
|
table.insert(vehicleObjectsToRemove, inventoryId)
|
||||||
career_vehicleSaveSystem.QueueVehicleToSave(inventoryId)
|
career_vehicleSaveSystem.EnqueueVehicleToSave(inventoryId)
|
||||||
career_vehicleSaveSystem.SaveVehicle(inventoryId)
|
career_vehicleSaveSystem.SaveVehicle(inventoryId)
|
||||||
career_vehicleSaveSystem.CheckSavedAsync(function()
|
career_vehicleSaveSystem.CheckSavedAsync(function()
|
||||||
career_modules_inventory_removeVehicleObject(inventoryId)
|
career_modules_inventory_removeVehicleObject(inventoryId)
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.dependencies = { 'career_career', 'career_saveSystem', 'career_modules_inventory' }
|
M.dependencies = { 'freeroam_facilities', 'ui_fadeScreen', 'career_career', 'career_saveSystem',
|
||||||
|
'career_modules_inventory' }
|
||||||
|
|
||||||
local extensionName = "career_vehicleSaveSystem"
|
local extensionName = "career_vehicleSaveSystem"
|
||||||
local vehicleSaves_temp = "/temp/career/vehicle_saves"
|
local vehicleSaves_temp = "/temp/career/vehicle_saves"
|
||||||
@ -65,13 +66,50 @@ local function GetVehicleSaveFile(root, inventoryId)
|
|||||||
return path .. "/save.json"
|
return path .. "/save.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function QueueVehicleToSave(inventoryId)
|
local function EnqueueVehicleToSave(inventoryId)
|
||||||
|
log("I", "saving", "enqueued vehicle " .. inventoryId)
|
||||||
M.queuedVehicleSaves[inventoryId] = true
|
M.queuedVehicleSaves[inventoryId] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function QueuedVehicleSaved(inventoryId)
|
local function DequeueVehicleToSave(inventoryId)
|
||||||
log("I", "saving", "saved vehicle " .. inventoryId)
|
log("I", "saving", "dequeued vehicle " .. inventoryId)
|
||||||
table.remove(M.queuedVehicleSaves, inventoryId)
|
M.queuedVehicleSaves[inventoryId] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function TeleportVehicle(inventoryId, delayed, callback)
|
||||||
|
log("I", "loading", "teleporting vehicle " .. inventoryId)
|
||||||
|
|
||||||
|
local veh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(inventoryId))
|
||||||
|
local location = { pos = veh:getPosition(), rot = quat(0, 0, 1, 0) * quat(veh:getRefNodeRotation()) }
|
||||||
|
local garage = career_modules_inventory.getClosestGarage(location.pos)
|
||||||
|
|
||||||
|
extensions.core_jobsystem.create(function(job)
|
||||||
|
if delayed then
|
||||||
|
job.sleep(1)
|
||||||
|
end
|
||||||
|
freeroam_facilities.teleportToGarage(garage.id, veh, false)
|
||||||
|
|
||||||
|
if callback then
|
||||||
|
callback()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local fadeInProgress = false
|
||||||
|
local function SetFade(fade)
|
||||||
|
if fadeInProgress and fade then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not fadeInProgress and not fade then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if fade then
|
||||||
|
ui_fadeScreen.start(0.5)
|
||||||
|
fadeInProgress = true
|
||||||
|
else
|
||||||
|
ui_fadeScreen.stop(0.5)
|
||||||
|
fadeInProgress = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function VehiclesSaved()
|
local function VehiclesSaved()
|
||||||
@ -108,22 +146,51 @@ local function SaveVehicle(inventoryId)
|
|||||||
local object = be:getObjectByID(vehicleId)
|
local object = be:getObjectByID(vehicleId)
|
||||||
object:queueLuaCommand("beamstate.save(\"" ..
|
object:queueLuaCommand("beamstate.save(\"" ..
|
||||||
saveFile ..
|
saveFile ..
|
||||||
"\"); obj:queueGameEngineLua('career_vehicleSaveSystem.QueuedVehicleSaved(\"" .. inventoryId .. "\")')")
|
"\"); obj:queueGameEngineLua('career_vehicleSaveSystem.DequeueVehicleToSave(" .. inventoryId .. ")');")
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
log('I', 'saving', 'vehicle ' .. inventoryId .. " not spawned")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function LoadVehicle(inventoryId)
|
local function FinishedLoading(inventoryId)
|
||||||
|
M.SetFade(false)
|
||||||
|
local veh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(inventoryId))
|
||||||
|
local pos, _ = freeroam_facilities.getGaragePosRot(career_modules_inventory.getClosestGarage(), veh)
|
||||||
|
career_modules_playerDriving.showPosition(pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function LoadVehicle(inventoryId, loadDamaged)
|
||||||
local saveFile = GetVehicleSaveFile(vehicleSaves_temp, inventoryId)
|
local saveFile = GetVehicleSaveFile(vehicleSaves_temp, inventoryId)
|
||||||
|
|
||||||
local vehicleId = career_modules_inventory.getVehicleIdFromInventoryId(inventoryId)
|
local vehicleId = career_modules_inventory.getVehicleIdFromInventoryId(inventoryId)
|
||||||
if vehicleId then
|
if vehicleId then
|
||||||
log("I", "loading", "loading vehicle from " .. saveFile)
|
log("I", "loading", "loading vehicle from " .. saveFile)
|
||||||
local object = be:getObjectByID(vehicleId)
|
if loadDamaged then
|
||||||
object:queueLuaCommand("beamstate.load(\"" ..
|
local object = be:getObjectByID(vehicleId)
|
||||||
saveFile .. "\")")
|
object:queueLuaCommand(
|
||||||
|
"beamstate.load(\"" .. saveFile .. "\"); " ..
|
||||||
|
"for key, value in pairs(v.data.controller) do " ..
|
||||||
|
" if value['fileName'] == 'advancedCouplerControl' then " ..
|
||||||
|
" local c = controller.getController(value['name']) " ..
|
||||||
|
" if c['reset'] then " ..
|
||||||
|
" c['reset']() " ..
|
||||||
|
" end " ..
|
||||||
|
" end " ..
|
||||||
|
" end; " ..
|
||||||
|
" obj:queueGameEngineLua(' " ..
|
||||||
|
" career_vehicleSaveSystem.TeleportVehicle( " ..
|
||||||
|
" " .. inventoryId .. ", " ..
|
||||||
|
" true, " ..
|
||||||
|
" function() " ..
|
||||||
|
" career_vehicleSaveSystem.FinishedLoading(" .. inventoryId .. ")" ..
|
||||||
|
" end) " ..
|
||||||
|
" ');"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
FinishedLoading(inventoryId)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -135,12 +202,12 @@ local function onSaveCurrentSaveSlot(currentSavePath, oldSaveDate, vehiclesThumb
|
|||||||
local vehicles = career_modules_inventory.getVehicles()
|
local vehicles = career_modules_inventory.getVehicles()
|
||||||
|
|
||||||
for id, _ in pairs(vehicles) do
|
for id, _ in pairs(vehicles) do
|
||||||
QueueVehicleToSave(id)
|
EnqueueVehicleToSave(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
for id, _ in pairs(M.queuedVehicleSaves) do
|
for id, _ in pairs(M.queuedVehicleSaves) do
|
||||||
if not SaveVehicle(id) then
|
if not SaveVehicle(id) then
|
||||||
QueuedVehicleSaved(id)
|
DequeueVehicleToSave(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CheckSavedAsync(function()
|
CheckSavedAsync(function()
|
||||||
@ -163,11 +230,16 @@ M.queuedVehicleSaves = {}
|
|||||||
|
|
||||||
M.SaveVehicle = SaveVehicle
|
M.SaveVehicle = SaveVehicle
|
||||||
M.LoadVehicle = LoadVehicle
|
M.LoadVehicle = LoadVehicle
|
||||||
|
M.FinishedLoading = FinishedLoading
|
||||||
|
|
||||||
|
M.TeleportVehicle = TeleportVehicle
|
||||||
|
|
||||||
|
M.SetFade = SetFade
|
||||||
|
|
||||||
M.CheckSavedAsync = CheckSavedAsync
|
M.CheckSavedAsync = CheckSavedAsync
|
||||||
|
|
||||||
M.QueueVehicleToSave = QueueVehicleToSave
|
M.EnqueueVehicleToSave = EnqueueVehicleToSave
|
||||||
M.QueuedVehicleSaved = QueuedVehicleSaved
|
M.DequeueVehicleToSave = DequeueVehicleToSave
|
||||||
|
|
||||||
M.onSaveCurrentSaveSlotAsyncStart = onSaveCurrentSaveSlotAsyncStart
|
M.onSaveCurrentSaveSlotAsyncStart = onSaveCurrentSaveSlotAsyncStart
|
||||||
M.onSaveCurrentSaveSlot = onSaveCurrentSaveSlot
|
M.onSaveCurrentSaveSlot = onSaveCurrentSaveSlot
|
||||||
|
Loading…
Reference in New Issue
Block a user