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

Create defos.script_api #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

padreputativo
Copy link

It resolves the issue of the warnings that appear in the linter due to not finding the extension globally, but it doesn't fix the display of the complete list of functions. Many thanks to Magna for the help.

It resolves the issue of the warnings that appear in the linter due to not finding the extension globally, but it doesn't fix the display of the complete list of functions.
@britzl
Copy link
Collaborator

britzl commented Aug 18, 2024

Nice! Is the intention to add all of the api functions?

@padreputativo
Copy link
Author

I preferred not to do it because I didn't have the exact list with the specific names of all the functions, and I also didn't know how to obtain it. I tried getting an AI to do it (since it's a repetitive task), but I wasn't successful, so I decided to leave it as is because it served the purpose of preventing errors. I didn't want to delete the identified function so it could serve as an example if someone knew how to complete the list.

@pixelpusherninja
Copy link

For what its worth i did it for my project. Only downfall is to keep updating it yourself though...

i created .lua-types/defos/init.lua


---@class Display
---@field id string
---@field bounds { x: number, y: number, width: number, height: number }
---@field name string
---@field refresh_rate number
---@field rotation number
---@field scale_factor number
---@field workspace { x: number, y: number, width: number, height: number }

defos = {}

---Gets the window size including the title bar
---@return number width The window width in pixels
---@return number height The window height in pixels
function defos.get_window_size() end

---Sets the window size including the title bar
---@param width number The desired window width in pixels
---@param height number The desired window height in pixels
function defos.set_window_size(width, height) end

---Sets the game view size and position in screen coordinates
---This adjusts the window so its containing game view is at the desired size and position
---The window will be larger than the given metrics because it includes the title bar
---@param x number The x position in screen coordinates (pass nil to center horizontally)
---@param y number The y position in screen coordinates (pass nil to center vertically)
---@param width number The desired view width in pixels
---@param height number The desired view height in pixels
function defos.set_view_size(x, y, width, height) end

---Toggles fullscreen mode. On HTML5, this only works from defos.on_click() or defos.on_interaction()
function defos.toggle_fullscreen() end

---Checks if the window is currently in fullscreen mode
---@return boolean is_fullscreen True if the window is in fullscreen mode
function defos.is_fullscreen() end

---Toggles window maximize status
function defos.toggle_maximized() end

---Checks if the window is currently maximized
---@return boolean is_maximized True if the window is maximized
function defos.is_maximized() end

---Minimizes the window (not supported on HTML5)
function defos.minimize() end

---Checks if the window is currently minimized
---@return boolean is_minimized True if the window is minimized
function defos.is_minimized() end

---Restores the window from a minimized or maximized state
function defos.restore() end

---Sets the window title
---@param title string The desired window title
function defos.set_window_title(title) end

---Gets the current window title
---@return string title The current window title
function defos.get_window_title() end

---Changes the game window's icon at runtime
---Windows: accepts .ico files
---macOS: accepts any image file supported by NSImage
---Linux: not supported yet
---@param icon_path string Path to the icon file
function defos.set_window_icon(icon_path) end

---Gets the window position in screen coordinates
---@return number x The window x position
---@return number y The window y position
function defos.get_window_position() end

---Sets the window position in screen coordinates
---@param x number The desired window x position
---@param y number The desired window y position
function defos.set_window_position(x, y) end

---Centers the window on the current display
function defos.center_window() end

---Gets information about all connected displays
---@return Display[] displays Table of display information
function defos.get_displays() end

---Gets the ID of the display containing the game window
---@return string display_id The current display ID
function defos.get_current_display_id() end

---Gets the bounds of a specific display
---@param display_id string The display ID to query
---@return { x: number, y: number, width: number, height: number } bounds The display bounds
function defos.get_display_bounds(display_id) end

---Shows or hides the mouse cursor
---@param visible boolean True to show the cursor, false to hide it
function defos.set_cursor_visible(visible) end

---Checks if the mouse cursor is currently visible
---@return boolean is_visible True if the cursor is visible
function defos.is_cursor_visible() end

---Sets the cursor position in screen coordinates (not supported on HTML5)
---@param x number The desired cursor x position
---@param y number The desired cursor y position
function defos.set_cursor_pos(x, y) end

---Gets the cursor position in screen coordinates
---@return number x The cursor x position
---@return number y The cursor y position
function defos.get_cursor_pos() end

return defos

and then included it into .vscode/settings.json

{
... Some other defold configs
"Lua.workspace.library": [
        ".lua-types",
    ],
... Some other defold configs
}

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.

3 participants