Shortcut scaling validation

This commit is contained in:
Robin K 2021-09-24 20:19:29 +02:00
parent 4e184df596
commit ef02c63032
5 changed files with 19 additions and 23 deletions

View File

@ -85,6 +85,7 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
// Add nodes to ROM tree.
for (TableTreeNode tableTreeNode : tableNodes) {
Table table = tableTreeNode.getTable();
String[] categories = table.getCategory().split("//");
if (settings.isDisplayHighTables() || settings.getUserLevel() >= table.getUserLevel()) {

View File

@ -55,6 +55,8 @@ public class Scale implements Serializable {
}
public boolean validate() {
if(expression.equals("x") && byteExpression.equals("x")) return true;
double startValue = 5;
double toReal = JEPUtil.evaluate(getExpression(), startValue); // convert real world value of "5"
double endValue = JEPUtil.evaluate(getByteExpression(), toReal);

View File

@ -118,6 +118,8 @@ public abstract class Table implements Serializable {
}
public void populateTable(byte[] input, int romRamOffset) throws ArrayIndexOutOfBoundsException, IndexOutOfBoundsException {
validateScaling();
// temporarily remove lock;
boolean tempLock = locked;
locked = false;
@ -199,8 +201,6 @@ public abstract class Table implements Serializable {
if(SettingsManager.getSettings().getDefaultScale().equalsIgnoreCase(scale.getName())) {
this.curScale = scale;
}
validateScaling();
}
public int getStorageAddress() {
@ -581,12 +581,6 @@ public abstract class Table implements Serializable {
public void validateScaling() {
if (getType() != TableType.SWITCH) {
// make sure a scale is present
if (scales.isEmpty()) {
scales.add(new Scale());
}
for(Scale scale : scales) {
if (!scale.validate()) {
TableView.showBadScalePopup(this, scale);

View File

@ -135,6 +135,8 @@ public class Table3D extends Table {
@Override
public void populateTable(byte[] input, int romRamOffset) throws NullPointerException, ArrayIndexOutOfBoundsException, IndexOutOfBoundsException {
validateScaling();
// fill first empty cell
if (!beforeRam) {
this.ramOffset = romRamOffset;

View File

@ -232,9 +232,6 @@ public final class RomAttributeParser {
}
public static int parseFileSize(String input) throws NumberFormatException {
try {
return Integer.parseInt(input);
} catch (NumberFormatException ex) {
if (input.substring(input.length() - 2).equalsIgnoreCase("kb")) {
return Integer.parseInt(input.substring(0, input.length() - 2)) * 1024;
}
@ -244,8 +241,8 @@ public final class RomAttributeParser {
else if (input.substring(input.length() - 1).equalsIgnoreCase("b")) {
return Integer.parseInt(input.substring(0, input.length() - 1));
}
throw new NumberFormatException();
}
return Integer.parseInt(input);
}
public static byte[] floatToByte(float input, Settings.Endian endian, Settings.Endian memModelEndian) {