Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements to webmap #78

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies {
tasks {
reobfJar {
dependsOn(shadowJar)

outputJar.set(jar.get().archiveFile)
}

// needed for below jank
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) {
level.getSeed(),
Point.of(level.getLevelData().getSpawnPos().getX(), level.getLevelData().getSpawnPos().getZ()),
Type.get(level.dimension().location().toString()),
level.convertable.getDimensionPath(level.dimension()).resolve("region")
level.levelStorageAccess.getDimensionPath(level.dimension()).resolve("region")
);
this.level = level;

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/net/pl3x/map/core/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ private ByteUtil() {
}

public static byte[] toBytes(int packed) {
byte[] bytes = new byte[4];
for (int i = 0; i < 4; i++) {
bytes[i] = (byte) (packed >>> (i * 8));
byte[] bytes = new byte[Integer.BYTES];
for (int i = 0; i < Integer.BYTES; i++) {
bytes[i] = (byte) (packed >>> (Byte.SIZE * (Integer.BYTES - 1 - i)));
}
return bytes;
}

public static int getInt(@NotNull ByteBuffer buffer, int index) {
int value = 0;
for (int i = 0; i < 4; i++) {
value |= (buffer.get(index + i) & 0xFF) << (i * 8);
for (int i = 0; i < Integer.BYTES; i++) {
value |= (buffer.get(index + i) & 0xFF) << (Byte.SIZE * (Integer.BYTES - 1 - i));
}
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabricLoom="1.9-SNAPSHOT"
#forgeLoader="[48,)"

minotaur="2.+" # https://github.com/modrinth/minotaur
paperweight="1.7.6" # https://github.com/PaperMC/Paperweight
paperweight="2.0.0-beta.8" # https://github.com/PaperMC/Paperweight
indra-git="3.1.3" # https://github.com/KyoriPowered/indra
shadowJar="8.3.5" # https://github.com/GradleUp/shadow

Expand Down
7 changes: 7 additions & 0 deletions webmap/src/Pl3xMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export class Pl3xMap {
}
});

// update map size when window size, scale, or orientation changes
'orientationchange resize'.split(' ').forEach((event: string): void => {
window.addEventListener(event, (): void => {
this._map.updateSizeToWindow();
}, {passive: true});
});

this._controlManager = new ControlManager(this);
this._playerManager = new PlayerManager(this);
this._worldManager = new WorldManager(this);
Expand Down
16 changes: 16 additions & 0 deletions webmap/src/map/Pl3xMapLeafletMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export default class Pl3xMapLeafletMap extends L.Map {
this.attributionControl.setPrefix("<a href='https://modrinth.com/plugin/pl3xmap/'>Pl3xMap &copy; 2020-2023</a>");

this._pl3xmap = pl3xmap;

// stuff to do after the map fully loads
this.on('load', (): void => this.onLoad());
}

onLoad(): void {
// fix map size on load - fixes android browser url bar pushing page off-screen
// https://chanind.github.io/javascript/2019/09/28/avoid-100vh-on-mobile-web.html
this.updateSizeToWindow();
}

// https://stackoverflow.com/a/60391674/3530727
Expand Down Expand Up @@ -72,4 +81,11 @@ export default class Pl3xMapLeafletMap extends L.Map {
public getCurrentZoom(): number {
return this.getMaxZoomOut() - this.getZoom();
}

public updateSizeToWindow(): void {
const style: CSSStyleDeclaration = this.getContainer().style;
style.width = `${window.innerWidth}px`;
style.height = `${window.innerHeight}px`;
this.invalidateSize();
}
}
7 changes: 5 additions & 2 deletions webmap/src/palette/BlockInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Block} from "./Block";

export class BlockInfo {
public readonly BYTE_SIZE: number = 8;
public readonly INTEGER_BYTES: number = 4;

private readonly _data: Uint8Array;

constructor(data: Uint8Array) {
Expand All @@ -17,8 +20,8 @@ export class BlockInfo {

private getInt(position: number): number {
let val: number = 0;
for (let i: number = 0; i < 4; i++) {
val |= (this._data[position + i] & 0xFF) << (i * 8);
for (let i: number = 0; i < this.INTEGER_BYTES; i++) {
val |= (this._data[position + i] & 0xFF) << (this.BYTE_SIZE * ((this.INTEGER_BYTES - 1) - i));
}
return val;
}
Expand Down
Loading