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

Added HLTB Subtitle and utility script #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Subtitles/HowLongToBeat.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scriptTitle=How Long to beat
scriptAuthor=Minze
scriptDescription=A subtitle that shows you the How Long to beat. This needs a previous run of the "How Long to Beat" Utility Script
7 changes: 7 additions & 0 deletions Subtitles/HowLongToBeat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GameListSubtitles["HowLongToBeat"] = function(Content)
local str = string.format("HLTB Not found, Title ID: %d", Content.TitleId)
for _, v in pairs(Sql.ExecuteFetchRows("SELECT TitleId,CompMain,CompPlus,Comp100 FROM HowLongToBeat where TitleId = "..Content.TitleId)) do
str = string.format("How Long To Beat: Main: %dh, Main + DLC: %dh, 100%%: %dh", v.CompMain, v.CompPlus, v.Comp100)
end
return str
end
115 changes: 115 additions & 0 deletions UtilityScripts/HowLongToBeat/Main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
scriptTitle = "How Long To Beat"
scriptAuthor = "MinZe"
scriptVersion = 1.0
scriptDescription = "Insert How long to beat data. (Can be removed after running it)"
scriptIcon = "icon.png"
scriptPermissions = { "sql", "filesystem" }

local function replace(str, t)
return (str:gsub('$(%w+)', t))
end
local function split(str, sep)
local result = {}
for match in (str .. sep):gmatch("(.-)" .. sep) do
table.insert(result, match)
end
return result
end

-- Function to split the fileStr by lines
local function splitLines(str)
local result = {}
for line in str:gmatch("([^\r\n]+)") do
table.insert(result, line)
end
return result
end
local function insert_hltb(titleId, compMain, compPlus, comp100)
local str =
[=[
INSERT INTO HowLongToBeat (TitleId,CompMain,CompPlus,Comp100) VALUES (
'$titleId',
'$compMain',
'$compPlus',
'$comp100'
);
]=]

Sql.Execute(replace(str, { titleId = titleId, compMain = compMain, compPlus = compPlus, comp100 = comp100 }))
end
local function processCSVFromString(fileStr, platform)
local results = {}
local lines = splitLines(fileStr)

-- Total lines to process (excluding header)
local totalLines = #lines - 1
Script.SetStatus("Starting CSV processing...") -- Set initial status

local firstLine = true -- To skip the header

for i, line in ipairs(lines) do
if Script.IsCanceled() then return end
if firstLine then
firstLine = false -- Skip the first line (header)
else
-- Split the line by comma
local values = split(line, ",")
-- Add them to the results table
insert_hltb(values[1], values[2], values[3], values[4])

-- Update progress and status
Script.SetProgress(i - 1, totalLines)
Script.SetStatus(string.format("Processing line %d of %d... for %s", i - 1, totalLines, platform))
end
end

-- Final status update after completion
Script.SetProgress(totalLines, totalLines)
Script.SetStatus("CSV processing complete!")

return results
end

function main()
local xboxPath = Script.GetBasePath() .. "output_Xbox 360.csv";
local xboxOgPath = Script.GetBasePath() .. "output_Xbox.csv";
if not FileSystem.FileExists(xboxPath) then
Script.ShowMessageBox("ERROR",
"Xbox file doesn't exist",
"OK");
return;
end
if not FileSystem.FileExists(xboxOgPath) then
Script.ShowMessageBox("ERROR",
"Xbox OG file doesn't exist",
"OK");
return;
end
Script.SetStatus("Creating table...");
Script.SetProgress(50);
local sql = [=[
create table if not EXISTS HowLongToBeat(
TitleId integer primary key,
CompMain integer not null,
CompPlus integer not null,
Comp100 integer not null
)
]=]
Sql.Execute("DROP TABLE IF EXISTS HowLongToBeat")
if Sql.Execute(sql) ~= true then
Script.ShowMessageBox("ERROR",
"Cannot execute the script",
"OK");
end
local i = 0
if Script.IsCanceled() then return end
processCSVFromString(FileSystem.ReadFile(xboxPath), "360")
if Script.IsCanceled() then return end
processCSVFromString(FileSystem.ReadFile(xboxOgPath), "OG")
local ret = Script.ShowMessageBox("Reload Required",
"In order for the changes to take effect you need to reload Aurora\nDo you want to reload Aurora now?", "No",
"Yes");
if ret.Button == 2 then
Aurora.Restart();
end
end
Binary file added UtilityScripts/HowLongToBeat/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading