Skip to content

Commit

Permalink
Merge branch 'luabridge' into 3.3.0
Browse files Browse the repository at this point in the history
While I'm not 100% done with this, it's at least at a stage where I'm confident it can safely replace sol as the binding library, will just need to go through and add tests for the rest of the types and fix things as they come
  • Loading branch information
sirjuddington committed Jan 24, 2025
2 parents 2195f5e + 5e454f6 commit 49fb5cd
Show file tree
Hide file tree
Showing 79 changed files with 15,640 additions and 28,574 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ indent_size = 2

[*.{h,cpp,c}]
guidelines = 80, 120

[*.lua]
indent_style = space
indent_size = 3
2 changes: 1 addition & 1 deletion dist/res/scripts/archive/Archive Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function YesNo(boolean)
end
end

function Execute(archive)
return function(archive)
-- Archive format info
AddOutputLine("Format: " .. archive.format.name)
AddOutputLine("Supports directories: " .. YesNo(archive.format.supportsDirs))
Expand Down
4 changes: 2 additions & 2 deletions dist/res/scripts/archive/_template.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- An archive script will run the Execute function (below) on the current archive
-- An archive script will run the returned function on the current archive
-- Archive scripts can be selected and run from the "Archive->Scripts" menu

function Execute(archive)
return function(archive)
-- Write your archive script here
end
4 changes: 2 additions & 2 deletions dist/res/scripts/entry/_template.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- An entry script will run the Execute function (below) on the current/selected entries
-- An entry script will run the returned function on the current/selected entries
-- Entry scripts can be selected and run from the "Entry->Scripts" menu,
-- or "Run Script" in the entry list context menu

function Execute(entries)
return function(entries)
for i,entry in ipairs(entries) do
-- Write your entry script here
end
Expand Down
54 changes: 54 additions & 0 deletions dist/res/scripts/general/Tests/Namespaces/App.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Tests for everything in the App namespace

App.LogMessage("App.LogMessage test")
App.LogWarning("App.LogWarning test")
App.LogError("App.LogError test")

local current_archive = App.CurrentArchive()
if current_archive == nil then
App.LogMessage('No current archive')
else
App.LogMessage('Current archive: ' .. current_archive.filename)
end

local current_entry = App.CurrentEntry()
if current_entry == nil then
App.LogMessage('No current entry')
else
App.LogMessage('Current entry: ' .. current_entry.name)
end

local entry_selection = App.CurrentEntrySelection()
App.LogMessage(#entry_selection .. ' selected entries:')
for _,entry in ipairs(entry_selection) do
App.LogMessage(' ' .. entry.name)
end

local current_palette = App.CurrentPalette()
if current_palette == nil then
App.LogMessage('No current palette (no base resource selected?)')
else
App.LogMessage('Current palette has ' .. current_palette.colourCount .. ' colours')
end

if current_archive ~= nil then
App.LogMessage('Showing the current archive...')
App.ShowArchive(current_archive)
end

if current_entry ~= nil then
App.LogMessage('Opening the current entry in a tab...')
App.ShowEntry(current_entry)
elseif #entry_selection > 0 then
App.LogMessage('Opening the first selected entry in a tab...')
App.ShowEntry(entry_selection[1])
else
App.LogMessage('No available entry to open')
end

local map_editor = App.MapEditor()
if map_editor == nil then
App.LogMessage('Map Editor not currently open')
else
App.LogMessage('Map Editor open, map: ' .. map_editor.map.name)
end
149 changes: 149 additions & 0 deletions dist/res/scripts/general/Tests/Namespaces/Archives.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
-- Tests for everything in the Archives namespace

local string title = 'Archives Namespace Test'

local function TestFail()
UI.MessageBox(title, 'Archives namespace test failed - see console log for details', UI.MB_ICON_ERROR)
end

local function ListOpenArchives()
App.LogMessage('All open archives:')
for i,archive in ipairs(Archives.All()) do
App.LogMessage(' ' .. i .. ': ' .. archive.filename)
end
end

local function ListEntries(archive)
for i = 1, math.min(5, #archive.entries) do
App.LogMessage(' ' .. i .. ': ' .. archive.entries[i].name)
end
end

local function ListBookmarks()
App.LogMessage('All bookmarks:')
for i,bookmark in ipairs(Archives.Bookmarks()) do
App.LogMessage(' ' .. i .. ': ' .. bookmark.name)
end
end

-- This test requires all archives to be closed initially, prompt
if UI.PromptYesNo(title, 'To run this test all archives must be closed, continue running script and close all open archives?') then
Archives.CloseAll()
else
return
end

-- Create archive (invalid format)
local archive, error = Archives.Create('dat')
if archive == nil then
App.LogMessage('Create with invalid archive format: Failed as expected, error: ' .. error)
else
App.LogError('Create with invalid archive format: Did not fail, something is wrong')
TestFail()
return
end

-- Create archive (valid format)
archive, error = Archives.Create('wad')
if archive == nil then
App.LogError('Create with valid archive format: Failed')
TestFail()
return
else
App.LogMessage('Create with valid archive format: Passed, archive created successfully')
end

-- BaseResource
archive = Archives.BaseResource()
if archive == nil then
App.LogMessage('No base resource archive loaded')
else
App.LogMessage('Base resource archive: ' .. archive.filename)
end

-- BaseResourcePaths
local base_resource_paths = Archives.BaseResourcePaths()
for i,path in ipairs(base_resource_paths) do
App.LogMessage('Base resource path ' .. i .. ': ' .. path)
end

-- OpenBaseResource (TODO - need a way to restore previous selection)

-- OpenFile with invalid path
archive, error = Archives.OpenFile('notafile_.naf')
if archive == nil then
App.LogMessage('Open with invalid path: Failed as expected, error: ' .. error)
else
App.LogError('Open with invalid path: Did not fail, something is wrong (or the file actually exists and is an archive somehow?)')
TestFail()
return
end

-- OpenFile with valid path (hopefully)
if #base_resource_paths > 0 then
archive, error = Archives.OpenFile(base_resource_paths[1])
if archive == nil then
App.LogMessage('Open with valid path: Failed to open, error: ' .. error)
else
App.LogMessage('Open with valid path: Passed, opened first base resource successfully')
end
else
App.LogMessage('Open with valid path: No base resource archives configured, skipping test')
end

ListOpenArchives()

-- Add first 2 entries in the last open archive to bookmarks
if archive == nil then
App.LogMessage('No open archives to add bookmarks to')
else
App.LogMessage('Adding first 2 entries of last open archive to bookmarks...')
for i = 1, math.min(2, #archive.entries) do
Archives.AddBookmark(archive.entries[i])
end
end

ListBookmarks()

-- Remove first bookmark
if #Archives.Bookmarks() > 0 then
App.LogMessage('Removing first bookmark...')
Archives.RemoveBookmark(Archives.Bookmarks()[1])
end

ListBookmarks()

-- Close the first open archive (should be the one created earlier)
App.LogMessage('Closing first open archive...')
Archives.Close(0)

ListOpenArchives()

-- Close all open archives
App.LogMessage('Closing all open archives...')
Archives.CloseAll()

ListOpenArchives()

-- ProgramResource
archive = Archives.ProgramResource()
if archive == nil then
App.LogMessage('No program resource archive loaded (how?)')
TestFail()
return
else
App.LogMessage('Program resource archive top 5 entries:')
ListEntries(archive)
end

-- List recent files
App.LogMessage('Recent files:')
for i,path in ipairs(Archives.RecentFiles()) do
App.LogMessage(' ' .. i .. ': ' .. path)
end

-- EntryType
local entry_type = Archives.EntryType('wad')
App.LogMessage('Entry type wad, name: ' .. entry_type.name .. ', category: ' .. entry_type.category)

UI.MessageBox(title, 'Archives namespace test completed successfully')
12 changes: 12 additions & 0 deletions dist/res/scripts/general/Tests/Namespaces/Game.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Tests for everything in the Game namespace

local title = 'Game Namespace Test'

local ttype = Game.ThingType(1)
if ttype == nil then
App.LogMessage('No ThingType 1 found (most likely no game configuration is currently loaded)')
else
App.LogMessage('ThingType 1 name: ' .. ttype.name)
end

UI.MessageBox(title, 'Game namespace test completed successfully')
61 changes: 61 additions & 0 deletions dist/res/scripts/general/Tests/Namespaces/Graphics.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- Tests for everything in the Graphics namespace

local title = 'Graphics Namespace Test'
local failed_count = 0

-- AllImageFormats
local all_formats = Graphics.AllImageFormats()
App.LogMessage('All image formats:')
for i,format in ipairs(all_formats) do
App.LogMessage(' ' .. i .. ': ' .. format.name .. ' (' .. format.id .. ')')
end

-- Invalid format
local format = Graphics.ImageFormat('abcdefghij')
if format == nil or format.id == 'unknown' then
App.LogMessage('Invalid image format test: Passed, got invalid format as expected')
else
App.LogMessage('Invalid image format test: Failed, got valid format ' .. format.id)
failed_count = failed_count + 1
end

-- Valid format
format = Graphics.ImageFormat('png')
if format == nil or format.id ~= 'png' then
App.LogMessage('Valid image format test: Failed, got invalid or wrong format')
failed_count = failed_count + 1
else
App.LogMessage('Valid image format test: Passed, got format ' .. format.id)
end

-- DetectImageFormat (using logo.png in slade.pk3)
local archive = Archives.ProgramResource()
local entry = archive:EntryAtPath('logo.png')
format = Graphics.DetectImageFormat(entry.data)
if format ~= nil and format.id == 'png' then
App.LogMessage('Detect image format test: Passed, detected format ' .. format.id)
else
App.LogMessage('Detect image format test: Failed, detected format ' .. (format and format.id or 'nil'))
failed_count = failed_count + 1
end

-- GetImageInfo
local info = Graphics.GetImageInfo(entry.data)
if info == nil then
App.LogMessage('Get image info test: Failed, got nil')
failed_count = failed_count + 1
else
App.LogMessage('Get image info test: Passed, got info:')
for key,value in pairs(info) do
App.LogMessage(' ' .. key .. ': ' .. tostring(value))
end
end


if failed_count == 0 then
UI.MessageBox(title, 'Graphics namespace test completed successfully')
else
UI.MessageBox(title,
'Graphics namespace test completed with ' .. failed_count .. ' failed test(s), see console log for details',
UI.MB_ICON_ERROR)
end
63 changes: 63 additions & 0 deletions dist/res/scripts/general/Tests/Namespaces/UI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
-- Tests for everything in the UI namespace

local title = 'UI Namespace Test'
local extensions = 'All Files (*.*)|*.*'
local PauseMsgBox = function(msg) UI.MessageBox(title, msg or 'Pause for splash window test') end


-- MessageBoxes
UI.MessageBox(title, 'Messagebox with default icon (info)')
UI.MessageBox(title, 'Messagebox with info icon', UI.MB_ICON_INFO)
UI.MessageBox(title, 'Messagebox with question icon', UI.MB_ICON_QUESTION)
UI.MessageBox(title, 'Messagebox with warning icon', UI.MB_ICON_WARNING)
UI.MessageBox(title, 'Messagebox with error icon', UI.MB_ICON_ERROR)
UI.MessageBoxExt(title, 'This is an extended message box', 'This is the detail box for long text')


-- Prompts
local response = UI.PromptString(title, 'Enter a string', '(default value)')
App.LogMessage('PromptString response: ' .. response)

response = UI.PromptNumber(title, 'Enter a number between 1 and 100', 1, 1, 100)
App.LogMessage('PromptNumber response: ' .. response)

response = UI.PromptYesNo(title, 'Yes or No?')
App.LogMessage('PromptYesNo response: ' .. tostring(response))

response = UI.PromptOpenFile('Select a File', extensions, '')
App.LogMessage('PromptOpenFile response: ' .. response)

response = UI.PromptOpenFiles('Select Files', extensions)
App.LogMessage('PromptOpenFiles response:')
for _,filename in ipairs(response) do
App.LogMessage(' ' .. filename)
end

response = UI.PromptSaveFile('Save File (no default name)', extensions)
App.LogMessage('PromptSaveFile response (no default name): ' .. response)

response = UI.PromptSaveFile('Save File (withdefault name)', extensions, 'doom2.wad')
App.LogMessage('PromptSaveFile response (with default name): ' .. response)

response, extension = UI.PromptSaveFiles('Save Files', extensions .. '|Text Files (*.txt)|*.txt')
App.LogMessage('PromptSaveFiles response: ' .. response .. ' (extension: ' .. extension .. ')')


-- Splash Window
UI.ShowSplash("Splash with no progress")
PauseMsgBox()
UI.ShowSplash("Splash with progress", true)
PauseMsgBox('Current progress: ' .. UI.SplashProgress())
UI.SetSplashMessage('New splash message')
PauseMsgBox()
UI.SetSplashProgress(0.5)
UI.SetSplashProgressMessage('Current progress: ' .. UI.SplashProgress())
PauseMsgBox()
UI.SetSplashProgress(-1)
UI.SetSplashProgressMessage('Indeterminate progress')
PauseMsgBox()
UI.HideSplash()
App.LogMessage('Splash window hidden')


UI.MessageBox(title, 'UI namespace test completed successfully')
Loading

0 comments on commit 49fb5cd

Please sign in to comment.