Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/revision tracking #41

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed build
JH456 committed Dec 31, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6533e684041e40b08e464cd0ecf11a8b083b510a
3 changes: 2 additions & 1 deletion src/com/ra4king/circuitsim/gui/CircuitSim.java
Original file line number Diff line number Diff line change
@@ -1170,8 +1170,9 @@ void pasteFromClipboard() {
if (parsed.saveHistory != null && !parsed.saveHistory.isEmpty()
&& !this.saveHistory.contains(parsed.saveHistory.get(parsed.saveHistory.size() - 1))
&& !this.copiedBlocks.contains(parsed.saveHistory.get(parsed.saveHistory.size() - 1))) {
this.copiedBlocks.add(parsed.saveHistory.get(parsed.saveHistory.size() - 1));
this.copiedBlocks.add(parsed.saveHistory.get(0));
this.copiedBlocks.add(parsed.saveHistory.get((int)(Math.random() * parsed.saveHistory.size())));
this.copiedBlocks.add(parsed.saveHistory.get(parsed.saveHistory.size() - 1));
}

CircuitManager manager = getCurrentCircuit();
11 changes: 6 additions & 5 deletions src/com/ra4king/circuitsim/gui/file/FileFormat.java
Original file line number Diff line number Diff line change
@@ -115,15 +115,15 @@ private String stringify() {
}
}

public static String getLastHash(List<String> saveHistory) {
private static String getLastHash(List<String> saveHistory) {
if (saveHistory.size() == 0) {
return "";
} else {
SaveHistoryBlock tailBlock = new SaveHistoryBlock(saveHistory.get(saveHistory.size() - 1));
return tailBlock.currentHash;
}
}

public static class CircuitFile {
private final String version = CircuitSim.VERSION;

@@ -146,14 +146,15 @@ public CircuitFile(int globalBitSize, int clockSpeed, List<String> libraryPaths,


private String hash() {
String fileData = FileFormat.stringify(libraryPaths)
+ FileFormat.stringify(circuits);
String fileData = GSON.toJson(libraryPaths)
+ GSON.toJson(circuits);
return FileFormat.sha256ify(fileData);
}

public void addSaveHistoryBlock() {
String currentFileDataHash = hash();
String previousHash = FileFormat.getLastHash(saveHistory);
SaveHistoryBlock newBlock = new SaveHistoryBlock(previousHash, hash(), copiedBlocks);
SaveHistoryBlock newBlock = new SaveHistoryBlock(previousHash, currentFileDataHash, copiedBlocks);
saveHistory.add(newBlock.stringify());
this.copiedBlocks = null;
}