Skip to content

Commit

Permalink
refactor: Config.NativeAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Aug 14, 2023
1 parent 5debf40 commit b74f3dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
mkdir -p ./temp/ox_doorlock
mkdir -p ./temp/ox_doorlock/web/
mkdir -p ./temp/ox_doorlock/convert/
cp ./{LICENSE,README.md,fxmanifest.lua,config.lua} ./temp/ox_doorlock
cp ./{LICENSE,README.md,fxmanifest.lua,config.lua,types.lua} ./temp/ox_doorlock
cp -r ./{client,server,sql,locales} ./temp/ox_doorlock
cp -r ./web/build ./temp/ox_doorlock/web/
cd ./temp && zip -r ../ox_doorlock.zip ./ox_doorlock
Expand Down
4 changes: 1 addition & 3 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ RegisterNetEvent('ox_doorlock:setState', function(id, state, source, data)
end

if door.state == state and door.distance and door.distance < 20 then
local useNativeAudio = GetConvarInt('doorlock:nativeaudio', 1) == 1

if useNativeAudio then
if Config.NativeAudio then
RequestScriptAudioBank('dlc_oxdoorlock/oxdoorlock', false)
local sound = state == 0 and door.unlockSound or door.lockSound or 'door_bolt'
local soundId = GetSoundId()
Expand Down
27 changes: 12 additions & 15 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
---@type DoorlockConfig
---@diagnostic disable-next-line: missing-fields
Config = {}

---Send a notification when the door is successfully locked/unlocked.
---@type boolean
---Trigger a notification on the client when the door state is successfully updated.
Config.Notify = false

---Draw a persistent notification while in-range of a door, with a prompt to lock/unlock.
---@type boolean
---Create a persistent notification while in-range of a door, prompting to lock/unlock.
Config.DrawTextUI = false

---Set the properties used by [DrawSprite](https://docs.fivem.net/natives/?_0xE7FFAE5EBF23D890).
---@type { [0]: table, [1]: table }
Config.DrawSprite = {
-- Unlocked
[0] = { 'mpsafecracking', 'lock_open', 0, 0, 0.018, 0.018, 0, 255, 255, 255, 100 },
Expand All @@ -18,24 +17,22 @@ Config.DrawSprite = {
[1] = { 'mpsafecracking', 'lock_closed', 0, 0, 0.018, 0.018, 0, 255, 255, 255, 100 },
}

---Allow the following ACL principal to use 'command.doorlock'.
---@type string
---Allow the specified ace principal to use 'command.doorlock'.
Config.CommandPrincipal = 'group.admin'

---Allow players with 'command.doorlock' permission to open any doors.
---@type boolean
---Allow players with the 'command.doorlock' principal to use any door.
Config.PlayerAceAuthorised = false

---Default skill check difficulty when no fields are defined in the Lockpick tab.
---@type SkillCheckDifficulity | SkillCheckDifficulity[]
---The default skill check difficulty when lockpicking a door.
Config.LockDifficulty = { 'easy', 'easy', 'medium' }

---Allow lockpicks to be used to lock an already unlocked door.
---@type boolean?
---Allow lockpicks to be used to lock an unlocked door.
Config.CanPickUnlockedDoors = false

---Items that function as lockpicks. Needed for ox_target, and authorisation checks.
---@type string[]
---An array of items that function as lockpicks.
Config.LockpickItems = {
'lockpick'
}

---Play sounds using game audio (sound natives) instead of through NUI.
Config.NativeAudio = true
7 changes: 2 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ exports('editDoor', function(id, data)
end
end)

local useNativeAudio = GetConvarInt('doorlock:nativeaudio', 1) == 1

local soundDirectory = useNativeAudio and 'audio/dlc_oxdoorlock/oxdoorlock' or 'web/build/sounds'
local fileFormat = useNativeAudio and '%.wav' or '%.ogg'

local soundDirectory = Config.NativeAudio and 'audio/dlc_oxdoorlock/oxdoorlock' or 'web/build/sounds'
local fileFormat = Config.NativeAudio and '%.wav' or '%.ogg'
local sounds = require 'server.utils'.getFilesInDirectory(soundDirectory, fileFormat)

local function createDoor(id, door, name)
Expand Down
23 changes: 23 additions & 0 deletions types.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---@class DrawSpriteProps
---@field [1] string textureDict
---@field [2] string textureName
---@field [3] number screenX
---@field [4] number screenY
---@field [5] number width
---@field [6] number height
---@field [7] number heading
---@field [8] integer red
---@field [9] integer green
---@field [10] integer blue
---@field [11] integer alpha

---@class DoorlockConfig
---@field Notify boolean
---@field DrawTextUI boolean
---@field CommandPrincipal string
---@field PlayerAceAuthorised boolean
---@field LockDifficulty SkillCheckDifficulity | SkillCheckDifficulity[]
---@field CanPickUnlockedDoors boolean
---@field LockpickItems string[]
---@field NativeAudio boolean
---@field DrawSprite { [0]: DrawSpriteProps, [1]: DrawSpriteProps }

0 comments on commit b74f3dd

Please sign in to comment.