Skip to content

Commit f8a71d5

Browse files
authored
feat: add snap to facing camera mode & update README.md (#21)
1 parent 7877dae commit f8a71d5

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# Compass Camera Control
22
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/RaazKH/CompassCameraControl?include_prereleases&logo=github)
3-
43
A RuneLite plugin that allows you to control the camera direction by either clicking the compass orb or using customizable keybindings.
54

65
## Compass Orb Control
7-
8-
You can cycle through cardinal directions or snap to the closest one by clicking on the compass orb.
6+
You can cycle through cardinal directions, snap to the closest one, or snap to your character's facing direction by clicking on the compass orb.
97

108
### Cycle Mode (default)
11-
129
1. If facing North, the camera will rotate to South.
1310
2. If facing South, it will rotate to East.
1411
3. If facing East, it will rotate to West.
@@ -17,23 +14,23 @@ You can cycle through cardinal directions or snap to the closest one by clicking
1714
The process repeats when clicking the compass orb.
1815

1916
### Snap to Closest Mode
20-
2117
When clicking the compass, the camera will snap to the closest cardinal direction.
2218
Useful for spinning the camera manually, then aligning to the grid.
2319

20+
### Snap to Facing Mode
21+
When clicking the compass, the camera will snap to face the same direction as your character.
22+
Works with all 8 directions (N, NE, E, SE, S, SW, W, NW).
2423

2524
### Shift-Click Option
26-
2725
You can configure how the plugin responds to clicks on the compass:
28-
2926
- **Off**: Always active, ignoring the Shift key.
3027
- **On Shift**: Only works when Shift is held down.
3128
- **Off Shift**: Works only when Shift is not held down.
3229

3330
## Keybindings
34-
3531
You can set up shortcuts for quick camera control. To prevent shortcuts from appearing in the chat, enable the "Key Remapping" plugin (included with RuneLite).
3632

33+
- **Snap to Facing**: Snap camera to your character's facing direction when pressed
3734
- **Snap to Closest**: Snap camera to the closest cardinal direction when pressed
3835
- **Cycle Cardinal**: Cycle through your custom cycle order of directions when pressed
3936
- **Look North Key**: Face camera North when pressed
@@ -42,21 +39,15 @@ You can set up shortcuts for quick camera control. To prevent shortcuts from app
4239
- **Look West Key**: Face camera West when pressed
4340

4441
---
45-
4642
### Custom Cycle Order
47-
4843
You can specify a custom order for cycling through directions. For example, if you prefer to cycle between North and South, you can set the cycle order to `N,S`. Only `N`, `S`, `W`, and `E` are valid characters for this field, all other characters will be ignored.
4944

5045
This field is **not** case-sensitive. Non-unique cardinal directions will be ignored. So `N,S,E,S` would cycle through `N,S,E`, the final `S` being a duplicate and thus is ignored.
5146

5247
---
53-
5448
#### Issues and Feedback
55-
5649
If you encounter any bugs, have suggestions for improvements, or would like to give feedback, please feel free to <a href="https://github.com/RaazKH/CompassCameraControl/issues">submit an issue</a>.
5750

5851
---
59-
6052
#### Contributors
61-
62-
Thanks to [LlemonDuck](https://github.com/LlemonDuck) and [insizhen](https://github.com/insizhen) for their valuable code contributions.
53+
Thanks to [LlemonDuck](https://github.com/LlemonDuck) and [insizhen](https://github.com/insizhen) for their valuable code contributions.

src/main/java/com/compassCameraControl/CompassCameraControlConfig.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public interface CompassCameraControlConfig extends Config
1515
name = "Mode",
1616
position = 1,
1717
description = "Cycle: North -> South -> East -> West (default)<br/>" +
18-
"Snap to Closest: Snaps the camera to the nearest cardinal direction"
18+
"Snap to Closest: Snaps the camera to the nearest cardinal direction<br/>" +
19+
"Snap to Facing: Snaps the camera to the player's facing direction"
1920
)
2021
default ControlMode controlMode()
2122
{
@@ -58,11 +59,22 @@ default ShiftMode shiftClickMode()
5859
)
5960
String cardinalKeybindingSnap = "cardinalKeybindingSnap";
6061

62+
@ConfigItem(
63+
keyName = "snapFacingKey",
64+
name = "Snap Facing",
65+
description = "Snaps the camera to the player's facing direction on key press",
66+
position = 5,
67+
section = cardinalKeybindingSnap
68+
)
69+
default Keybind snapFacingKey() {
70+
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
71+
}
72+
6173
@ConfigItem(
6274
keyName = "snapCloseKey",
6375
name = "Snap to Closest",
6476
description = "Snaps the camera to the nearest cardinal direction on key press",
65-
position = 5,
77+
position = 6,
6678
section = cardinalKeybindingSnap
6779
)
6880
default Keybind snapCloseKey() {
@@ -73,7 +85,7 @@ default Keybind snapCloseKey() {
7385
keyName = "cycleCardinalKey",
7486
name = "Cycle Cardinal",
7587
description = "Cycles through cardinal directions on key press",
76-
position = 6,
88+
position = 7,
7789
section = cardinalKeybindingSnap
7890
)
7991
default Keybind cycleCardinalKey() {
@@ -84,7 +96,7 @@ default Keybind cycleCardinalKey() {
8496
keyName = "lookNorthKey",
8597
name = "Look North Key",
8698
description = "Face camera North on key press",
87-
position = 7,
99+
position = 8,
88100
section = cardinalKeybindingSnap
89101
)
90102
default Keybind lookNorthKey() {
@@ -95,7 +107,7 @@ default Keybind lookNorthKey() {
95107
keyName = "lookSouthKey",
96108
name = "Look South Key",
97109
description = "Face camera South on key press",
98-
position = 8,
110+
position = 9,
99111
section = cardinalKeybindingSnap
100112
)
101113
default Keybind lookSouthKey() {
@@ -106,7 +118,7 @@ default Keybind lookSouthKey() {
106118
keyName = "lookEastKey",
107119
name = "Look East Key",
108120
description = "Face camera East on key press",
109-
position = 9,
121+
position = 10,
110122
section = cardinalKeybindingSnap
111123
)
112124
default Keybind lookEastKey() {
@@ -117,7 +129,7 @@ default Keybind lookEastKey() {
117129
keyName = "lookWestKey",
118130
name = "Look West Key",
119131
description = "Face camera West on key press",
120-
position = 10,
132+
position = 11,
121133
section = cardinalKeybindingSnap
122134
)
123135
default Keybind lookWestKey() {

src/main/java/com/compassCameraControl/CompassCameraControlPlugin.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ public class CompassCameraControlPlugin extends Plugin
3838

3939

4040
private static final int NORTH_YAW = 0;
41+
private static final int NORTHWEST_YAW = 256;
42+
private static final int WEST_YAW = 512;
43+
private static final int SOUTHWEST_YAW = 768;
4144
private static final int SOUTH_YAW = 1024;
45+
private static final int SOUTHEAST_YAW= 1280;
4246
private static final int EAST_YAW = 1536;
43-
private static final int WEST_YAW = 512;
47+
private static final int NORTHEAST_YAW = 1792;
4448

4549
private static final Map<Character, Integer> directionMap = Map.of(
4650
'N', NORTH_YAW,
@@ -49,6 +53,7 @@ public class CompassCameraControlPlugin extends Plugin
4953
'W', WEST_YAW
5054
);
5155

56+
private static final String SNAP_FACING = "Snap Facing";
5257
private static final String SNAP_CARDINAL = "Snap Cardinal";
5358
private static final String CYCLE_CARDINAL = "Cycle Cardinal";
5459

@@ -66,6 +71,10 @@ public void onMenuEntryAdded(MenuEntryAdded event)
6671
String newOption;
6772
switch (config.controlMode())
6873
{
74+
case SNAP_TO_FACING:
75+
newOption = SNAP_FACING;
76+
break;
77+
6978
case SNAP_TO_CLOSEST:
7079
newOption = SNAP_CARDINAL;
7180
break;
@@ -88,6 +97,11 @@ public void onCompassAction(MenuEntry event)
8897
{
8998
switch (event.getOption())
9099
{
100+
case SNAP_FACING:
101+
facingYaw();
102+
client.playSoundEffect(SoundEffectID.UI_BOOP);
103+
break;
104+
91105
case SNAP_CARDINAL:
92106
alignYaw();
93107
client.playSoundEffect(SoundEffectID.UI_BOOP);
@@ -188,6 +202,21 @@ private void alignYaw()
188202
client.setCameraYawTarget(closestYaw);
189203
}
190204

205+
private void facingYaw()
206+
{
207+
if (client.getLocalPlayer() == null)
208+
{
209+
return;
210+
}
211+
212+
int playerOrientation = client.getLocalPlayer().getOrientation();
213+
int direction = playerOrientation / 256;
214+
215+
int[] yaws = {SOUTH_YAW, SOUTHWEST_YAW, WEST_YAW, NORTHWEST_YAW, NORTH_YAW, NORTHEAST_YAW, EAST_YAW, SOUTHEAST_YAW};
216+
217+
client.setCameraYawTarget(yaws[direction]);
218+
}
219+
191220
private final KeyListener keyListener = new KeyListener() {
192221
@Override
193222
public void keyTyped(KeyEvent event) { }
@@ -198,8 +227,9 @@ public void keyReleased(KeyEvent event) { }
198227
@Override
199228
public void keyPressed(KeyEvent event) {
200229
boolean handledEvent = true;
201-
202-
if (config.snapCloseKey().matches(event)) {
230+
if (config.snapFacingKey().matches(event)) {
231+
facingYaw();
232+
} else if (config.snapCloseKey().matches(event)) {
203233
alignYaw();
204234
} else if (config.cycleCardinalKey().matches(event)) {
205235
cycleYaw();

src/main/java/com/compassCameraControl/ControlMode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum ControlMode
88

99
CYCLE("Cycle"),
1010
SNAP_TO_CLOSEST("Snap to Closest"),
11+
SNAP_TO_FACING("Snap to Facing"),
1112
;
1213

1314
private final String name;

0 commit comments

Comments
 (0)