-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various luabridge migration fixes/changes
- Started writing some basic tests for scripting namespaces and types - Fixed enum handling (can't just convert to int, need to register them with luabridge) - Handle functions with multiple return values manually, since luabridge doesn't support it directly but we can still manually push the return values - Various minor fixes for issues found while testing scripting functions
- Loading branch information
1 parent
40c6d04
commit 576ce3b
Showing
27 changed files
with
1,013 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Oops, something went wrong.