Skip to content

Commit a0fa7b1

Browse files
authored
Merge pull request #165 from runejs/walkpath-debug
feat: create `walkpath` debug command
2 parents bd51320 + c00a584 commit a0fa7b1

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

src/main/java/org/runejs/client/Main.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.runejs.client.cache.CacheArchive;
55
import org.runejs.client.cache.CacheFileChannel;
66
import org.runejs.client.frame.ChatBox;
7+
import org.runejs.client.frame.DebugTools;
78
import org.runejs.client.frame.ScreenController;
89
import org.runejs.client.frame.ScreenMode;
910
import org.runejs.client.frame.console.Console;
@@ -872,6 +873,8 @@ public static void method353() {
872873
((Class35) Rasterizer3D.interface3).animateTextures(MovedStatics.anInt199);
873874
KeyFocusListener.draw3dScreen();
874875

876+
DebugTools.drawWalkPath();
877+
875878
if(ScreenController.frameMode == ScreenMode.FIXED) {
876879
Console.console.drawConsole(512, 334);
877880
Console.console.drawConsoleArea(512, 334);

src/main/java/org/runejs/client/SpotAnim.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.runejs.client.cache.media.AnimationSequence;
44
import org.runejs.client.cache.def.SpotAnimDefinition;
5+
import org.runejs.client.frame.DebugTools;
56
import org.runejs.client.media.VertexNormal;
67
import org.runejs.client.media.renderable.Model;
78
import org.runejs.client.media.renderable.Renderable;
@@ -59,8 +60,12 @@ else if(lightness > 126)
5960
}
6061

6162
public static void renderPlayers(int arg0, boolean arg1) {
62-
if(Player.localPlayer.worldX >> 7 == MovedStatics.destinationX && Player.localPlayer.worldY >> 7 == Class55.destinationY)
63+
if(Player.localPlayer.worldX >> 7 == MovedStatics.destinationX && Player.localPlayer.worldY >> 7 == Class55.destinationY) {
6364
MovedStatics.destinationX = 0;
65+
66+
DebugTools.walkpathX = null;
67+
DebugTools.walkpathY = null;
68+
}
6469
int i = Player.localPlayerCount;
6570
if(arg1)
6671
i = 1;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.runejs.client.frame;
2+
3+
import org.runejs.client.MovedStatics;
4+
import org.runejs.client.media.Rasterizer;
5+
import org.runejs.client.scene.Point2d;
6+
7+
public class DebugTools {
8+
public static boolean walkpathEnabled = false;
9+
public static int[] walkpathX = null;
10+
public static int[] walkpathY = null;
11+
12+
public static void drawWalkPath() {
13+
if (!walkpathEnabled || walkpathX == null) {
14+
return;
15+
}
16+
17+
int lastTileX = walkpathX[0];
18+
int lastTileY = walkpathY[0];
19+
20+
Point2d pathStartPos = MovedStatics.getProjectedScreenPosition(10, lastTileY * 128 + 64, lastTileX * 128 + 64);
21+
Point2d pathFinishPos = MovedStatics.getProjectedScreenPosition(10, walkpathY[walkpathY.length - 1] * 128 + 64, walkpathX[walkpathX.length - 1] * 128 + 64);
22+
23+
Point2d lastTilePos = pathStartPos;
24+
for (int i = 1; i < walkpathX.length; i++) {
25+
int tileX = walkpathX[i];
26+
int tileY = walkpathY[i];
27+
28+
Point2d nextPos = MovedStatics.getProjectedScreenPosition(10, tileY * 128 + 64, tileX * 128 + 64);
29+
30+
if (lastTilePos != null && nextPos != null) {
31+
Rasterizer.drawDiagonalLine(lastTilePos.x, lastTilePos.y, nextPos.x, nextPos.y, 0x00FFAC);
32+
}
33+
34+
lastTileX = tileX;
35+
lastTileY = tileY;
36+
lastTilePos = nextPos;
37+
}
38+
39+
if (pathStartPos != null) {
40+
Rasterizer.drawCircle(pathStartPos.x, pathStartPos.y, 2, 0xE055DE);
41+
}
42+
43+
if (pathFinishPos != null) {
44+
Rasterizer.drawCircle(pathFinishPos.x, pathFinishPos.y, 4, 0xE055DE);
45+
}
46+
}
47+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.runejs.client.frame.console.Commands;
2+
3+
import org.runejs.client.frame.DebugTools;
4+
import org.runejs.client.frame.console.Command;
5+
import org.runejs.client.frame.console.Console;
6+
7+
public class DebugWalkCommand extends Command {
8+
public DebugWalkCommand() {
9+
super(new String[]{"debugwalk"}, "Toggles debug walkpath");
10+
}
11+
12+
@Override
13+
public void execute(Console console, String[] cmdInput) {
14+
DebugTools.walkpathEnabled = !DebugTools.walkpathEnabled;
15+
if(DebugTools.walkpathEnabled) {
16+
console.log("<col=00FF00>Walkpath is now drawn</col>");
17+
} else {
18+
console.log("<col=FF0000>Walkpath is now hidden</col>");
19+
}
20+
}
21+
}

src/main/java/org/runejs/client/frame/console/Console.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private void initialiseCommands() {
6262
commands.add(new ClearCommand());
6363
commands.add(new DebugCommand());
6464
commands.add(new DebugViewCommand());
65+
commands.add(new DebugWalkCommand());
6566
commands.add(new DebugWidgetsCommand());
6667
commands.add(new EchoCommand());
6768
commands.add(new PlayerRightsCommand());

src/main/java/org/runejs/client/media/renderable/actor/Pathfinding.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.runejs.client.media.renderable.actor;
22

3+
import org.runejs.client.frame.DebugTools;
34
import org.runejs.client.media.renderable.Item;
45
import org.runejs.client.message.outbound.WalkOutboundMessage;
56
import org.runejs.client.net.OutgoingPackets;
@@ -249,6 +250,16 @@ else if((waypoint & 0b1000) != 0)
249250
int x = walkingQueueX[currentIndex];
250251
int y = walkingQueueY[currentIndex];
251252

253+
if (DebugTools.walkpathEnabled) {
254+
DebugTools.walkpathX = new int[maxPathSize + 1];
255+
DebugTools.walkpathY = new int[maxPathSize + 1];
256+
257+
DebugTools.walkpathX[0] = startX;
258+
DebugTools.walkpathY[0] = startY;
259+
DebugTools.walkpathX[1] = x;
260+
DebugTools.walkpathY[1] = y;
261+
}
262+
252263
WalkOutboundMessage.WalkType walkType = WalkOutboundMessage.WalkType.TILE;
253264

254265
if(clickType == 0) {
@@ -267,6 +278,11 @@ else if(clickType == 2) {
267278
int stepX = walkingQueueX[currentIndex] - x;
268279
int stepY = walkingQueueY[currentIndex] - y;
269280

281+
if (DebugTools.walkpathEnabled) {
282+
DebugTools.walkpathX[counter + 1] = walkingQueueX[currentIndex];
283+
DebugTools.walkpathY[counter + 1] = walkingQueueY[currentIndex];
284+
}
285+
270286
steps.add(new WalkOutboundMessage.WalkStep(stepX, stepY));
271287
}
272288

0 commit comments

Comments
 (0)