Skip to content

Commit

Permalink
Introduce ArenaManagerOptions to remove a couple of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Jan 23, 2024
1 parent c78f071 commit 784ad9f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
import com.github.tofpu.speedbridge2.common.game.listener.GameListener;
import com.github.tofpu.speedbridge2.common.gameextra.land.Land;
import com.github.tofpu.speedbridge2.common.gameextra.land.LandController;
import com.github.tofpu.speedbridge2.common.gameextra.land.arena.ArenaManagerOptions;
import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager;
import com.github.tofpu.speedbridge2.common.island.Island;
import com.github.tofpu.speedbridge2.common.lobby.LobbyService;
import com.github.tofpu.speedbridge2.common.schematic.SchematicHandler;
import com.github.tofpu.speedbridge2.event.dispatcher.EventDispatcherService;
import com.github.tofpu.speedbridge2.object.Vector;
import com.github.tofpu.speedbridge2.object.player.OnlinePlayer;
import com.github.tofpu.speedbridge2.service.manager.ServiceManager;

import java.util.UUID;

public class BridgeSystem {
private static final ArenaManagerOptions DEFAULT_OPTIONS = new ArenaManagerOptions(new Vector(0, 100, 0), 10);
private final EventDispatcherService eventDispatcher;
private final IslandGameHandler gameHandler;
private final GameLandReserver landReserver;
Expand All @@ -25,7 +29,7 @@ public BridgeSystem(EventDispatcherService eventDispatcher, SchematicHandler sch
this.eventDispatcher = eventDispatcher;
this.gameHandler = new IslandGameHandler(eventDispatcher);

LandController landController = new LandController(new IslandGameArenaManager(arenaAdapter));
LandController landController = new LandController(new BasicArenaManager(arenaAdapter, DEFAULT_OPTIONS));
this.landReserver = new GameLandReserver(arenaAdapter.gameWorld(), schematicHandler, landController);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.tofpu.speedbridge2.common.gameextra.land.arena;

import com.github.tofpu.speedbridge2.object.Vector;

public class ArenaManagerOptions {
private final Vector initialPosition;
private final int gapBetweenIsland;

public ArenaManagerOptions(Vector initialPosition, int gapBetweenIsland) {
this.initialPosition = initialPosition;
this.gapBetweenIsland = gapBetweenIsland;
}

public ArenaManagerOptions(Vector initialPosition) {
this(initialPosition, 10);
}

public Vector initialPosition() {
return initialPosition;
}

public int gapBetweenIsland() {
return gapBetweenIsland;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class BasicArenaManager implements ArenaManager {
protected final PlatformArenaAdapter arenaAdapter;
public class BasicArenaManager implements ArenaManager {
protected final ArenaManagerOptions options;
protected final ClipboardPaster clipboardPaster;
protected final Vector initialPosition;

private final AtomicInteger offsetX;
private final Queue<Land> landReserves;

public BasicArenaManager(PlatformArenaAdapter arenaAdapter, Vector initialPosition) {
this.arenaAdapter = arenaAdapter;
public BasicArenaManager(PlatformArenaAdapter arenaAdapter, ArenaManagerOptions options) {
this.options = options;
this.clipboardPaster = arenaAdapter.clipboardPaster();
this.initialPosition = initialPosition;
this.offsetX = new AtomicInteger((int) initialPosition.x());
this.offsetX = new AtomicInteger((int) initialPosition().x());
this.landReserves = new LinkedList<>();
}

Expand Down Expand Up @@ -91,10 +89,14 @@ public void clear(Land land) {
}

protected Position reservePosition(RegionInfo region, World world) {
return new Position(world, offsetX.getAndAdd(region.getWidth() + gapBetweenLand()), (int) initialPosition.y(), (int) initialPosition.z());
return new Position(world, offsetX.getAndAdd(region.getWidth() + gapBetweenLand()), (int) initialPosition().y(), (int) initialPosition().z());
}

protected int gapBetweenLand() {
return 10;
return options.gapBetweenIsland();
}

public Vector initialPosition() {
return options.initialPosition();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.github.tofpu.speedbridge2.common.gameextra.land.GameLandReserver;
import com.github.tofpu.speedbridge2.common.gameextra.land.Land;
import com.github.tofpu.speedbridge2.common.gameextra.land.LandController;
import com.github.tofpu.speedbridge2.common.gameextra.land.arena.ArenaManagerOptions;
import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager;
import com.github.tofpu.speedbridge2.common.island.Island;
import com.github.tofpu.speedbridge2.common.island.IslandService;
import com.github.tofpu.speedbridge2.common.lobby.LobbyService;
import com.github.tofpu.speedbridge2.common.schematic.SchematicHandler;
import com.github.tofpu.speedbridge2.common.setup.listener.IslandSetupListener;
import com.github.tofpu.speedbridge2.event.dispatcher.EventDispatcherService;
import com.github.tofpu.speedbridge2.object.Location;
import com.github.tofpu.speedbridge2.object.Vector;
import com.github.tofpu.speedbridge2.object.World;
import com.github.tofpu.speedbridge2.object.player.OnlinePlayer;
import com.github.tofpu.speedbridge2.service.manager.ServiceManager;
Expand All @@ -19,6 +22,7 @@
import java.util.UUID;

public class GameSetupSystem {
private static final ArenaManagerOptions DEFAULT_OPTIONS = new ArenaManagerOptions(new Vector(0, 100, 100));
private final IslandSetupHandler setupHandler;
private final EventDispatcherService eventDispatcherService;
private final World world;
Expand All @@ -29,7 +33,7 @@ public GameSetupSystem(EventDispatcherService eventDispatcherService, PlatformAr
this.setupHandler = new IslandSetupHandler(eventDispatcherService);
this.eventDispatcherService = eventDispatcherService;
this.world = arenaAdapter.gameWorld();
this.landReserver = new GameLandReserver(world, schematicHandler, new LandController(new IslandSetupArenaManager(arenaAdapter)));
this.landReserver = new GameLandReserver(world, schematicHandler, new LandController(new BasicArenaManager(arenaAdapter, DEFAULT_OPTIONS)));
this.islandService = islandService;
}

Expand Down

This file was deleted.

0 comments on commit 784ad9f

Please sign in to comment.