Skip to content

Commit

Permalink
Stop raving same data to config if no changes. detected
Browse files Browse the repository at this point in the history
  • Loading branch information
nani committed Oct 9, 2022
1 parent 638574a commit ccb7182
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions gui/lobby/LobbyPage/PlayerList~autociv.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
PlayerList = new Proxy(PlayerList, {
construct: function (target, args)
{
const autociv_playersBox_preferences = new ConfigJSON("playersBox", true, false);
const playersBox = Engine.GetGUIObjectByName("playersBox");
construct: function (target, args) {
const autociv_playersBox_preferences = new ConfigJSON(
"playersBox",
true,
false
);
const playersBox = Engine.GetGUIObjectByName("playersBox");

for (let id of autociv_playersBox_preferences.getIds())
playersBox[id] = autociv_playersBox_preferences.getValue(id);
for (let id of autociv_playersBox_preferences.getIds())
playersBox[id] = autociv_playersBox_preferences.getValue(id);

let instance = new target(...args);
instance.autociv_playersBox_preferences = autociv_playersBox_preferences
return instance;
}
let instance = new target(...args);
instance.autociv_playersBox_preferences = autociv_playersBox_preferences;
warn("1");
return instance;
},
});

autociv_patchApplyN(PlayerList.prototype, "onPlayerListSelection", function (target, that, args)
{
if (that.autociv_playersBox_preferences)
{
for (let id of ["selected_column", "selected_column_order"])
that.autociv_playersBox_preferences.setValue(id, that.playersBox[id])
that.autociv_playersBox_preferences.save()
autociv_patchApplyN(
PlayerList.prototype,
"onPlayerListSelection",
function (target, that, args) {
if (that.autociv_playersBox_preferences) {
warn("2");
const needsSave = ["selected_column", "selected_column_order"]
.map((id) => {
let old = that.autociv_playersBox_preferences.getValue(id);
if (old == that.playersBox[id]) return false;
that.autociv_playersBox_preferences.setValue(id, that.playersBox[id]);
return true;
})
.some((v) => v);

if (needsSave) {
that.autociv_playersBox_preferences.save();
}
}

return target.apply(that, args);
})
}
);

0 comments on commit ccb7182

Please sign in to comment.