124 lines
4.4 KiB
Plaintext
124 lines
4.4 KiB
Plaintext
|
------------------------------------------------------------------------------------------------------------------------
|
||
|
---
|
||
|
--- Original Author(s) : NLTP_ASHES
|
||
|
--- Edited : N/A
|
||
|
--- Date : 05/11/2023
|
||
|
--- License : Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
|
||
|
---
|
||
|
--- Script used to restore the last playing song/radio when loading a save.
|
||
|
---
|
||
|
------------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
-- Variables
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
local ppdar_radio_state
|
||
|
local ppdar_radio_selected
|
||
|
local ppdar_radio_vol
|
||
|
|
||
|
local ppdar_plyr_state
|
||
|
local ppdar_plyr_loop
|
||
|
local ppdar_plyr_shuffle
|
||
|
local ppdar_plyr_vol
|
||
|
local ppdar_plyr_now
|
||
|
local ppdar_plyr_playlist
|
||
|
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
-- Core Functions
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
--- Function used to restore the last playing song/radio after a save load.
|
||
|
--- @return nil
|
||
|
function restore_pda_player()
|
||
|
if ppdar_radio_state then
|
||
|
restore_radio_player()
|
||
|
return
|
||
|
end
|
||
|
if ppdar_plyr_state then
|
||
|
restore_music_player()
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function restore_radio_player()
|
||
|
-- Restore settings
|
||
|
ui_pda_radio_tab.radio_vol = ppdar_radio_vol
|
||
|
|
||
|
-- Start radio
|
||
|
ui_pda_radio_tab.action_radio_start()
|
||
|
printf("[PPDAR] PDA radio started according to saved data")
|
||
|
|
||
|
-- Switch channel
|
||
|
CreateTimeEvent("ppdar_restore_channel",ppdar_radio_selected,0,function()
|
||
|
if ui_pda_radio_tab.radio_selected ~= ppdar_radio_selected then
|
||
|
ui_pda_radio_tab.action_radio_ch(ppdar_radio_selected)
|
||
|
else
|
||
|
return true
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
function restore_music_player()
|
||
|
-- Restore settings
|
||
|
ui_pda_radio_tab.plyr_loop = ppdar_plyr_loop
|
||
|
ui_pda_radio_tab.plyr_shuffle = ppdar_plyr_shuffle
|
||
|
ui_pda_radio_tab.plyr_vol = ppdar_plyr_vol
|
||
|
ui_pda_radio_tab.playlist = ppdar_plyr_playlist
|
||
|
ui_pda_radio_tab.plyr_now[ui_pda_radio_tab.playlist] = ppdar_plyr_now
|
||
|
|
||
|
-- Start player
|
||
|
ui_pda_radio_tab.action_plyr_start()
|
||
|
printf("[PPDAR] PDA music player started according to saved data")
|
||
|
end
|
||
|
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
-- Data persistence
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
--- Function used to store information in the save file.
|
||
|
--- @param m_data table
|
||
|
--- @return nil
|
||
|
function save_state(m_data)
|
||
|
-- PDA radio settings
|
||
|
m_data.ppdar_radio_state = ui_pda_radio_tab.radio_state
|
||
|
m_data.ppdar_radio_selected = ui_pda_radio_tab.radio_selected
|
||
|
m_data.ppdar_radio_vol = ui_pda_radio_tab.radio_vol
|
||
|
|
||
|
m_data.ppdar_plyr_state = ui_pda_radio_tab.plyr_state
|
||
|
m_data.ppdar_plyr_loop = ui_pda_radio_tab.plyr_loop
|
||
|
m_data.ppdar_plyr_shuffle = ui_pda_radio_tab.plyr_shuffle
|
||
|
m_data.ppdar_plyr_vol = ui_pda_radio_tab.plyr_vol
|
||
|
m_data.ppdar_plyr_now = ui_pda_radio_tab.plyr_now[ui_pda_radio_tab.playlist]
|
||
|
m_data.ppdar_plyr_playlist = ui_pda_radio_tab.playlist
|
||
|
end
|
||
|
|
||
|
--- Function used to load information stored in the save file.
|
||
|
--- @param m_data table
|
||
|
--- @return nil
|
||
|
function load_state(m_data)
|
||
|
-- PDA radio settings
|
||
|
ppdar_radio_state = m_data.ppdar_radio_state or false
|
||
|
ppdar_radio_selected = m_data.ppdar_radio_selected or 0
|
||
|
ppdar_radio_vol = m_data.ppdar_radio_vol or 0.5
|
||
|
|
||
|
-- PDA music player settings
|
||
|
ppdar_plyr_state = m_data.ppdar_plyr_state or false
|
||
|
ppdar_plyr_loop = m_data.ppdar_plyr_loop or 1
|
||
|
ppdar_plyr_shuffle = m_data.ppdar_plyr_shuffle or false
|
||
|
ppdar_plyr_vol = m_data.ppdar_plyr_vol or 0.5
|
||
|
ppdar_plyr_now = m_data.ppdar_plyr_now or 1
|
||
|
ppdar_plyr_playlist = m_data.ppdar_plyr_playlist or 1
|
||
|
end
|
||
|
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
-- Callbacks registration
|
||
|
-- ---------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
--- Function used to register callbacks.
|
||
|
--- @return nil
|
||
|
function on_game_start()
|
||
|
RegisterScriptCallback("save_state", save_state)
|
||
|
RegisterScriptCallback("load_state", load_state)
|
||
|
RegisterScriptCallback("actor_on_first_update", restore_pda_player)
|
||
|
end
|