Skip to content

Commit

Permalink
link pin
Browse files Browse the repository at this point in the history
  • Loading branch information
sk7725 committed Feb 1, 2021
1 parent d5be041 commit 5b8377d
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ block.betamindy-cloner.name = Block Cloner
block.betamindy-cloner.description = Clones the [accent]block it is facing[] to [#a9d8ff]the tile behind it[]. If the [accent]facing block[] is a payload block, the payload will be read, and the size limit will not be applied. Can only clone blocks that you should be able to place by yourself. Consumes items and power.
block.betamindy-cloner.details = A perfect way to make piston flying machine factories.

# Logic
block.betamindy-linkpin.name = Link Pin
block.betamindy-linkpin.description = Can be linked to a processor to display all of its links, even disabled ones. [scarlet]Invalid links[] will have a red name, [lightgray]inactive links[] will have a black square. When pushed by a piston, the linked processor's links will also be shifted.

# Stats
stat.dphealth = {0}*payload health*distance(blocks)

Expand Down
4 changes: 4 additions & 0 deletions assets/bundles/bundle_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ block.betamindy-cloner.name = \uBE14\uB85D \uBCF5\uC0AC\uAE30
block.betamindy-cloner.description = [accent]\uBC14\uB77C\uBCF4\uB294 \uBE14\uB85D[]\uC744 [#a9d8ff]\uC774 \uBE14\uB85D \uB4A4[]\uB85C \uBCF5\uC0AC\uD569\uB2C8\uB2E4. [accent]\uBC14\uB77C\uBCF4\uB294 \uBE14\uB85D[]\uC774 \uD654\uBB3C \uC218\uC1A1 \uBE14\uB85D\uC77C \uACBD\uC6B0, \uD654\uBB3C\uC774 \uBCF5\uC81C\uB418\uBA70 \uC774 \uACBD\uC6B0 \uD06C\uAE30 \uC81C\uD55C\uC5D0 \uC601\uD5A5\uBC1B\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uD50C\uB808\uC774\uC5B4\uAC00 \uC9C1\uC811 \uADF8 \uC704\uCE58\uC5D0 \uB193\uC744 \uC218 \uC788\uB294 \uBE14\uB85D\uB9CC \uBCF5\uC0AC\uAC00 \uAC00\uB2A5\uD569\uB2C8\uB2E4. \uC790\uC6D0\uACFC \uC804\uB825\uC744 \uC18C\uBAA8\uD569\uB2C8\uB2E4.
block.betamindy-cloner.details = \uD53C\uC2A4\uD1A4 \uD0C8\uAC83 \uACF5\uC7A5\uC744 \uB9CC\uB4E4\uAE30\uC5D0 \uC548\uC131\uB9DE\uCDA4\uC774\uB2E4.

# Logic
block.betamindy-linkpin.name = \uC5F0\uACB0 \uD540
block.betamindy-linkpin.description = \uC5F0\uACB0\uB41C \uD504\uB85C\uC138\uC11C\uC758 \uBAA8\uB4E0 \uC5F0\uACB0\uC744 \uD45C\uC2DC\uD569\uB2C8\uB2E4. [scarlet]\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uC5F0\uACB0[]\uC740 \uBD89\uC740 \uC774\uB984, [lightgray]\uBE44\uD65C\uC131\uD654\uB41C \uC5F0\uACB0[]\uC740 \uAC80\uC740 \uC0AC\uAC01\uD615\uC73C\uB85C \uD45C\uC2DC\uB429\uB2C8\uAC00. \uD53C\uC2A4\uD1A4\uC73C\uB85C \uBC00\uBA74, \uC5F0\uACB0\uB41C \uD504\uB85C\uC138\uC11C\uC758 \uBAA8\uB4E0 \uC5F0\uACB0\uB4E4\uB3C4 \uAC19\uC774 \uBC00\uB9BD\uB2C8\uB2E4.

# Stats
stat.dphealth = {0}x\uD654\uBB3C \uCCB4\uB825x\uBE44\uAC70\uB9AC(\uBE14\uB85D)

Expand Down
Binary file added assets/sprites/blocks/logic/linkpin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/effects/linkpin-laser-end.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/effects/linkpin-laser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion src/betamindy/content/MindyBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import betamindy.world.blocks.defense.turrets.*;
import betamindy.world.blocks.distribution.*;
import betamindy.world.blocks.environment.*;
import betamindy.world.blocks.logic.*;
import betamindy.world.blocks.power.*;
import betamindy.world.blocks.production.*;
import betamindy.world.blocks.units.BoostPad;
Expand Down Expand Up @@ -39,7 +40,9 @@ public class MindyBlocks implements ContentList {
//drills
drillMini, drillMega,
//units
boostPad;
boostPad,
//logic
linkPin;

@Override
public void load() {
Expand Down Expand Up @@ -403,5 +406,9 @@ public TextureRegion[] icons(){
size = 2;
requirements(Category.units, with(Items.lead, 24, Items.silicon, 10, Items.phaseFabric, 30));
}};

linkPin = new LinkPinner("linkpin"){{
requirements(Category.logic, with( Items.graphite, 30,Items.silicon, 15, Items.metaglass, 30));
}};
}
}
3 changes: 3 additions & 0 deletions src/betamindy/util/XeloUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import arc.struct.*;
import arc.util.*;
import betamindy.world.blocks.distribution.*;
import betamindy.world.blocks.logic.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.entities.Units;
Expand Down Expand Up @@ -158,6 +159,8 @@ public boolean _pushSingle(Building build, int direction){
_pushUnits(build, direction);

Vars.world.tile(bx+d4(direction).x, by+d4(direction).y).setBlock(build.block, build.team, build.rotation, () -> build);

if(build instanceof PushReact) ((PushReact)build).pushed(direction);
return true;
}

Expand Down
270 changes: 270 additions & 0 deletions src/betamindy/world/blocks/logic/LinkPinner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
package betamindy.world.blocks.logic;

import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.logic.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.logic.LogicBlock.*;
import mindustry.world.meta.*;

import static arc.Core.atlas;
import static mindustry.Vars.tilesize;
import static mindustry.Vars.world;

public class LinkPinner extends Block {
public float range = 8 * 10;
public TextureRegion laser, laserEnd;
public Color color = Pal.sapBullet;

public LinkPinner(String name){
super(name);
update = true;
solid = true;
expanded = true;
rotate = false;
configurable = true;
saveConfig = false;

config(Integer.class, (LinkPinnerBuild entity, Integer i) -> {
Building other = world.build(i);
if(other == null) return;
if(entity.link != null && entity.link.id == other.id){
//unlink
entity.link = null;
}
else if(entity.validLink(other)){
//link
entity.linkTo((LogicBuild) other);
}
});

config(Point2.class, (LinkPinnerBuild entity, Point2 i) -> {
if(entity.link == null){
entity.cachePos = Point2.pack(i.x + entity.tileX(), i.y + entity.tileY());
entity.cacheLink = entity.cachePos != entity.pos();
}
});
}

@Override
public void load() {
super.load();
laser = atlas.find(name + "-laser", "betamindy-linkpin-laser");
laserEnd = atlas.find(name + "-laser-end", "betamindy-linkpin-laser-end");
}

@Override
public void setStats(){
super.setStats();

stats.add(Stat.linkRange, range / 8, StatUnit.blocks);
}

@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
Drawf.circles(x*tilesize + offset, y*tilesize + offset, range);
}

protected void drawLaser(Team team, float x1, float y1, float x2, float y2, int size1, int size2){
float angle1 = Angles.angle(x1, y1, x2, y2),
vx = Mathf.cosDeg(angle1), vy = Mathf.sinDeg(angle1),
len1 = size1 * tilesize / 2f - 1.5f, len2 = size2 * tilesize / 2f - 1.5f;

Drawf.laser(team, laser, laserEnd, x1 + vx*len1, y1 + vy*len1, x2 - vx*len2, y2 - vy*len2, 0.25f);
}

public class LinkPinnerBuild extends Building implements PushReact{
public @Nullable LogicBuild link;
public float heat = 0f;
public boolean changed = false;

protected boolean cacheLink = false;
protected int cachePos = 0;

@Override
public void updateTile(){
if(link != null && changed){
link.updateCode();
changed = false;
}

super.updateTile();
if(heat > 0.01f) heat -= delta();

if(link == null && cacheLink && !Vars.net.client()){
//there is a remembered link, try to connect to it
Building b = world.build(cachePos);
if(b != null && !(b.block instanceof ConstructBlock)){
if(b instanceof LogicBuild){
//attempt reconnection
if(validLink(b)){
linkTo((LogicBuild) b);
}
}
else{
cacheLink = false;
}
}
}

if(link != null && !validLink()){
//sever the line but remember the destination
cacheLink = true;
cachePos = link.pos();
link = null;
}
}

public void linkTo(LogicBuild other){
link = other;
cacheLink = false;
}

public void pushed(int dir){
if(link != null && enabled && link.links.any()){
link.links.forEach(l -> {
l.x += Geometry.d4x(dir);
l.y += Geometry.d4y(dir);
});
heat = 30f;
changed = true;
}
}

@Override
public void draw() {
super.draw();
if(enabled && link != null && link.isValid()){
Draw.z(Layer.blockOver);
Draw.color(color);
Draw.blend(Blending.additive);
//Lines.square(x, y, 4f);

float o = (Time.time * 0.1f) % 7f - 3.5f;
Lines.stroke(1f - Math.abs(o / 3.5f));
Lines.line(x - 3.5f, y + o , x + 3.5f, y + o );
Lines.line(x + o , y - 3.5f, x + o , y + 3.5f);

Draw.color();
Draw.blend();
}
if(link != null && link.isValid()){
Draw.z(Layer.power);
drawLaser(team, x, y, link.x, link.y, size, link.block.size);

if(heat > 0.01f){
Draw.color(color, Color.white, heat / 30f);
Draw.alpha(heat / 30f);
Lines.stroke(0.8f);
link.links.each(l -> {
if(l.active) Lines.square(l.x * tilesize, l.y * tilesize, 6f, 45f);
});
}
Draw.reset();
}
}

public boolean validLink(Building other){
return other != null && other.isValid() && other.team == team && other.within(this, range + other.block.size*tilesize/2f) && (other instanceof LogicBuild);
}

public boolean validLink(){
return link != null && link.isValid() && link.team == team && link.within(this, range + link.block.size*tilesize/2f);
}

@Override
public boolean onConfigureTileTapped(Building other){
if(this == other){
deselect();
return false;
}

if(validLink(other)){
configure(other.pos());
return false;
}

return super.onConfigureTileTapped(other);
}

@Override
public void drawConfigure(){
super.drawConfigure();

Drawf.circles(x, y, range);
if(link == null) return;

Drawf.square(link.x, link.y, link.block.size * tilesize / 2f + 1f, Pal.accent);
LogicLink cursor = null;
Tile hoverTile = world.tileWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);

for(LogicLink l : link.links){
if(cursor == null && hoverTile != null && l.x == hoverTile.x && l.y == hoverTile.y) cursor = l;
else drawLink(l);
}

//draw top text on separate layer
for(LogicLink l : link.links){
if(cursor == null) drawLinkText(l);
}

if(cursor != null){
drawLink(cursor);
drawLinkText(cursor);
}
}

public void drawLink(LogicLink l){
Building build = world.build(l.x, l.y);
if(build != null) Drawf.square(build.x, build.y, build.block.size * tilesize / 2f + 1f, l.active ? Pal.place : Pal.darkerGray);
else Drawf.square(l.x * tilesize, l.y * tilesize, tilesize / 2f + 1f, l.active ? Pal.place : Pal.darkerGray);
}
public void drawLinkText(LogicLink l){
Building build = world.build(l.x, l.y);
if(build != null) build.block.drawPlaceText(l.name, build.tileX(), build.tileY(), link.validLink(build));
else drawPlaceText(l.name, l.x, l.y, false);
}

@Override
public Point2 config(){
if(link == null) return Point2.unpack(pos());
return Point2.unpack(link.pos()).sub(tile.x, tile.y);
}

@Override
public void write(Writes write){
super.write(write);
write.bool(link != null);
if(link != null){
write.i(link.pos());
}
}

@Override
public void read(Reads read, byte revision){
super.read(read, revision);
if(read.bool()){
cachePos = read.i();
cacheLink = true;
}
}

@Override
public Object senseObject(LAccess sensor){
switch(sensor){
case config: return link;
default: return super.senseObject(sensor);
}
}
}
}
6 changes: 6 additions & 0 deletions src/betamindy/world/blocks/logic/PushReact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package betamindy.world.blocks.logic;

/** Reacts when pushed (or pulled) by pistons. */
public interface PushReact {
void pushed(int dir);
}

0 comments on commit 5b8377d

Please sign in to comment.