Completed input refactoring
- Moved everything related to controls into controls package - Moved controls related to placing/breaking stuff into InteractionControls - Localizer now provides access to the list of languages - Fixed a random bug in TestMusicPlayer because why not amirite
This commit is contained in:
parent
a06d8ee056
commit
359879b0fe
@ -45,7 +45,7 @@ import ru.windcorp.progressia.common.util.Vectors;
|
||||
import ru.windcorp.progressia.common.world.GravityModel;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.test.CollisionModelRenderer;
|
||||
import ru.windcorp.progressia.test.TestPlayerControls;
|
||||
import ru.windcorp.progressia.test.controls.TestPlayerControls;
|
||||
|
||||
public class LayerWorld extends Layer {
|
||||
|
||||
@ -229,11 +229,6 @@ public class LayerWorld extends Layer {
|
||||
|
||||
@Override
|
||||
public void handleInput(InputEvent event) {
|
||||
if (event.isConsumed())
|
||||
return;
|
||||
|
||||
tmp_testControls.handleInput(event);
|
||||
|
||||
if (!event.isConsumed()) {
|
||||
inputBasedControls.handleInput(event);
|
||||
}
|
||||
|
@ -73,6 +73,12 @@ public class Localizer {
|
||||
return language;
|
||||
}
|
||||
|
||||
public List<String> getLanguages() {
|
||||
List<String> result = new ArrayList<>(langList.keySet());
|
||||
result.sort(null);
|
||||
return result;
|
||||
}
|
||||
|
||||
public synchronized String getValue(String key) {
|
||||
if (data == null) {
|
||||
throw new IllegalStateException("Localizer not yet initialized");
|
||||
|
@ -33,6 +33,7 @@ import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||
import ru.windcorp.progressia.server.Player;
|
||||
import ru.windcorp.progressia.server.Server;
|
||||
import ru.windcorp.progressia.server.ServerState;
|
||||
import ru.windcorp.progressia.test.controls.TestPlayerControls;
|
||||
|
||||
public class LayerButtonTest extends MenuLayer {
|
||||
|
||||
|
@ -39,6 +39,7 @@ import ru.windcorp.progressia.common.Units;
|
||||
import ru.windcorp.progressia.common.util.dynstr.DynamicStrings;
|
||||
import ru.windcorp.progressia.server.Server;
|
||||
import ru.windcorp.progressia.server.ServerState;
|
||||
import ru.windcorp.progressia.test.controls.TestPlayerControls;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -29,17 +29,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.client.ClientState;
|
||||
import ru.windcorp.progressia.client.audio.Sound;
|
||||
import ru.windcorp.progressia.client.comms.controls.*;
|
||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyMatcher;
|
||||
import ru.windcorp.progressia.client.graphics.input.WheelScrollEvent;
|
||||
import ru.windcorp.progressia.client.graphics.world.Selection;
|
||||
import ru.windcorp.progressia.client.world.block.*;
|
||||
import ru.windcorp.progressia.client.world.cro.ChunkRenderOptimizerRegistry;
|
||||
import ru.windcorp.progressia.client.world.cro.ChunkRenderOptimizerSimple;
|
||||
@ -48,25 +37,19 @@ import ru.windcorp.progressia.client.world.entity.*;
|
||||
import ru.windcorp.progressia.client.world.tile.*;
|
||||
import ru.windcorp.progressia.common.collision.AABB;
|
||||
import ru.windcorp.progressia.common.collision.CollisionModel;
|
||||
import ru.windcorp.progressia.common.comms.controls.*;
|
||||
import ru.windcorp.progressia.common.state.StatefulObjectRegistry.Factory;
|
||||
import ru.windcorp.progressia.common.world.GravityModelRegistry;
|
||||
import ru.windcorp.progressia.common.world.block.*;
|
||||
import ru.windcorp.progressia.common.world.entity.*;
|
||||
import ru.windcorp.progressia.common.world.io.ChunkIO;
|
||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
||||
import ru.windcorp.progressia.common.world.tile.*;
|
||||
import ru.windcorp.progressia.server.Server;
|
||||
import ru.windcorp.progressia.server.comms.controls.*;
|
||||
import ru.windcorp.progressia.server.world.block.*;
|
||||
import ru.windcorp.progressia.server.world.context.ServerBlockContext;
|
||||
import ru.windcorp.progressia.server.world.context.ServerTileContext;
|
||||
import ru.windcorp.progressia.server.world.context.ServerTileStackContext;
|
||||
import ru.windcorp.progressia.server.world.entity.*;
|
||||
import ru.windcorp.progressia.server.world.generation.planet.PlanetGravityModel;
|
||||
import ru.windcorp.progressia.server.world.tile.*;
|
||||
import ru.windcorp.progressia.test.Flowers.FlowerVariant;
|
||||
import ru.windcorp.progressia.test.Rocks.RockType;
|
||||
import ru.windcorp.progressia.test.controls.TestPlayerControls;
|
||||
import ru.windcorp.progressia.test.gen.TestGravityModel;
|
||||
import ru.windcorp.progressia.test.trees.BlockRenderLeavesHazel;
|
||||
import ru.windcorp.progressia.test.trees.BlockRenderLeavesPine;
|
||||
@ -293,82 +276,7 @@ public class TestContent {
|
||||
private static void regsiterControls() {
|
||||
TestPlayerControls.getInstance().registerControls();
|
||||
|
||||
ControlDataRegistry data = ControlDataRegistry.getInstance();
|
||||
ControlTriggerRegistry triggers = ControlTriggerRegistry.getInstance();
|
||||
ControlLogicRegistry logic = ControlLogicRegistry.getInstance();
|
||||
|
||||
data.register("Test:BreakBlock", ControlBreakBlockData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:BreakBlock",
|
||||
KeyEvent.class,
|
||||
TestContent::onBlockBreakTrigger,
|
||||
KeyMatcher.LMB::matches,
|
||||
i -> isAnythingSelected()
|
||||
)
|
||||
);
|
||||
logic.register(ControlLogic.of("Test:BreakBlock", TestContent::onBlockBreakReceived));
|
||||
|
||||
data.register("Test:PlaceBlock", ControlPlaceBlockData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:PlaceBlock",
|
||||
KeyEvent.class,
|
||||
TestContent::onBlockPlaceTrigger,
|
||||
KeyMatcher.RMB::matches,
|
||||
i -> isAnythingSelected() && TestPlayerControls.getInstance().isBlockSelected()
|
||||
)
|
||||
);
|
||||
|
||||
logic.register(ControlLogic.of("Test:PlaceBlock", TestContent::onBlockPlaceReceived));
|
||||
|
||||
data.register("Test:PlaceTile", ControlPlaceTileData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:PlaceTile",
|
||||
KeyEvent.class,
|
||||
TestContent::onTilePlaceTrigger,
|
||||
KeyMatcher.RMB::matches,
|
||||
i -> isAnythingSelected() && !TestPlayerControls.getInstance().isBlockSelected()
|
||||
)
|
||||
);
|
||||
logic.register(ControlLogic.of("Test:PlaceTile", TestContent::onTilePlaceReceived));
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SwitchPlacingModeMMB",
|
||||
KeyEvent.class,
|
||||
() -> TestPlayerControls.getInstance().switchPlacingMode(),
|
||||
KeyMatcher.MMB::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SwitchPlacingModeWheel",
|
||||
WheelScrollEvent.class,
|
||||
() -> TestPlayerControls.getInstance().switchPlacingMode(),
|
||||
e -> e.hasHorizontalMovement() || InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SelectNextBlockOrTile",
|
||||
WheelScrollEvent.class,
|
||||
e -> TestPlayerControls.getInstance().selectNextBlockOrTile(e),
|
||||
e -> !e.hasHorizontalMovement() && !InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:StartNextMusic",
|
||||
KeyEvent.class,
|
||||
TestMusicPlayer::startNextNow,
|
||||
new KeyMatcher("M")::matches
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static void register(BlockData x) {
|
||||
@ -424,95 +332,6 @@ public class TestContent {
|
||||
EntityLogicRegistry.getInstance().register(x);
|
||||
}
|
||||
|
||||
private static Selection getSelection() {
|
||||
ru.windcorp.progressia.client.Client client = ClientState.getInstance();
|
||||
if (client == null || !client.isReady())
|
||||
return null;
|
||||
|
||||
return client.getLocalPlayer().getSelection();
|
||||
}
|
||||
|
||||
private static boolean isAnythingSelected() {
|
||||
ru.windcorp.progressia.client.Client client = ClientState.getInstance();
|
||||
if (client == null || !client.isReady())
|
||||
return false;
|
||||
|
||||
return client.getLocalPlayer().getSelection().exists();
|
||||
}
|
||||
|
||||
private static void onBlockBreakTrigger(ControlData control) {
|
||||
((ControlBreakBlockData) control).setBlockInWorld(getSelection().getBlock());
|
||||
Sound sfx = new Sound("Progressia:BlockDestroy");
|
||||
sfx.setPosition(getSelection().getPoint());
|
||||
sfx.setPitch((float) (Math.random() + 1 * 0.5));
|
||||
sfx.play(false);
|
||||
}
|
||||
|
||||
private static void onBlockBreakReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
Vec3i blockInWorld = ((ControlBreakBlockData) packet.getControl()).getBlockInWorld();
|
||||
server.createAbsoluteContext().setBlock(blockInWorld, BlockDataRegistry.getInstance().get("Test:Air"));
|
||||
}
|
||||
|
||||
private static void onBlockPlaceTrigger(ControlData control) {
|
||||
((ControlPlaceBlockData) control).set(
|
||||
TestPlayerControls.getInstance().getSelectedBlock(),
|
||||
getSelection().getBlock().add_(getSelection().getSurface().getVector())
|
||||
);
|
||||
}
|
||||
|
||||
private static void onBlockPlaceReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
ControlPlaceBlockData controlData = ((ControlPlaceBlockData) packet.getControl());
|
||||
BlockData block = controlData.getBlock();
|
||||
Vec3i blockInWorld = controlData.getBlockInWorld();
|
||||
if (server.getWorld().getData().getChunkByBlock(blockInWorld) == null)
|
||||
return;
|
||||
server.createAbsoluteContext().setBlock(blockInWorld, block);
|
||||
}
|
||||
|
||||
private static void onTilePlaceTrigger(ControlData control) {
|
||||
((ControlPlaceTileData) control).set(
|
||||
TestPlayerControls.getInstance().getSelectedTile(),
|
||||
getSelection().getBlock(),
|
||||
getSelection().getSurface()
|
||||
);
|
||||
}
|
||||
|
||||
private static void onTilePlaceReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
ControlPlaceTileData controlData = ((ControlPlaceTileData) packet.getControl());
|
||||
TileData tile = controlData.getTile();
|
||||
Vec3i blockInWorld = controlData.getBlockInWorld();
|
||||
AbsFace face = controlData.getFace();
|
||||
|
||||
if (server.getWorld().getData().getChunkByBlock(blockInWorld) == null) {
|
||||
return;
|
||||
}
|
||||
if (server.getWorld().getData().getTiles(blockInWorld, face).isFull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerBlockContext context = server.createContext(blockInWorld);
|
||||
ServerTileStackContext tsContext = context.push(context.toContext(face));
|
||||
ServerTileContext tileContext = tsContext.push(tsContext.getTileCount());
|
||||
|
||||
TileLogic logic = TileLogicRegistry.getInstance().get(tile.getId());
|
||||
if (!logic.canOccupyFace(tileContext)) {
|
||||
return;
|
||||
}
|
||||
tileContext.addTile(tile);
|
||||
}
|
||||
|
||||
private static void registerMisc() {
|
||||
ChunkIO.registerCodec(new TestChunkCodec());
|
||||
|
||||
|
@ -110,6 +110,7 @@ public class TestMusicPlayer implements Runnable {
|
||||
String file = it.next().toString();
|
||||
if (!file.endsWith(".ogg") && !file.endsWith(".oga")) {
|
||||
LogManager.getLogger().warn("Skipping " + file + ": not .ogg nor .oga");
|
||||
continue;
|
||||
}
|
||||
|
||||
String id = "Progressia:Music" + (i++);
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ru.windcorp.progressia.test;
|
||||
package ru.windcorp.progressia.test.controls;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.comms.controls.ControlData;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ru.windcorp.progressia.test;
|
||||
package ru.windcorp.progressia.test.controls;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.comms.controls.ControlData;
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ru.windcorp.progressia.test;
|
||||
package ru.windcorp.progressia.test.controls;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.comms.controls.ControlData;
|
@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.test.controls;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.client.ClientState;
|
||||
import ru.windcorp.progressia.client.audio.Sound;
|
||||
import ru.windcorp.progressia.client.comms.controls.ControlTriggerRegistry;
|
||||
import ru.windcorp.progressia.client.comms.controls.ControlTriggers;
|
||||
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyMatcher;
|
||||
import ru.windcorp.progressia.client.graphics.input.WheelScrollEvent;
|
||||
import ru.windcorp.progressia.client.graphics.world.Selection;
|
||||
import ru.windcorp.progressia.common.comms.controls.ControlData;
|
||||
import ru.windcorp.progressia.common.comms.controls.ControlDataRegistry;
|
||||
import ru.windcorp.progressia.common.comms.controls.PacketControl;
|
||||
import ru.windcorp.progressia.common.world.block.BlockData;
|
||||
import ru.windcorp.progressia.common.world.block.BlockDataRegistry;
|
||||
import ru.windcorp.progressia.common.world.rels.AbsFace;
|
||||
import ru.windcorp.progressia.common.world.tile.TileData;
|
||||
import ru.windcorp.progressia.server.Server;
|
||||
import ru.windcorp.progressia.server.comms.controls.ControlLogic;
|
||||
import ru.windcorp.progressia.server.comms.controls.ControlLogicRegistry;
|
||||
import ru.windcorp.progressia.server.world.context.ServerBlockContext;
|
||||
import ru.windcorp.progressia.server.world.context.ServerTileContext;
|
||||
import ru.windcorp.progressia.server.world.context.ServerTileStackContext;
|
||||
import ru.windcorp.progressia.server.world.tile.TileLogic;
|
||||
import ru.windcorp.progressia.server.world.tile.TileLogicRegistry;
|
||||
import ru.windcorp.progressia.test.TestContent;
|
||||
|
||||
public class InteractionControls {
|
||||
|
||||
private int selectedBlock;
|
||||
private int selectedTile;
|
||||
private boolean isBlockSelected;
|
||||
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
selectedBlock = 0;
|
||||
selectedTile = 0;
|
||||
isBlockSelected = true;
|
||||
}
|
||||
|
||||
public void registerControls() {
|
||||
ControlDataRegistry data = ControlDataRegistry.getInstance();
|
||||
ControlTriggerRegistry triggers = ControlTriggerRegistry.getInstance();
|
||||
ControlLogicRegistry logic = ControlLogicRegistry.getInstance();
|
||||
|
||||
data.register("Test:BreakBlock", ControlBreakBlockData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:BreakBlock",
|
||||
KeyEvent.class,
|
||||
this::onBlockBreakTrigger,
|
||||
KeyMatcher.LMB::matches,
|
||||
i -> isAnythingSelected()
|
||||
)
|
||||
);
|
||||
logic.register(ControlLogic.of("Test:BreakBlock", InteractionControls::onBlockBreakReceived));
|
||||
|
||||
data.register("Test:PlaceBlock", ControlPlaceBlockData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:PlaceBlock",
|
||||
KeyEvent.class,
|
||||
this::onBlockPlaceTrigger,
|
||||
KeyMatcher.RMB::matches,
|
||||
i -> isAnythingSelected() && isBlockSelected()
|
||||
)
|
||||
);
|
||||
|
||||
logic.register(ControlLogic.of("Test:PlaceBlock", InteractionControls::onBlockPlaceReceived));
|
||||
|
||||
data.register("Test:PlaceTile", ControlPlaceTileData::new);
|
||||
triggers.register(
|
||||
ControlTriggers.of(
|
||||
"Test:PlaceTile",
|
||||
KeyEvent.class,
|
||||
this::onTilePlaceTrigger,
|
||||
KeyMatcher.RMB::matches,
|
||||
i -> isAnythingSelected() && !isBlockSelected()
|
||||
)
|
||||
);
|
||||
logic.register(ControlLogic.of("Test:PlaceTile", InteractionControls::onTilePlaceReceived));
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SwitchPlacingModeMMB",
|
||||
KeyEvent.class,
|
||||
this::switchPlacingMode,
|
||||
KeyMatcher.MMB::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SwitchPlacingModeWheel",
|
||||
WheelScrollEvent.class,
|
||||
this::switchPlacingMode,
|
||||
e -> e.hasHorizontalMovement() || InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SelectNextBlockOrTile",
|
||||
WheelScrollEvent.class,
|
||||
this::selectNextBlockOrTile,
|
||||
e -> !e.hasHorizontalMovement() && !InputTracker.isKeyPressed(GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static Selection getSelection() {
|
||||
ru.windcorp.progressia.client.Client client = ClientState.getInstance();
|
||||
if (client == null || !client.isReady())
|
||||
return null;
|
||||
|
||||
return client.getLocalPlayer().getSelection();
|
||||
}
|
||||
|
||||
private static boolean isAnythingSelected() {
|
||||
ru.windcorp.progressia.client.Client client = ClientState.getInstance();
|
||||
if (client == null || !client.isReady())
|
||||
return false;
|
||||
|
||||
return client.getLocalPlayer().getSelection().exists();
|
||||
}
|
||||
|
||||
private void onBlockBreakTrigger(ControlData control) {
|
||||
((ControlBreakBlockData) control).setBlockInWorld(getSelection().getBlock());
|
||||
Sound sfx = new Sound("Progressia:BlockDestroy");
|
||||
sfx.setPosition(getSelection().getPoint());
|
||||
sfx.setPitch((float) (Math.random() + 1 * 0.5));
|
||||
sfx.play(false);
|
||||
}
|
||||
|
||||
private static void onBlockBreakReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
Vec3i blockInWorld = ((ControlBreakBlockData) packet.getControl()).getBlockInWorld();
|
||||
server.createAbsoluteContext().setBlock(blockInWorld, BlockDataRegistry.getInstance().get("Test:Air"));
|
||||
}
|
||||
|
||||
private void onBlockPlaceTrigger(ControlData control) {
|
||||
((ControlPlaceBlockData) control).set(
|
||||
getSelectedBlock(),
|
||||
getSelection().getBlock().add_(getSelection().getSurface().getVector())
|
||||
);
|
||||
}
|
||||
|
||||
private static void onBlockPlaceReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
ControlPlaceBlockData controlData = ((ControlPlaceBlockData) packet.getControl());
|
||||
BlockData block = controlData.getBlock();
|
||||
Vec3i blockInWorld = controlData.getBlockInWorld();
|
||||
if (server.getWorld().getData().getChunkByBlock(blockInWorld) == null)
|
||||
return;
|
||||
server.createAbsoluteContext().setBlock(blockInWorld, block);
|
||||
}
|
||||
|
||||
private void onTilePlaceTrigger(ControlData control) {
|
||||
((ControlPlaceTileData) control).set(
|
||||
getSelectedTile(),
|
||||
getSelection().getBlock(),
|
||||
getSelection().getSurface()
|
||||
);
|
||||
}
|
||||
|
||||
private static void onTilePlaceReceived(
|
||||
Server server,
|
||||
PacketControl packet,
|
||||
ru.windcorp.progressia.server.comms.Client client
|
||||
) {
|
||||
ControlPlaceTileData controlData = ((ControlPlaceTileData) packet.getControl());
|
||||
TileData tile = controlData.getTile();
|
||||
Vec3i blockInWorld = controlData.getBlockInWorld();
|
||||
AbsFace face = controlData.getFace();
|
||||
|
||||
if (server.getWorld().getData().getChunkByBlock(blockInWorld) == null) {
|
||||
return;
|
||||
}
|
||||
if (server.getWorld().getData().getTiles(blockInWorld, face).isFull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerBlockContext context = server.createContext(blockInWorld);
|
||||
ServerTileStackContext tsContext = context.push(context.toContext(face));
|
||||
ServerTileContext tileContext = tsContext.push(tsContext.getTileCount());
|
||||
|
||||
TileLogic logic = TileLogicRegistry.getInstance().get(tile.getId());
|
||||
if (!logic.canOccupyFace(tileContext)) {
|
||||
return;
|
||||
}
|
||||
tileContext.addTile(tile);
|
||||
}
|
||||
|
||||
public void switchPlacingMode() {
|
||||
isBlockSelected = !isBlockSelected;
|
||||
}
|
||||
|
||||
public void selectNextBlockOrTile(WheelScrollEvent event) {
|
||||
if (isBlockSelected) {
|
||||
selectedBlock += event.isUp() ? +1 : -1;
|
||||
|
||||
int size = TestContent.PLACEABLE_BLOCKS.size();
|
||||
|
||||
if (selectedBlock < 0) {
|
||||
selectedBlock = size - 1;
|
||||
} else if (selectedBlock >= size) {
|
||||
selectedBlock = 0;
|
||||
}
|
||||
} else {
|
||||
selectedTile += event.isUp() ? +1 : -1;
|
||||
|
||||
int size = TestContent.PLACEABLE_TILES.size();
|
||||
|
||||
if (selectedTile < 0) {
|
||||
selectedTile = size - 1;
|
||||
} else if (selectedTile >= size) {
|
||||
selectedTile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockData getSelectedBlock() {
|
||||
return TestContent.PLACEABLE_BLOCKS.get(selectedBlock);
|
||||
}
|
||||
|
||||
public TileData getSelectedTile() {
|
||||
return TestContent.PLACEABLE_TILES.get(selectedTile);
|
||||
}
|
||||
|
||||
public boolean isBlockSelected() {
|
||||
return isBlockSelected;
|
||||
}
|
||||
|
||||
}
|
@ -120,7 +120,13 @@ public class MovementControls {
|
||||
|
||||
Mat3 movementTransform = getMovementTransform(player, null);
|
||||
Vec3 desiredVelocity = getDesiredVelocity(movementTransform, speed, isFlying);
|
||||
Vec3 newVelocity = getNewVelocity(desiredVelocity, player.getVelocity(), authority, player.getUpVector());
|
||||
Vec3 newVelocity = getNewVelocity(
|
||||
desiredVelocity,
|
||||
player.getVelocity(),
|
||||
authority,
|
||||
player.getUpVector(),
|
||||
isFlying
|
||||
);
|
||||
player.getVelocity().set(newVelocity);
|
||||
|
||||
tmp_syncServerEntity();
|
||||
@ -188,7 +194,7 @@ public class MovementControls {
|
||||
return desiredVelocity;
|
||||
}
|
||||
|
||||
private Vec3 getNewVelocity(Vec3 desiredVelocity, Vec3 oldVelocity, float authority, Vec3 up) {
|
||||
private Vec3 getNewVelocity(Vec3 desiredVelocity, Vec3 oldVelocity, float authority, Vec3 up, boolean isFlying) {
|
||||
|
||||
// newVelocity = oldVelocity + small change toward desiredVelocity
|
||||
Vec3 newVelocity = new Vec3()
|
||||
@ -251,6 +257,14 @@ public class MovementControls {
|
||||
}
|
||||
|
||||
private void handleSpacePress(KeyEvent e) {
|
||||
if (
|
||||
ClientState.getInstance().getCamera().getAnchor() instanceof EntityAnchor
|
||||
&& ((EntityAnchor) ClientState.getInstance().getCamera().getAnchor()).getEntity().getId()
|
||||
.equals("Test:NoclipCamera")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
double timeSinceLastSpacePress = e.getTime() - lastSpacePress;
|
||||
|
||||
if (timeSinceLastSpacePress < FLYING_SWITCH_MAX_DELAY) {
|
||||
|
@ -16,23 +16,26 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ru.windcorp.progressia.test;
|
||||
package ru.windcorp.progressia.test.controls;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import ru.windcorp.progressia.client.ClientState;
|
||||
import ru.windcorp.progressia.client.comms.controls.ControlTriggerRegistry;
|
||||
import ru.windcorp.progressia.client.comms.controls.ControlTriggers;
|
||||
import ru.windcorp.progressia.client.graphics.GUI;
|
||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.WheelScrollEvent;
|
||||
import ru.windcorp.progressia.client.graphics.input.KeyMatcher;
|
||||
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
||||
import ru.windcorp.progressia.client.localization.Localizer;
|
||||
import ru.windcorp.progressia.common.world.block.BlockData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.common.world.tile.TileData;
|
||||
import ru.windcorp.progressia.test.controls.CameraControls;
|
||||
import ru.windcorp.progressia.test.controls.MovementControls;
|
||||
import ru.windcorp.progressia.test.LayerButtonTest;
|
||||
import ru.windcorp.progressia.test.LayerDebug;
|
||||
import ru.windcorp.progressia.test.TestMusicPlayer;
|
||||
|
||||
public class TestPlayerControls {
|
||||
|
||||
@ -44,10 +47,7 @@ public class TestPlayerControls {
|
||||
|
||||
private final MovementControls movementControls = new MovementControls();
|
||||
private final CameraControls cameraControls = new CameraControls();
|
||||
|
||||
private int selectedBlock = 0;
|
||||
private int selectedTile = 0;
|
||||
private boolean isBlockSelected = true;
|
||||
private final InteractionControls interactionControls = new InteractionControls();
|
||||
|
||||
private LayerDebug debugLayer = null;
|
||||
|
||||
@ -62,11 +62,9 @@ public class TestPlayerControls {
|
||||
private void reset() {
|
||||
movementControls.reset();
|
||||
cameraControls.reset();
|
||||
interactionControls.reset();
|
||||
|
||||
debugLayer = null;
|
||||
selectedBlock = 0;
|
||||
selectedTile = 0;
|
||||
isBlockSelected = true;
|
||||
}
|
||||
|
||||
public void applyPlayerControls() {
|
||||
@ -76,52 +74,78 @@ public class TestPlayerControls {
|
||||
public void registerControls() {
|
||||
movementControls.registerControls();
|
||||
cameraControls.registerControls();
|
||||
interactionControls.registerControls();
|
||||
|
||||
ControlTriggerRegistry triggers = ControlTriggerRegistry.getInstance();
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:PauseGame",
|
||||
KeyEvent.class,
|
||||
this::pauseGame,
|
||||
new KeyMatcher("Escape")::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:ToggleFullscreen",
|
||||
KeyEvent.class,
|
||||
this::toggleFullscreen,
|
||||
new KeyMatcher("F11")::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:ToggleVSync",
|
||||
KeyEvent.class,
|
||||
this::toggleVSync,
|
||||
new KeyMatcher("F12")::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:ToggleDebugLayer",
|
||||
KeyEvent.class,
|
||||
this::toggleDebugLayer,
|
||||
new KeyMatcher("F3")::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:SwitchLanguage",
|
||||
KeyEvent.class,
|
||||
this::switchLanguage,
|
||||
new KeyMatcher("L")::matches
|
||||
)
|
||||
);
|
||||
|
||||
triggers.register(
|
||||
ControlTriggers.localOf(
|
||||
"Test:StartNextMusic",
|
||||
KeyEvent.class,
|
||||
TestMusicPlayer::startNextNow,
|
||||
new KeyMatcher("M")::matches
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void handleInput(InputEvent event) {
|
||||
if (event instanceof KeyEvent) {
|
||||
if (onKeyEvent((KeyEvent) event)) {
|
||||
event.consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean onKeyEvent(KeyEvent event) {
|
||||
if (!event.isPress())
|
||||
return false;
|
||||
switch (event.getKey()) {
|
||||
case GLFW.GLFW_KEY_ESCAPE:
|
||||
handleEscape();
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_F11:
|
||||
GraphicsInterface.makeFullscreen(!GraphicsBackend.isFullscreen());
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_F12:
|
||||
GraphicsBackend.setVSyncEnabled(!GraphicsBackend.isVSyncEnabled());
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_F3:
|
||||
handleDebugLayerSwitch();
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_L:
|
||||
handleLanguageSwitch();
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleEscape() {
|
||||
private void pauseGame() {
|
||||
GUI.addTopLayer(new LayerButtonTest());
|
||||
}
|
||||
|
||||
private void handleDebugLayerSwitch() {
|
||||
private void toggleFullscreen() {
|
||||
GraphicsInterface.makeFullscreen(!GraphicsBackend.isFullscreen());
|
||||
}
|
||||
|
||||
private void toggleVSync() {
|
||||
GraphicsBackend.setVSyncEnabled(!GraphicsBackend.isVSyncEnabled());
|
||||
}
|
||||
|
||||
private void toggleDebugLayer() {
|
||||
if (debugLayer == null) {
|
||||
this.debugLayer = new LayerDebug();
|
||||
}
|
||||
@ -133,41 +157,19 @@ public class TestPlayerControls {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLanguageSwitch() {
|
||||
private void switchLanguage() {
|
||||
Localizer localizer = Localizer.getInstance();
|
||||
if (localizer.getLanguage().equals("ru-RU")) {
|
||||
localizer.setLanguage("en-US");
|
||||
List<String> languages = localizer.getLanguages();
|
||||
|
||||
int index = languages.indexOf(localizer.getLanguage());
|
||||
|
||||
if (index == languages.size() - 1) {
|
||||
index = 0;
|
||||
} else {
|
||||
localizer.setLanguage("ru-RU");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public void switchPlacingMode() {
|
||||
isBlockSelected = !isBlockSelected;
|
||||
}
|
||||
|
||||
public void selectNextBlockOrTile(WheelScrollEvent event) {
|
||||
if (isBlockSelected) {
|
||||
selectedBlock += event.isUp() ? +1 : -1;
|
||||
|
||||
int size = TestContent.PLACEABLE_BLOCKS.size();
|
||||
|
||||
if (selectedBlock < 0) {
|
||||
selectedBlock = size - 1;
|
||||
} else if (selectedBlock >= size) {
|
||||
selectedBlock = 0;
|
||||
}
|
||||
} else {
|
||||
selectedTile += event.isUp() ? +1 : -1;
|
||||
|
||||
int size = TestContent.PLACEABLE_TILES.size();
|
||||
|
||||
if (selectedTile < 0) {
|
||||
selectedTile = size - 1;
|
||||
} else if (selectedTile >= size) {
|
||||
selectedTile = 0;
|
||||
}
|
||||
}
|
||||
localizer.setLanguage(languages.get(index));
|
||||
}
|
||||
|
||||
public EntityData getEntity() {
|
||||
@ -183,15 +185,15 @@ public class TestPlayerControls {
|
||||
}
|
||||
|
||||
public BlockData getSelectedBlock() {
|
||||
return TestContent.PLACEABLE_BLOCKS.get(selectedBlock);
|
||||
return interactionControls.getSelectedBlock();
|
||||
}
|
||||
|
||||
public TileData getSelectedTile() {
|
||||
return TestContent.PLACEABLE_TILES.get(selectedTile);
|
||||
return interactionControls.getSelectedTile();
|
||||
}
|
||||
|
||||
public boolean isBlockSelected() {
|
||||
return isBlockSelected;
|
||||
return interactionControls.isBlockSelected();
|
||||
}
|
||||
|
||||
public boolean isFlying() {
|
Reference in New Issue
Block a user