Manual add/delete cheats works now. How high is the water, momma? 3 ft. high and rising. W00t!

This commit is contained in:
Brendan Robert 2015-08-23 21:54:43 -05:00
parent facd73d345
commit 926485ac38
3 changed files with 35 additions and 32 deletions

View File

@ -6,6 +6,7 @@
package jace.cheat; package jace.cheat;
import java.util.ArrayList; import java.util.ArrayList;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.IntegerProperty; import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
@ -24,6 +25,7 @@ public class MemoryCell implements Comparable<MemoryCell> {
public IntegerProperty readCount = new SimpleIntegerProperty(); public IntegerProperty readCount = new SimpleIntegerProperty();
public IntegerProperty execCount = new SimpleIntegerProperty(); public IntegerProperty execCount = new SimpleIntegerProperty();
public IntegerProperty writeCount = new SimpleIntegerProperty(); public IntegerProperty writeCount = new SimpleIntegerProperty();
public BooleanBinding hasCount = readCount.add(execCount).add(writeCount).greaterThan(0);
public ObservableList<Integer> readInstructions = FXCollections.observableList(new ArrayList<>()); public ObservableList<Integer> readInstructions = FXCollections.observableList(new ArrayList<>());
public ObservableList<Integer> writeInstructions = FXCollections.observableList(new ArrayList<>()); public ObservableList<Integer> writeInstructions = FXCollections.observableList(new ArrayList<>());
private int x; private int x;
@ -72,4 +74,8 @@ public class MemoryCell implements Comparable<MemoryCell> {
return address - o.address; return address - o.address;
} }
public boolean hasCounts() {
return hasCount.get();
}
} }

View File

@ -35,7 +35,6 @@ public class MetaCheat extends Cheats {
NO_CHANGE, ANY_CHANGE, LESS, GREATER, AMOUNT NO_CHANGE, ANY_CHANGE, LESS, GREATER, AMOUNT
} }
public static class SearchResult { public static class SearchResult {
int address; int address;
@ -52,7 +51,6 @@ public class MetaCheat extends Cheats {
} }
} }
MetacheatUI ui; MetacheatUI ui;
public int fadeRate = 1; public int fadeRate = 1;
@ -106,12 +104,7 @@ public class MetaCheat extends Cheats {
return Integer.parseInt(s); return Integer.parseInt(s);
} else { } else {
String upper = s.toUpperCase(); String upper = s.toUpperCase();
boolean positive = true; boolean positive = !upper.startsWith("-");
if (upper.startsWith("-")) {
positive = false;
upper = upper.substring(1);
}
for (int i = 0; i < upper.length(); i++) { for (int i = 0; i < upper.length(); i++) {
char c = upper.charAt(i); char c = upper.charAt(i);
if ((c >= '0' && c <= '9') || (c >= 'A' & c <= 'F')) { if ((c >= '0' && c <= '9') || (c >= 'A' & c <= 'F')) {
@ -134,12 +127,18 @@ public class MetaCheat extends Cheats {
cheat.activeProperty().set(true); cheat.activeProperty().set(true);
cheatList.add(cheat); cheatList.add(cheat);
computer.getMemory().addListener(cheat); computer.getMemory().addListener(cheat);
cheat.addressProperty().addListener((prop, oldVal, newVal)->{ cheat.addressProperty().addListener((prop, oldVal, newVal) -> {
computer.getMemory().removeListener(cheat); computer.getMemory().removeListener(cheat);
cheat.doConfig(); cheat.doConfig();
computer.getMemory().addListener(cheat); computer.getMemory().addListener(cheat);
}); });
} }
public void removeCheat(DynamicCheat cheat) {
cheat.active.set(false);
computer.getMemory().removeListener(cheat);
cheatList.remove(cheat);
}
@Override @Override
protected void unregisterListeners() { protected void unregisterListeners() {
@ -299,24 +298,22 @@ public class MetaCheat extends Cheats {
public void tick() { public void tick() {
if (fadeCounter-- <= 0) { if (fadeCounter-- <= 0) {
fadeCounter = FADE_TIMER_VALUE; fadeCounter = FADE_TIMER_VALUE;
memoryCells.values().stream().forEach((jace.cheat.MemoryCell cell) -> { memoryCells.values().stream()
boolean change = false; .filter((cell) -> cell.hasCounts())
if (cell.execCount.get() > 0) { .forEach((cell) -> {
cell.execCount.set(Math.max(0, cell.execCount.get() - fadeRate)); if (cell.execCount.get() > 0) {
change = true; cell.execCount.set(Math.max(0, cell.execCount.get() - fadeRate));
} }
if (cell.readCount.get() > 0) { if (cell.readCount.get() > 0) {
cell.readCount.set(Math.max(0, cell.readCount.get() - fadeRate)); cell.readCount.set(Math.max(0, cell.readCount.get() - fadeRate));
change = true; }
} if (cell.writeCount.get() > 0) {
if (cell.writeCount.get() > 0) { cell.writeCount.set(Math.max(0, cell.writeCount.get() - fadeRate));
cell.writeCount.set(Math.max(0, cell.writeCount.get() - fadeRate)); }
change = true; if (MemoryCell.listener != null) {
} MemoryCell.listener.changed(null, cell, cell);
if (change && MemoryCell.listener != null) { }
MemoryCell.listener.changed(null, cell, cell); });
}
});
} }
} }

View File

@ -127,7 +127,7 @@ public class MetacheatUI {
@FXML @FXML
void addCheat(ActionEvent event) { void addCheat(ActionEvent event) {
cheatEngine.addCheat(new DynamicCheat(0, "?"));
} }
@FXML @FXML
@ -137,7 +137,7 @@ public class MetacheatUI {
@FXML @FXML
void deleteCheat(ActionEvent event) { void deleteCheat(ActionEvent event) {
cheatsTableView.getSelectionModel().getSelectedItems().forEach(cheatEngine::removeCheat);
} }
@FXML @FXML
@ -281,12 +281,12 @@ public class MetacheatUI {
TableColumn<DynamicCheat, Integer> addrColumn = (TableColumn<DynamicCheat, Integer>) cheatsTableView.getColumns().get(2); TableColumn<DynamicCheat, Integer> addrColumn = (TableColumn<DynamicCheat, Integer>) cheatsTableView.getColumns().get(2);
addrColumn.setCellValueFactory(new PropertyValueFactory<>("address")); addrColumn.setCellValueFactory(new PropertyValueFactory<>("address"));
addrColumn.setCellFactory((TableColumn<DynamicCheat, Integer> param) -> { addrColumn.setCellFactory((TableColumn<DynamicCheat, Integer> param) -> {
return new TextFieldTableCell<>(new IntegerStringConverter(){ return new TextFieldTableCell<>(new IntegerStringConverter() {
@Override @Override
public String toString(Integer value) { public String toString(Integer value) {
return "$"+Integer.toHexString(value); return "$" + Integer.toHexString(value);
} }
@Override @Override
public Integer fromString(String value) { public Integer fromString(String value) {
return cheatEngine.parseInt(value); return cheatEngine.parseInt(value);