mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-13 09:17:28 +07:00
Bugfixes
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
package mindustry.world.blocks.logic;
|
package mindustry.world.blocks.logic;
|
||||||
|
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.math.geom.*;
|
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
@ -38,31 +37,21 @@ public class LogicBlock extends Block{
|
|||||||
config(Integer.class, (LogicBuild entity, Integer pos) -> {
|
config(Integer.class, (LogicBuild entity, Integer pos) -> {
|
||||||
//if there is no valid link in the first place, nobody cares
|
//if there is no valid link in the first place, nobody cares
|
||||||
if(!entity.validLink(world.build(pos))) return;
|
if(!entity.validLink(world.build(pos))) return;
|
||||||
int x = Point2.x(pos), y = Point2.y(pos);
|
|
||||||
Building lbuild = world.build(pos);
|
Building lbuild = world.build(pos);
|
||||||
|
int x = lbuild.tileX(), y = lbuild.tileY();
|
||||||
|
|
||||||
LogicLink link = entity.links.find(l -> l.x == x && l.y == y);
|
LogicLink link = entity.links.find(l -> l.x == x && l.y == y);
|
||||||
|
String bname = getLinkName(lbuild.block);
|
||||||
|
|
||||||
if(link != null){
|
if(link != null){
|
||||||
link.active = !link.active;
|
link.active = !link.active;
|
||||||
|
//find a name when the base name differs (new block type)
|
||||||
|
if(!link.name.startsWith(bname)){
|
||||||
|
link.name = "";
|
||||||
|
link.name = entity.findLinkName(lbuild.block);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
String bname = getLinkName(lbuild.block);
|
LogicLink out = new LogicLink(x, y, entity.findLinkName(lbuild.block), true);
|
||||||
int maxnum = 0;
|
|
||||||
|
|
||||||
for(LogicLink others : entity.links){
|
|
||||||
if(others.name.startsWith(bname)){
|
|
||||||
|
|
||||||
String num = others.name.substring(bname.length());
|
|
||||||
try{
|
|
||||||
int parsed = Integer.parseInt(num);
|
|
||||||
maxnum = Math.max(parsed, maxnum);
|
|
||||||
}catch(NumberFormatException ignored){
|
|
||||||
//ignore failed parsing, it isn't relevant
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LogicLink out = new LogicLink(x, y, bname + (maxnum + 1), true);
|
|
||||||
entity.links.add(out);
|
entity.links.add(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +110,7 @@ public class LogicBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class LogicLink{
|
public static class LogicLink{
|
||||||
public boolean active = true, valid = true;
|
public boolean active = true, valid;
|
||||||
public int x, y;
|
public int x, y;
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
@ -187,6 +176,37 @@ public class LogicBlock extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String findLinkName(Block block){
|
||||||
|
String bname = getLinkName(block);
|
||||||
|
Bits taken = new Bits(links.size);
|
||||||
|
int max = 1;
|
||||||
|
|
||||||
|
for(LogicLink others : links){
|
||||||
|
if(others.name.startsWith(bname)){
|
||||||
|
|
||||||
|
String num = others.name.substring(bname.length());
|
||||||
|
try{
|
||||||
|
int val = Integer.parseInt(num);
|
||||||
|
taken.set(val);
|
||||||
|
max = Math.max(val, max);
|
||||||
|
}catch(NumberFormatException ignored){
|
||||||
|
//ignore failed parsing, it isn't relevant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int outnum = 0;
|
||||||
|
|
||||||
|
for(int i = 1; i < max + 2; i++){
|
||||||
|
if(!taken.get(i)){
|
||||||
|
outnum = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bname + outnum;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateCode(){
|
public void updateCode(){
|
||||||
updateCode(code);
|
updateCode(code);
|
||||||
}
|
}
|
||||||
@ -250,6 +270,12 @@ public class LogicBlock extends Block{
|
|||||||
if(valid != l.valid ){
|
if(valid != l.valid ){
|
||||||
changed = true;
|
changed = true;
|
||||||
l.valid = valid;
|
l.valid = valid;
|
||||||
|
if(valid){
|
||||||
|
//this prevents conflicts
|
||||||
|
l.name = "";
|
||||||
|
//finds a new matching name after toggling
|
||||||
|
l.name = findLinkName(world.build(l.x, l.y).block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +363,8 @@ public class LogicBlock extends Block{
|
|||||||
@Override
|
@Override
|
||||||
public boolean onConfigureTileTapped(Building other){
|
public boolean onConfigureTileTapped(Building other){
|
||||||
if(this == other){
|
if(this == other){
|
||||||
return true;
|
deselect();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(validLink(other)){
|
if(validLink(other)){
|
||||||
|
@ -8,6 +8,7 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
public class LogicDisplay extends Block{
|
public class LogicDisplay extends Block{
|
||||||
@ -44,7 +45,7 @@ public class LogicDisplay extends Block{
|
|||||||
if(buffer == null){
|
if(buffer == null){
|
||||||
buffer = new FrameBuffer(displaySize, displaySize);
|
buffer = new FrameBuffer(displaySize, displaySize);
|
||||||
//clear the buffer - some OSs leave garbage in it
|
//clear the buffer - some OSs leave garbage in it
|
||||||
buffer.begin(Color.clear);
|
buffer.begin(Pal.darkerMetal);
|
||||||
buffer.end();
|
buffer.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user