Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaleform class #698

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

CodexisPhantom
Copy link

This add a scaleform class for a better management and usage of scaleforms.

At first it was a PR from Mycroft-Studios intended for qbx_core, but after discussions with the team we felt that this code would fit better in ox_lib so chatty asked for someone to create a PR.

@CodexisPhantom CodexisPhantom changed the title Feat/scaleform Scaleform class Jan 26, 2025
end

self.handle = scaleform
self.draw = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use more descriptive property names like isDrawing or such.
You could also use private properties or otherwise mark the property as private for LLS.

---@return nil
---@description Create a new scaleform class
function lib.scaleform:constructor(details)
details = type(details) == "table" and details or { name = details }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've mixed ' and " for strings in a number of places. We generally use '.

Comment on lines 98 to 104
if not self.handle then
return error('Scaleform handle is nil')
end

if type(args) ~= 'table' then
return error('Args must be a table')
end
Copy link
Member

@thelindat thelindat Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These error messages (and elsewhere) could be formatted a little better. I've used a typeError function in some other parts of ox_lib.

BeginScaleformMovieMethod(self.handle, name)

if args then
convertArgs(args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args cannot be falsey, so this if statement is redundant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I corrected the code because args can be false. Here is a modified code from qbx_police where I tested the scaleform class.

local function setupIntructionalScaleform()
    if not currentScaleform then
        return
    end

    currentScaleform:callMethod('CLEAR_ALL')
    currentScaleform:callMethod('SET_CLEAR_SPACE', { 200 })
    currentScaleform:callMethod('SET_DATA_SLOT', { 1, GetControlInstructionalButton(1, 177, true), 'Fermer la caméra' })
    currentScaleform:callMethod('DRAW_INSTRUCTIONAL_BUTTONS')
    currentScaleform:callMethod('SET_BACKGROUND_COLOUR', { 0, 0, 0, 80 })
end


---@param expectedType 'boolean' | 'integer' | 'string'
---@return boolean | integer | string
---@description Awaits the return value, and converts it to a usable data type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for @description here and in other places.

self.handle = scaleform
self.draw = false

self.fullScreen = details.fullScreen ~= nil and details.fullScreen or true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be true.

end

---@param name string
---@param args? table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be marked as optional, as your type check ensures it is a table. You should also clarify that it's an array-like table and which types are valid - (number | string | boolean)[]

@CodexisPhantom
Copy link
Author

I did all the changes with this fix, check if this is what you wanted and let me know if there is something else.

local scaleform = lib.requestScaleformMovie(details.name)

self.sfHandle = scaleform
self.private.isDrawing = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've set isDrawing as private, but other references to the variable don't check the private table.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I pushed without checking 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants