Skip to content

Commit

Permalink
Merge pull request #50 from TibiNonEst/bust
Browse files Browse the repository at this point in the history
Add bust rendering
  • Loading branch information
astei authored Mar 21, 2022
2 parents de7931b + 4931a5f commit 879ac58
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum RenderType {
Helm,
Cube,
Body,
Bust,
Cape,
}

Expand All @@ -44,6 +45,9 @@ impl RenderType {
RenderType::Cube => img.render_cube(true, size),
RenderType::Body => img.render_body(options)
.resize(size, size * 2, image::imageops::FilterType::Nearest),
RenderType::Bust => img.render_body(options)
.crop(0, 0, 16, 16)
.resize(size, size, image::imageops::FilterType::Nearest),
RenderType::Cape => img.get_cape()
.resize(size, size, image::imageops::FilterType::Nearest),
}
Expand All @@ -56,6 +60,7 @@ fn what_to_render_type(what: String) -> Option<RenderType> {
"helm" => Some(RenderType::Helm),
"cube" => Some(RenderType::Cube),
"body" => Some(RenderType::Body),
"bust" => Some(RenderType::Bust),
"cape" => Some(RenderType::Cape),
_ => None
}
Expand Down
14 changes: 14 additions & 0 deletions website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ <h3>Fetch a player's body</h3>
</code>
<img src="/armor/body/Reply/32" class="render-pixelate" alt="Default example" width="32" height="64">
</div>

<h3>Fetch a player's bust</h3>
<div class="example">
<code>
GET https://crafthead.net/bust/6a085b2c19fb4986b453231aa942bbec
</code>
<img src="/bust/6a085b2c19fb4986b453231aa942bbec/32" class="render-pixelate" alt="Default example" width="32" height="32">
</div>
<div class="example">
<code>
GET https://crafthead.net/armor/bust/Reply
</code>
<img src="/armor/bust/Reply/32" class="render-pixelate" alt="Default example" width="32" height="32">
</div>

<h3>Fetch a player's skin</h3>
<div class="example">
Expand Down
6 changes: 5 additions & 1 deletion worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ async function processRequest(skinService: MojangRequestService, interpreted: Cr
case RequestedKind.Avatar:
case RequestedKind.Helm:
case RequestedKind.Cube:
case RequestedKind.Body: {
case RequestedKind.Body:
case RequestedKind.Bust: {
const skin = await skinService.retrieveSkin(interpreted, gatherer);
return renderImage(skin, interpreted);
}
Expand Down Expand Up @@ -144,6 +145,9 @@ async function renderImage(skin: Response, request: CraftheadRequest): Promise<R
case RequestedKind.Body:
which = "body";
break;
case RequestedKind.Bust:
which = "bust";
break;
case RequestedKind.Cape:
which = "cape";
break;
Expand Down
5 changes: 4 additions & 1 deletion worker/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum RequestedKind {
Helm,
Cube,
Body,
Bust,
Cape,
Profile
}
Expand Down Expand Up @@ -40,6 +41,8 @@ function stringKindToRequestedKind(kind: string): RequestedKind | null {
return RequestedKind.Helm;
case "body":
return RequestedKind.Body;
case "bust":
return RequestedKind.Bust;
case "cape":
return RequestedKind.Cape;
case "profile":
Expand All @@ -58,7 +61,7 @@ export function interpretRequest(request: Request): CraftheadRequest | null {
let armored = false
let sliceAmt = 1

if (url.pathname.includes("armor/body")) {
if (url.pathname.includes("armor/body") || url.pathname.includes("armor/bust")) {
armored = true
sliceAmt = 2
}
Expand Down
2 changes: 1 addition & 1 deletion worker/util/cache-bust.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default 4;
export default 5;

0 comments on commit 879ac58

Please sign in to comment.