Slim skins
This commit is contained in:
@@ -1022,15 +1022,28 @@ export class GameServer {
|
||||
|
||||
register(
|
||||
literal<ServerCommandSource>("skin")
|
||||
.describe("Changes your skin to a 64x64 png from the web, or back to the default without a url")
|
||||
.describe(
|
||||
"Changes your skin to a 64x64 png from the web, slim for 3 pixel wide arms. " +
|
||||
"Back to the default without a url",
|
||||
)
|
||||
.executes((context) => {
|
||||
this.set_skin(context.source.server_player, undefined);
|
||||
this.set_skin(context.source.server_player, undefined, false);
|
||||
context.source.send_message("Your skin is back to the default");
|
||||
})
|
||||
.then(
|
||||
argument<string, ServerCommandSource>("url", word())
|
||||
.executes((context) =>
|
||||
this.#download_skin(context.source.server_player, context.get<string>("url"))
|
||||
this.#download_skin(context.source.server_player, context.get<string>("url"), false)
|
||||
)
|
||||
.then(
|
||||
argument<string, ServerCommandSource>("model", choice(["slim", "normal"]))
|
||||
.executes((context) =>
|
||||
this.#download_skin(
|
||||
context.source.server_player,
|
||||
context.get<string>("url"),
|
||||
context.get<string>("model") === "slim",
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1063,15 +1076,17 @@ export class GameServer {
|
||||
);
|
||||
}
|
||||
|
||||
// a base64 png, or undefined for the default skin. everyone is told, the player too
|
||||
set_skin(player: ServerPlayer, skin: string | undefined) {
|
||||
// a base64 png, or undefined for the default skin, and whether it's for the slim model. everyone is told, the
|
||||
// player too
|
||||
set_skin(player: ServerPlayer, skin: string | undefined, slim: boolean) {
|
||||
player.skin = skin;
|
||||
player.slim = slim;
|
||||
this.world.dirty = true;
|
||||
this.#broadcast({ type: "player_skin", id: player.id, skin });
|
||||
this.#broadcast({ type: "player_skin", id: player.id, skin, slim: slim || undefined });
|
||||
}
|
||||
|
||||
// the host downloads it, which takes a while, so the player hears back later
|
||||
#download_skin(player: ServerPlayer, url: string) {
|
||||
#download_skin(player: ServerPlayer, url: string, slim: boolean) {
|
||||
if (player.downloading_skin) {
|
||||
throw new CommandError("Your last skin is still downloading");
|
||||
}
|
||||
@@ -1086,7 +1101,7 @@ export class GameServer {
|
||||
throw new Error(problem);
|
||||
}
|
||||
if (online()) {
|
||||
this.set_skin(player, encode_skin(bytes));
|
||||
this.set_skin(player, encode_skin(bytes), slim);
|
||||
this.send_chat(player, "Skin changed");
|
||||
}
|
||||
})
|
||||
|
||||
@@ -31,6 +31,7 @@ export interface SavedPlayer {
|
||||
vitals?: SavedVitals;
|
||||
// base64 png, see /skin
|
||||
skin?: string;
|
||||
slim?: boolean;
|
||||
}
|
||||
|
||||
export class ServerPlayer {
|
||||
@@ -56,6 +57,8 @@ export class ServerPlayer {
|
||||
screen: OpenScreen | undefined;
|
||||
// base64 png, see /skin. undefined is the default skin
|
||||
skin: string | undefined;
|
||||
// the skin is for the model with 3 pixel wide arms
|
||||
slim = false;
|
||||
// a /skin download is on its way, one at a time
|
||||
downloading_skin = false;
|
||||
|
||||
@@ -81,6 +84,7 @@ export class ServerPlayer {
|
||||
yaw: this.yaw,
|
||||
pitch: this.pitch,
|
||||
skin: this.skin,
|
||||
slim: this.slim || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,6 +99,7 @@ export class ServerPlayer {
|
||||
inventory: this.inventory.to_data(),
|
||||
vitals: this.vitals.save(),
|
||||
skin: this.skin,
|
||||
slim: this.slim || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -108,5 +113,6 @@ export class ServerPlayer {
|
||||
this.inventory.load(saved.inventory);
|
||||
this.vitals.load(saved.vitals);
|
||||
this.skin = saved.skin;
|
||||
this.slim = saved.slim ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user