Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander authored and FoundationGames committed Aug 18, 2023
1 parent 3ae3c22 commit 88c75ba
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void init() {
initEntities();
ClientPackets.initClient();

Platform.get().controllerCompat().initCompat();
Platform.get().controller().initCompat();

Platform.get().registerMenuScreen(Automobility.AUTO_MECHANIC_SCREEN.require(), AutoMechanicTableScreen::new);
Platform.get().registerMenuScreen(Automobility.SINGLE_SLOT_SCREEN.require(), SingleSlotScreen::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.foundationgames.automobility.controller;

public interface ControllerCompat {
public interface AutomobileController {
boolean accelerating();

boolean braking();
Expand All @@ -15,7 +15,7 @@ default void crashRumble() {}

default void initCompat() {}

ControllerCompat INCOMPATIBLE = new ControllerCompat() {
AutomobileController INCOMPATIBLE = new AutomobileController() {
@Override
public boolean accelerating() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private void setDrifting(boolean drifting) {
}

if (this.drifting != drifting) {
Platform.get().controllerCompat().updateDriftRumbleState(drifting);
Platform.get().controller().updateDriftRumbleState(drifting);
}
}

Expand Down Expand Up @@ -904,7 +904,7 @@ public void postMovementTick() {

if (isVehicle() && level().isClientSide()) {
if (getPassengers().stream().anyMatch(p -> p instanceof LocalPlayer)) {
Platform.get().controllerCompat().crashRumble();
Platform.get().controller().crashRumble();
}
}

Expand Down Expand Up @@ -1224,7 +1224,7 @@ public void createDriftParticles() {
}

private static boolean inLockedViewMode() {
return Platform.get().controllerCompat().inControllerMode();
return Platform.get().controller().inControllerMode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public class LocalPlayerMixin {
public void automobility$setAutomobileInputs(CallbackInfo ci) {
LocalPlayer self = (LocalPlayer)(Object)this;
if (self.getVehicle() instanceof AutomobileEntity vehicle) {
if (Platform.get().controllerCompat().inControllerMode()) {
if (Platform.get().controller().inControllerMode()) {
vehicle.provideClientInput(
Platform.get().controllerCompat().accelerating(),
Platform.get().controllerCompat().braking(),
Platform.get().controller().accelerating(),
Platform.get().controller().braking(),
input.left,
input.right,
Platform.get().controllerCompat().drifting()
Platform.get().controller().drifting()
);
} else {
vehicle.provideClientInput(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.foundationgames.automobility.platform;

import com.mojang.blaze3d.vertex.PoseStack;
import io.github.foundationgames.automobility.controller.ControllerCompat;
import io.github.foundationgames.automobility.controller.AutomobileController;
import io.github.foundationgames.automobility.util.HexCons;
import io.github.foundationgames.automobility.util.TriCons;
import io.github.foundationgames.automobility.util.TriFunc;
Expand Down Expand Up @@ -88,6 +88,6 @@ static Platform get() {

SimpleParticleType simpleParticleType(boolean z);

ControllerCompat controllerCompat();
AutomobileController controller();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.foundationgames.automobility.screen;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.platform.Platform;
import io.github.foundationgames.automobility.util.AUtils;
Expand All @@ -27,7 +26,7 @@ public enum AutomobileHud {;
public static void render(GuiGraphics graphics, Player player, AutomobileEntity auto, float tickDelta) {
renderSpeedometer(graphics, auto);

if (!Platform.get().controllerCompat().inControllerMode()) {
if (!Platform.get().controller().inControllerMode()) {
float alpha = Math.max(0, (auto.getStandStillTime() * 2) - 1);

// Check on a 0-255 converted version of alpha, because 0 alpha will render things at 100% alpha for some
Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.foundationgames.automobility.fabric;

import com.mojang.blaze3d.vertex.PoseStack;
import io.github.foundationgames.automobility.controller.ControllerCompat;
import io.github.foundationgames.automobility.fabric.controller.controlify.ControlifyCompat;
import io.github.foundationgames.automobility.fabric.controller.midnightcontrols.AutomobilityMidnightControls;
import io.github.foundationgames.automobility.controller.AutomobileController;
import io.github.foundationgames.automobility.fabric.controller.controlify.ControlifyController;
import io.github.foundationgames.automobility.fabric.controller.midnightcontrols.MidnightController;
import io.github.foundationgames.automobility.platform.Platform;
import io.github.foundationgames.automobility.util.HexCons;
import io.github.foundationgames.automobility.util.TriCons;
Expand Down Expand Up @@ -65,7 +65,7 @@
public class FabricPlatform implements Platform {
private static final FabricPlatform INSTANCE = new FabricPlatform();

private ControllerCompat controllerCompat = null;
private AutomobileController automobileController = null;

public static void init() {
Platform.init(INSTANCE);
Expand Down Expand Up @@ -153,18 +153,18 @@ public SimpleParticleType simpleParticleType(boolean z) {
}

@Override
public ControllerCompat controllerCompat() {
if (controllerCompat == null) {
public AutomobileController controller() {
if (automobileController == null) {
if (FabricLoader.getInstance().isModLoaded("controlify")) {
controllerCompat = new ControlifyCompat();
automobileController = new ControlifyController();
} else if (FabricLoader.getInstance().isModLoaded("midnightcontrols")) {
controllerCompat = new AutomobilityMidnightControls();
automobileController = new MidnightController();
} else {
controllerCompat = ControllerCompat.INCOMPATIBLE;
automobileController = AutomobileController.INCOMPATIBLE;
}
}

return controllerCompat;
return automobileController;
}

}
Original file line number Diff line number Diff line change
@@ -1,71 +1,64 @@
package io.github.foundationgames.automobility.fabric.controller.controlify;

import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.api.bind.BindingSupplier;
import dev.isxander.controlify.api.bind.ControllerBinding;
import dev.isxander.controlify.rumble.BasicRumbleEffect;
import dev.isxander.controlify.rumble.ContinuousRumbleEffect;
import dev.isxander.controlify.rumble.RumbleSource;
import dev.isxander.controlify.rumble.RumbleState;
import io.github.foundationgames.automobility.controller.ControllerCompat;
import dev.isxander.controlify.api.bind.ControlifyBindingsApi;
import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint;
import dev.isxander.controlify.api.event.ControlifyEvents;
import dev.isxander.controlify.api.guide.ActionPriority;
import dev.isxander.controlify.api.ingameguide.ActionLocation;
import dev.isxander.controlify.bindings.BindContext;
import dev.isxander.controlify.bindings.GamepadBinds;
import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import net.minecraft.network.chat.Component;

public class ControlifyCompat implements ControllerCompat {
static BindingSupplier accelerateBinding, brakeBinding, driftBinding;
private ContinuousRumbleEffect driftRumbleEffect = null;
import java.util.Optional;
import java.util.Set;

public class ControlifyCompat implements ControlifyEntrypoint {
@Override
public boolean accelerating() {
return isDown(accelerateBinding);
}
public void onControlifyPreInit(ControlifyApi controlify) {
BindContext drivingCtx = new BindContext(Automobility.rl("driving"), Set.of());
Component category = Component.translatable("controlify.binding_category.driving");

@Override
public boolean braking() {
return isDown(brakeBinding);
}
ControlifyController.accelerateBinding = ControlifyBindingsApi.get().registerBind(Automobility.rl("accelerate_automobile"), builder -> builder
.defaultBind(GamepadBinds.A_BUTTON)
.context(drivingCtx)
.category(category));
ControlifyController.brakeBinding = ControlifyBindingsApi.get().registerBind(Automobility.rl("brake_automobile"), builder -> builder
.defaultBind(GamepadBinds.B_BUTTON)
.context(drivingCtx)
.category(category));
ControlifyController.driftBinding = ControlifyBindingsApi.get().registerBind(Automobility.rl("drift_automobile"), builder -> builder
.defaultBind(GamepadBinds.RIGHT_TRIGGER)
.context(drivingCtx)
.category(category));

@Override
public boolean drifting() {
return isDown(driftBinding);
}
ControlifyEvents.INGAME_GUIDE_REGISTRY.register((bindings, registry) -> {
var accelerate = bindings.get(Automobility.rl("accelerate_automobile"));
var brake = bindings.get(Automobility.rl("brake_automobile"));
var drift = bindings.get(Automobility.rl("drift_automobile"));

@Override
public boolean inControllerMode() {
return ControlifyApi.get().currentInputMode().isController();
}

private boolean isDown(BindingSupplier binding) {
return inControllerMode() && ControlifyApi.get().getCurrentController()
.map(binding::onController)
.map(ControllerBinding::held)
.orElse(false);
}

@Override
public void crashRumble() {
ControlifyApi.get().getCurrentController().ifPresent(controller -> {
controller.rumbleManager().play(
RumbleSource.DAMAGE,
BasicRumbleEffect.byTime(
t -> new RumbleState(t < 0.5 ? 1 : 0, 1 - t),
20
)
);
registry.registerGuideAction(accelerate, ActionLocation.LEFT, ActionPriority.LOW, ctx -> {
if (ctx.player().getVehicle() instanceof AutomobileEntity)
return Optional.of(Component.translatable("controlify.binding.automobility.accelerate_automobile"));
return Optional.empty();
});
registry.registerGuideAction(brake, ActionLocation.LEFT, ActionPriority.LOW, ctx -> {
if (ctx.player().getVehicle() instanceof AutomobileEntity)
return Optional.of(Component.translatable("controlify.binding.automobility.brake_automobile"));
return Optional.empty();
});
registry.registerGuideAction(drift, ActionLocation.LEFT, ActionPriority.LOW, ctx -> {
if (ctx.player().getVehicle() instanceof AutomobileEntity)
return Optional.of(Component.translatable("controlify.binding.automobility.drift_automobile"));
return Optional.empty();
});
});
}

@Override
public void updateDriftRumbleState(boolean drifting) {
if (drifting) {
if (driftRumbleEffect != null && !driftRumbleEffect.isFinished())
return;
public void onControllersDiscovered(ControlifyApi controlify) {

driftRumbleEffect = ContinuousRumbleEffect.builder()
.constant(0f, 0.8f)
.build();
ControlifyApi.get().getCurrentController().ifPresent(controller ->
controller.rumbleManager().play(RumbleSource.MASTER, driftRumbleEffect));
} else if (driftRumbleEffect != null) {
driftRumbleEffect.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.github.foundationgames.automobility.fabric.controller.controlify;

import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.api.bind.BindingSupplier;
import dev.isxander.controlify.api.bind.ControllerBinding;
import dev.isxander.controlify.rumble.BasicRumbleEffect;
import dev.isxander.controlify.rumble.ContinuousRumbleEffect;
import dev.isxander.controlify.rumble.RumbleSource;
import dev.isxander.controlify.rumble.RumbleState;
import io.github.foundationgames.automobility.controller.AutomobileController;

public class ControlifyController implements AutomobileController {
static BindingSupplier accelerateBinding, brakeBinding, driftBinding;
private ContinuousRumbleEffect driftRumbleEffect = null;

@Override
public boolean accelerating() {
return isDown(accelerateBinding);
}

@Override
public boolean braking() {
return isDown(brakeBinding);
}

@Override
public boolean drifting() {
return isDown(driftBinding);
}

@Override
public boolean inControllerMode() {
return ControlifyApi.get().currentInputMode().isController();
}

private boolean isDown(BindingSupplier binding) {
return inControllerMode() && ControlifyApi.get().getCurrentController()
.map(binding::onController)
.map(ControllerBinding::held)
.orElse(false);
}

@Override
public void crashRumble() {
ControlifyApi.get().getCurrentController().ifPresent(controller -> {
controller.rumbleManager().play(
RumbleSource.DAMAGE,
BasicRumbleEffect.byTime(
t -> new RumbleState(t < 0.5 ? 1 : 0, 1 - t),
20
)
);
});
}

@Override
public void updateDriftRumbleState(boolean drifting) {
if (drifting) {
if (driftRumbleEffect != null && !driftRumbleEffect.isFinished())
return;

driftRumbleEffect = ContinuousRumbleEffect.builder()
.constant(0f, 0.8f)
.build();
ControlifyApi.get().getCurrentController().ifPresent(controller ->
controller.rumbleManager().play(RumbleSource.MASTER, driftRumbleEffect));
} else if (driftRumbleEffect != null) {
driftRumbleEffect.stop();
}
}
}
Loading

0 comments on commit 88c75ba

Please sign in to comment.