dev tools: add simple settings tracker

This commit is contained in:
Adam
2017-05-03 18:52:31 -04:00
parent 29280179f7
commit 6f8d000351
3 changed files with 146 additions and 1 deletions

View File

@@ -49,6 +49,8 @@ public class DevToolsPanel extends PluginPanel
private JButton renderWallsBtn = new JButton();
private JButton renderDecorBtn = new JButton();
private JButton renderInventoryBtn = new JButton();
private JButton settingsSnapshotBtn = new JButton();
private JButton settingsClearBtn = new JButton();
private JLabel textLbl = new JLabel();
private JLabel textColorLbl = new JLabel();
@@ -62,6 +64,8 @@ public class DevToolsPanel extends PluginPanel
private DefaultMutableTreeNode widgetListRoot = new DefaultMutableTreeNode();
private final SettingsTracker settingsTracker = new SettingsTracker(client);
public DevToolsPanel(DevTools plugin)
{
this.plugin = plugin;
@@ -79,7 +83,7 @@ public class DevToolsPanel extends PluginPanel
private JPanel createOptionsPanel()
{
JPanel container = new JPanel();
container.setLayout(new GridLayout(4, 2, 3, 3));
container.setLayout(new GridLayout(5, 2, 3, 3));
container.setBorder(PADDING_BORDER);
renderPlayersBtn = new JButton("Players");
@@ -146,6 +150,14 @@ public class DevToolsPanel extends PluginPanel
});
container.add(renderInventoryBtn);
settingsSnapshotBtn = new JButton("Get Settings");
settingsSnapshotBtn.addActionListener(settingsTracker::snapshot);
container.add(settingsSnapshotBtn);
settingsClearBtn = new JButton("Clear Settings");
settingsClearBtn.addActionListener(settingsTracker::clear);
container.add(settingsClearBtn);
return container;
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.devtools;
import java.awt.event.ActionEvent;
import java.util.Arrays;
import net.runelite.api.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SettingsTracker
{
private static final Logger logger = LoggerFactory.getLogger(SettingsTracker.class);
private final Client client;
private int[] clientSettings;
private int[] widgetSettings;
public SettingsTracker(Client client)
{
this.client = client;
}
public void snapshot(ActionEvent e)
{
if (clientSettings == null || widgetSettings == null)
{
clientSettings = copy(client.getSettings());
widgetSettings = copy(client.getWidgetSettings());
logger.info("Snapshotted client and widget settings");
return;
}
int[] newClientSettings = client.getSettings();
int[] newWidgetSettings = client.getWidgetSettings();
for (int i = 0; i < Math.min(clientSettings.length, newClientSettings.length); ++i)
{
int before = clientSettings[i];
int after = newClientSettings[i];
if (before == after)
{
continue;
}
logger.info("Client setting index {} has changed from {} to {}: {} -> {}",
i, before, after, prettyPrintInt(before), prettyPrintInt(after));
}
for (int i = 0; i < Math.min(widgetSettings.length, newWidgetSettings.length); ++i)
{
int before = widgetSettings[i];
int after = newWidgetSettings[i];
if (before == after)
{
continue;
}
logger.info("Widget setting index {} has changed from {} to {}: {} -> {}",
i, before, after, prettyPrintInt(before), prettyPrintInt(after));
}
clientSettings = copy(newClientSettings);
widgetSettings = copy(newWidgetSettings);
}
public void clear(ActionEvent e)
{
clientSettings = widgetSettings = null;
}
private static int[] copy(int[] array)
{
return Arrays.copyOf(array, array.length);
}
private static String prettyPrintInt(int value)
{
String s = Integer.toBinaryString(value);
while (s.length() < 32)
{
s = "0" + s;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 32; i += 8)
{
String substr = s.substring(i, i + 8);
if (i > 0)
{
sb.append(' ');
}
sb.append(substr);
}
return sb.toString();
}
}