Skip to content

Commit

Permalink
Physical radios
Browse files Browse the repository at this point in the history
  • Loading branch information
justarandomguyintheinternet committed Dec 10, 2023
1 parent de8177c commit 35140e7
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions modules/physical/observersP.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,50 @@

local observersP = {}

local function handleActionNotifier(controller, evt)
local notifier = ActionNotifier.new()
notifier:SetNone()
if controller:IsDisabled() or controller:IsUnpowered() or not controller:IsON() then
return EntityNotificationType.DoNotNotifyEntity
end
controller:Notify(notifier, evt)
return EntityNotificationType.SendThisEventToEntity
end

function observersP.init(radioMod)
ObserveAfter("RadioControllerPS", "OnNextStation", function (this, evt)
-- print(this.activeStation)
-- 13 total vanilla stations, 4 is the first one
Override("RadioControllerPS", "OnNextStation", function (this, evt, wrapped)
if RadioStationDataProvider.GetRadioStationUIIndex(this.activeStation) > 12 or this.activeStation > 13 then
this.previousStation = this.activeStation
this.activeStation = math.max(RadioStationDataProvider.GetRadioStationUIIndex(this.activeStation), this.activeStation) + 1
if this.activeStation > 13 + #radioMod.radioManager.radios then
this.activeStation = 12
return wrapped(evt)
end

return handleActionNotifier(this, evt)
else
return wrapped(evt)
end
end)

Override("RadioControllerPS", "OnPreviousStation", function (this, evt, wrapped)
if this.activeStation > 13 then
this.previousStation = this.activeStation
this.activeStation = this.activeStation - 1
if this.activeStation < 14 then
this.activeStation = 4
return wrapped(evt)
end

return handleActionNotifier(this, evt)
elseif this.activeStation == 4 then
this.previousStation = this.activeStation
this.activeStation = 13 + #radioMod.radioManager.radios
return handleActionNotifier(this, evt)
else
return wrapped(evt)
end
end)

Override("RadioControllerPS", "GameAttached", function (this)
Expand All @@ -13,11 +54,17 @@ function observersP.init(radioMod)
this:TryInitializeInteractiveState()
end)

Override("RadioControllerPS", "SetDefaultRadioStation", function (this)
if not this.radioSetup.randomizeStartingStation then
this.activeStation = this.radioSetup.startingStation
return
end
this.activeStation = math.random(0, 13 + #radioMod.radioManager.radios)
end)

Observe("Radio", "PlayGivenStation", function (this)
local active = this:GetDevicePS():GetActiveStationIndex()

-- print(active)

if active > 13 then
local radio = radioMod.radioManager.radios[active - 13]

Expand Down

0 comments on commit 35140e7

Please sign in to comment.