-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filterpreset): Implement loading/saving filter presets
commit 3f6636a Author: Alkorith <[email protected]> Date: Mon Sep 11 11:25:05 2023 -0500 feat(filterpreset): Implement loading/saving filter presets commit 9872554 Author: Alkorith <[email protected]> Date: Mon Sep 11 11:30:53 2023 -0500 chore(filterpresets): Add lunajson dependency
- Loading branch information
Showing
12 changed files
with
1,075 additions
and
2 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
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
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
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
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,7 @@ | ||
local load_preset = require("filterpreset.load_preset") | ||
local save_preset = require("filterpreset.save_preset") | ||
|
||
return { | ||
load_preset = load_preset, | ||
save_preset = save_preset | ||
} |
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,80 @@ | ||
local json = require('lunajson') | ||
|
||
local first_time_call_guard = true | ||
|
||
-- Use default skillset names | ||
local json_filter_categories = DeepCopy(ms.SkillSets) | ||
table.insert(json_filter_categories, "Length") | ||
table.insert(json_filter_categories, "ClearPercent") | ||
|
||
local RateKey = "Rate" | ||
local ExclusiveFilterKey = "ExclusiveFilter" | ||
local HighestSkillsetOnlyKey = "HighestSkillsetOnly" | ||
local HighestDifficultyOnlyKey = "HighestDifficultyOnly" | ||
|
||
local function load_preset(filename, explicit_call, pn) | ||
explicit_call = explicit_call or false | ||
|
||
if not (explicit_call or first_time_call_guard) then return end | ||
if first_time_call_guard then first_time_call_guard = false end | ||
|
||
pn = pn or PLAYER_1 | ||
filename = filename or "default.json" | ||
|
||
local full_path = ( | ||
PROFILEMAN:GetProfileDir(pn_to_profile_slot(pn)) | ||
.. '/filter_presets/' | ||
.. filename | ||
.. '.json' | ||
) | ||
|
||
local file_output = File.Read(full_path) | ||
if not file_output then return end | ||
|
||
|
||
local data = json.decode(file_output) | ||
|
||
for i = 1, #json_filter_categories do | ||
if data[json_filter_categories[i]] then | ||
local setting = data[json_filter_categories[i]] | ||
|
||
if setting.min then | ||
FILTERMAN:SetSSFilter(setting.min, i, 0) | ||
end | ||
|
||
if setting.max then | ||
FILTERMAN:SetSSFilter(setting.max, i, 1) | ||
end | ||
end | ||
end | ||
|
||
if data[RateKey] then | ||
local setting = data[RateKey] | ||
|
||
if setting.min then | ||
FILTERMAN:SetMinFilterRate(setting.min) | ||
end | ||
|
||
if setting.max then | ||
FILTERMAN:SetMaxFilterRate(setting.max) | ||
end | ||
end | ||
|
||
if data[ExclusiveFilterKey] then | ||
FILTERMAN:SetFilterMode(data[ExclusiveFilterKey]) | ||
end | ||
|
||
if data[HighestSkillsetOnlyKey] then | ||
FILTERMAN:SetHighestSkillsetsOnly(data[HighestSkillsetOnlyKey]) | ||
end | ||
|
||
if data[HighestDifficultyOnlyKey] then | ||
FILTERMAN:HighestDifficultyOnlyKey(data[HighestDifficultyOnlyKey]) | ||
end | ||
|
||
if explicit_call then | ||
ms.ok(string.format("Loaded filter preset: %s", full_path)) | ||
end | ||
end | ||
|
||
return load_preset |
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,44 @@ | ||
local json = require('lunajson') | ||
|
||
-- Use default skillset names | ||
local json_filter_categories = DeepCopy(ms.SkillSets) | ||
table.insert(json_filter_categories, "Length") | ||
table.insert(json_filter_categories, "ClearPercent") | ||
|
||
local RateKey = "Rate" | ||
local ExclusiveFilterKey = "ExclusiveFilter" | ||
local HighestSkillsetOnlyKey = "HighestSkillsetOnly" | ||
local HighestDifficultyOnlyKey = "HighestDifficultyOnly" | ||
|
||
local function save_preset(filename, pn) | ||
filename = filename or "default" | ||
pn = pn or PLAYER_1 | ||
|
||
local filter_preset = { | ||
Rate = { | ||
min = math.round(FILTERMAN:GetMinFilterRate(), 1), | ||
max = math.round(FILTERMAN:GetMaxFilterRate(), 1) | ||
}, | ||
ExclusiveFilter = FILTERMAN:GetFilterMode(), | ||
HighestSkillsetOnly = FILTERMAN:GetHighestSkillsetsOnly(), | ||
HighestDifficultyOnly = FILTERMAN:GetHighestDifficultyOnly() | ||
} | ||
|
||
for i = 1, #json_filter_categories do | ||
filter_preset[json_filter_categories[i]] = { | ||
min = FILTERMAN:GetSSFilter(i, 0), | ||
max = FILTERMAN:GetSSFilter(i, 1) | ||
} | ||
end | ||
|
||
local full_path = ( | ||
PROFILEMAN:GetProfileDir(pn_to_profile_slot(pn)) | ||
.. '/filter_presets/' | ||
.. filename | ||
.. '.json' | ||
) | ||
File.Write(full_path, json.encode(filter_preset)) | ||
ms.ok(string.format("Saved file to: %s", full_path)) | ||
end | ||
|
||
return save_preset |
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,8 @@ | ||
local newdecoder = require 'lunajson.decoder' | ||
local newencoder = require 'lunajson.encoder' | ||
-- If you need multiple contexts of decoder and/or encoder, | ||
-- you can require lunajson.decoder and/or lunajson.encoder directly. | ||
return { | ||
decode = newdecoder(), | ||
encode = newencoder(), | ||
} |
Oops, something went wrong.