Skip to content

Commit

Permalink
Add page for setting an override by hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed May 7, 2024
1 parent 0d8d708 commit 1b8537d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/app/api/api-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ export class ApiClient {
});
}

public SetLevelHashAsOverride(hash: string): void {
this.apiRequestCreator.makeRequest("POST", `levels/hash/${hash}/setAsOverride`)
.subscribe(_ => {
this.bannerService.pushSuccess("Check your game!", `In LBP, head to 'Lucky Dip' (or any category) and that level will show up!`);
});
}

public UploadImageAsset(hash: string, data: ArrayBuffer): Observable<Asset> {
return this.apiRequestCreator.makeRequest("POST", `assets/${hash}`, data);
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {StatisticsComponent} from "./pages/statistics/statistics.component";
import {ContestsComponent} from "./pages/contests/contests.component";
import {ManageContestComponent} from "./pages/manage-contest/manage-contest.component";
import {ContestComponent} from "./pages/contest/contest.component";
import {PlayHashComponent} from "./pages/play-hash/play-hash.component";

const routes: Routes = [
{path: "", component: MainComponent},
Expand Down Expand Up @@ -85,6 +86,8 @@ const routes: Routes = [
{path: "contests", component: ContestsComponent},
{path: "contests/:id", component: ContestComponent},
{path: "contests/:id/manage", component: ManageContestComponent},

{path: "playhash", component: PlayHashComponent, canActivate: [authenticationGuard]},
];

if (isDevMode()) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import {MarkdownModule, MarkedOptions} from "ngx-markdown";
import {markedOptionsFactory} from "./markdown.config";
import {ContestPreviewComponent} from "./components/contest-preview/contest-preview.component";
import {ContestLabelComponent} from "./components/contest-label/contest-label.component";
import { PlayHashComponent } from './pages/play-hash/play-hash.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -177,6 +178,7 @@ import {ContestLabelComponent} from "./components/contest-label/contest-label.co
ContestBannerComponent,
ContestPreviewComponent,
ContestLabelComponent,
PlayHashComponent,
],
imports: [
BrowserModule,
Expand Down
6 changes: 3 additions & 3 deletions src/app/markdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function markedOptionsFactory(): MarkedOptions {
return `<h${level} class="font-bold text-${tailwindFontSize} mt-2.5">${text}</h${level}>`;
}

renderer.link = (href, title) => {
return `<a href="${href}" class="text-secondary-bright hover:underline">${title ?? href}</a>`;
renderer.link = (href, title, text) => {
return `<a href="${href}" class="text-secondary-bright hover:underline">${text}</a>`;
}

renderer.list = (body, ordered) => {
Expand All @@ -38,7 +38,7 @@ export function markedOptionsFactory(): MarkedOptions {
return {
renderer: renderer,
gfm: true,
breaks: true,
breaks: false,
pedantic: false,
};
}
40 changes: 40 additions & 0 deletions src/app/pages/play-hash/play-hash.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<page-header class="text-3xl">Play Level by Hash</page-header>
<div class="leading-tight">
<p>
This page helps players wanting to play levels from the Dry Archive
If you want to play a level from the archive, first head to
<a href="https://maticzpl.xyz/lbpfind/" class="text-secondary-bright font-bold">LBPFind</a>
to find a level you'd like to play.
</p>
<br/>
<p>
Once you've found a level, press <b>Info</b> to view the level's data. Copy the <b>Hash</b>.
</p>
<p>
It should look something like this hash: <code>50a197bfe47187c37c36f59ea9c038b1938fa9be</code>
</p>
<br/>
<p>
Next, paste that hash below.
</p>
<br/>

<form-input name="Level Hash" [icon]="faCertificate" [(value)]="levelHash"></form-input>

<br/>
<p>
And then, play!
</p>

<br/>
<div class="w-36">
<primary-button text="Play Now!" [icon]="faPlay" (click)="setAsOverride()"></primary-button>
</div>

<br/>
<p class="text-warning">
<fa-icon [icon]="faTriangleExclamation" class="mr-1"></fa-icon>
Note that this feature has no safety against accidents.
Don't put an invalid hash, or a hash for a future version of the game, otherwise you might crash.
</p>
</div>
25 changes: 25 additions & 0 deletions src/app/pages/play-hash/play-hash.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';
import {faCertificate, faPlay, faTriangleExclamation} from "@fortawesome/free-solid-svg-icons";
import {ApiClient} from "../../api/api-client.service";

@Component({
selector: 'app-play-hash',
templateUrl: './play-hash.component.html'
})
export class PlayHashComponent {
protected readonly faCertificate = faCertificate;
protected readonly faPlay = faPlay;

levelHash: string = "";

constructor(private api: ApiClient) {
}

setAsOverride() {
if(this.levelHash.length <= 0) return;

this.api.SetLevelHashAsOverride(this.levelHash);
}

protected readonly faTriangleExclamation = faTriangleExclamation;
}

0 comments on commit 1b8537d

Please sign in to comment.