mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-14 17:57:56 +07:00
make logic stuff public, cleanup
This commit is contained in:
@ -39,9 +39,7 @@ public enum LAccess{
|
|||||||
enabled("to"), //"to" is standard for single parameter access
|
enabled("to"), //"to" is standard for single parameter access
|
||||||
shoot("x", "y", "shoot"),
|
shoot("x", "y", "shoot"),
|
||||||
shootp(true, "unit", "shoot"),
|
shootp(true, "unit", "shoot"),
|
||||||
configure(true, 30, "to")
|
configure(true, 30, "to");
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
public final String[] params;
|
public final String[] params;
|
||||||
public final boolean isObj;
|
public final boolean isObj;
|
||||||
|
@ -17,9 +17,9 @@ public class LAssembler{
|
|||||||
|
|
||||||
private int lastVar;
|
private int lastVar;
|
||||||
/** Maps names to variable IDs. */
|
/** Maps names to variable IDs. */
|
||||||
ObjectMap<String, BVar> vars = new ObjectMap<>();
|
public ObjectMap<String, BVar> vars = new ObjectMap<>();
|
||||||
/** All instructions to be executed. */
|
/** All instructions to be executed. */
|
||||||
LInstruction[] instructions;
|
public LInstruction[] instructions;
|
||||||
|
|
||||||
public LAssembler(){
|
public LAssembler(){
|
||||||
//instruction counter
|
//instruction counter
|
||||||
@ -105,7 +105,7 @@ public class LAssembler{
|
|||||||
if(index++ > max) break;
|
if(index++ > max) break;
|
||||||
|
|
||||||
line = line.replace("\t", "").trim();
|
line = line.replace("\t", "").trim();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String[] arr;
|
String[] arr;
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@ public class LCanvas extends Table{
|
|||||||
//ew static variables
|
//ew static variables
|
||||||
static LCanvas canvas;
|
static LCanvas canvas;
|
||||||
|
|
||||||
DragLayout statements;
|
public DragLayout statements;
|
||||||
StatementElem dragging;
|
public StatementElem dragging;
|
||||||
ScrollPane pane;
|
public ScrollPane pane;
|
||||||
Group jumps;
|
public Group jumps;
|
||||||
float targetWidth;
|
float targetWidth;
|
||||||
|
|
||||||
public LCanvas(){
|
public LCanvas(){
|
||||||
@ -69,18 +69,18 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(LStatement statement){
|
public void add(LStatement statement){
|
||||||
statements.addChild(new StatementElem(statement));
|
statements.addChild(new StatementElem(statement));
|
||||||
}
|
}
|
||||||
|
|
||||||
String save(){
|
public String save(){
|
||||||
Seq<LStatement> st = statements.getChildren().<StatementElem>as().map(s -> s.st);
|
Seq<LStatement> st = statements.getChildren().<StatementElem>as().map(s -> s.st);
|
||||||
st.each(LStatement::saveUI);
|
st.each(LStatement::saveUI);
|
||||||
|
|
||||||
return LAssembler.write(st);
|
return LAssembler.write(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(String asm){
|
public void load(String asm){
|
||||||
jumps.clear();
|
jumps.clear();
|
||||||
|
|
||||||
Seq<LStatement> statements = LAssembler.read(asm);
|
Seq<LStatement> statements = LAssembler.read(asm);
|
||||||
@ -239,7 +239,7 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class StatementElem extends Table{
|
public class StatementElem extends Table{
|
||||||
LStatement st;
|
public LStatement st;
|
||||||
|
|
||||||
public StatementElem(LStatement st){
|
public StatementElem(LStatement st){
|
||||||
this.st = st;
|
this.st = st;
|
||||||
@ -319,7 +319,7 @@ public class LCanvas extends Table{
|
|||||||
marginBottom(7);
|
marginBottom(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy(){
|
public void copy(){
|
||||||
LStatement copy = st.copy();
|
LStatement copy = st.copy();
|
||||||
if(copy != null){
|
if(copy != null){
|
||||||
StatementElem s = new StatementElem(copy);
|
StatementElem s = new StatementElem(copy);
|
||||||
@ -345,15 +345,15 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class JumpButton extends ImageButton{
|
public static class JumpButton extends ImageButton{
|
||||||
Color hoverColor = Pal.place;
|
public Color hoverColor = Pal.place;
|
||||||
Color defaultColor = Color.white;
|
public Color defaultColor = Color.white;
|
||||||
Prov<StatementElem> to;
|
public Prov<StatementElem> to;
|
||||||
boolean selecting;
|
public boolean selecting;
|
||||||
float mx, my;
|
public float mx, my;
|
||||||
ClickListener listener;
|
public ClickListener listener;
|
||||||
StatementElem hovered;
|
public StatementElem hovered;
|
||||||
|
|
||||||
JumpCurve curve;
|
public JumpCurve curve;
|
||||||
|
|
||||||
public JumpButton(Prov<StatementElem> getter, Cons<StatementElem> setter){
|
public JumpButton(Prov<StatementElem> getter, Cons<StatementElem> setter){
|
||||||
super(Tex.logicNode, Styles.colori);
|
super(Tex.logicNode, Styles.colori);
|
||||||
@ -421,7 +421,7 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementElem hovered(){
|
public StatementElem hovered(){
|
||||||
Element e = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
|
Element e = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
|
||||||
if(e != null){
|
if(e != null){
|
||||||
while(e != null && !(e instanceof StatementElem)){
|
while(e != null && !(e instanceof StatementElem)){
|
||||||
@ -434,7 +434,7 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class JumpCurve extends Element{
|
public static class JumpCurve extends Element{
|
||||||
JumpButton button;
|
public JumpButton button;
|
||||||
|
|
||||||
public JumpCurve(JumpButton button){
|
public JumpCurve(JumpButton button){
|
||||||
this.button = button;
|
this.button = button;
|
||||||
@ -483,7 +483,7 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawCurve(float x, float y, float x2, float y2){
|
public void drawCurve(float x, float y, float x2, float y2){
|
||||||
Lines.stroke(4f, button.color);
|
Lines.stroke(4f, button.color);
|
||||||
Draw.alpha(parentAlpha);
|
Draw.alpha(parentAlpha);
|
||||||
|
|
||||||
@ -494,8 +494,7 @@ public class LCanvas extends Table{
|
|||||||
x + dist, y,
|
x + dist, y,
|
||||||
x2 + dist, y2,
|
x2 + dist, y2,
|
||||||
x2, y2,
|
x2, y2,
|
||||||
Math.max(20, (int)(Mathf.dst(x, y, x2, y2) / 6))
|
Math.max(20, (int)(Mathf.dst(x, y, x2, y2) / 6)));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import mindustry.ui.dialogs.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class LogicDialog extends BaseDialog{
|
public class LogicDialog extends BaseDialog{
|
||||||
LCanvas canvas;
|
public LCanvas canvas;
|
||||||
Cons<String> consumer = s -> {};
|
Cons<String> consumer = s -> {};
|
||||||
|
|
||||||
public LogicDialog(){
|
public LogicDialog(){
|
||||||
@ -25,7 +25,7 @@ public class LogicDialog extends BaseDialog{
|
|||||||
addCloseListener();
|
addCloseListener();
|
||||||
|
|
||||||
buttons.defaults().size(160f, 64f);
|
buttons.defaults().size(160f, 64f);
|
||||||
buttons.button("@back", Icon.left, this::hide);
|
buttons.button("@back", Icon.left, this::hide).name("back");
|
||||||
|
|
||||||
buttons.button("@edit", Icon.edit, () -> {
|
buttons.button("@edit", Icon.edit, () -> {
|
||||||
BaseDialog dialog = new BaseDialog("@editor.export");
|
BaseDialog dialog = new BaseDialog("@editor.export");
|
||||||
@ -53,7 +53,7 @@ public class LogicDialog extends BaseDialog{
|
|||||||
|
|
||||||
dialog.addCloseButton();
|
dialog.addCloseButton();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
});
|
}).name("edit");
|
||||||
|
|
||||||
buttons.button("@add", Icon.add, () -> {
|
buttons.button("@add", Icon.add, () -> {
|
||||||
BaseDialog dialog = new BaseDialog("@add");
|
BaseDialog dialog = new BaseDialog("@add");
|
||||||
@ -79,11 +79,11 @@ public class LogicDialog extends BaseDialog{
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}).disabled(t -> canvas.statements.getChildren().size >= LExecutor.maxInstructions);
|
}).disabled(t -> canvas.statements.getChildren().size >= LExecutor.maxInstructions);
|
||||||
|
|
||||||
add(canvas).grow();
|
add(canvas).grow().name("canvas");
|
||||||
|
|
||||||
row();
|
row();
|
||||||
|
|
||||||
add(buttons).growX();
|
add(buttons).growX().name("canvas");
|
||||||
|
|
||||||
hidden(() -> consumer.get(canvas.save()));
|
hidden(() -> consumer.get(canvas.save()));
|
||||||
|
|
||||||
|
@ -38,9 +38,7 @@ public enum LogicOp{
|
|||||||
floor("floor", Math::floor),
|
floor("floor", Math::floor),
|
||||||
ceil("ceil", Math::ceil),
|
ceil("ceil", Math::ceil),
|
||||||
sqrt("sqrt", Math::sqrt),
|
sqrt("sqrt", Math::sqrt),
|
||||||
rand("rand", d -> Mathf.rand.nextDouble() * d),
|
rand("rand", d -> Mathf.rand.nextDouble() * d);
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
public static final LogicOp[] all = values();
|
public static final LogicOp[] all = values();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user