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

added macro versioning #2463

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions ugs-core/src/com/willwinder/universalgcodesender/types/Macro.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serial;
import java.util.Objects;
import java.io.Serializable;
import java.util.UUID;

Expand All @@ -15,6 +17,7 @@ public class Macro implements Serializable {
private String name;
private String description;
private String gcode;
private MacroVersion version;

public Macro() {
}
Expand Down Expand Up @@ -67,16 +70,37 @@ public void setGcode(String gcode) {
this.gcode = gcode;
}

public MacroVersion getVersion() {
return version;
}

public void setVersion(MacroVersion version) {
this.version = Objects.requireNonNullElse(version, MacroVersion.V1);
}

@Override
public String toString() {
return "Macro{" +
"uuid='" + uuid + '\'' +
"name='" + name + '\'' +
", description='" + description + '\'' +
", gcode='" + gcode + '\'' +
", version=" + version +
'}';
}

@Serial
public Object readResolve() {
this.version = Objects.requireNonNullElse(this.version, MacroVersion.V2);
return this;
}

@Serial
public Object writeReplace() {
this.version = Objects.requireNonNullElse(this.version, MacroVersion.V1);
return this;
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.willwinder.universalgcodesender.types;

public enum MacroVersion {
/**
* The first version of the macro system.
* This version allows pseudo-multiline macros separated by a semicolon.
* It also allows for the use of the {prompt|name} macros and machine and work coordinate substitution.
* This version is compatible with the newer macro system, but will not be separated in multiple lines.
*/
V1(1),

// TODO: Add more documentation when the second version is implemented.
/**
* The second version of the macro system.
* This version will be backwards compatible with the first version, but will allow for the use of
* multi-line macros and more TBA.
*/
V2(2);

private final int version;

MacroVersion(int version) {
this.version = version;
}

public int getVersion() {
return version;
}
}