Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Oct 31, 2024
1 parent 5bec93a commit e283447
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 59 deletions.
Binary file removed examples/example-vite-svelte-recs/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/example-vite-svelte-recs/dojoConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import manifest from "../manifests/dev/deployment/manifest.json";
import manifest from "../../worlds/dojo-starter/manifests/dev/deployment/manifest.json";

import { createDojoConfig } from "@dojoengine/core";

Expand Down
2 changes: 1 addition & 1 deletion examples/example-vite-svelte-recs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte + TS</title>
<title>Vite + Svelte + TS + Dojo</title>
</head>
<body>
<div id="app"></div>
Expand Down
71 changes: 45 additions & 26 deletions examples/example-vite-svelte-recs/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
<script lang="ts">
import type { Entity } from "@dojoengine/recs";
import { componentValueStore, type ComponentStore } from "./dojo/componentValueStore";
import {
componentValueStore,
type ComponentStore,
} from "./dojo/componentValueStore";
import { dojoStore, accountStore, burnerStore } from "./stores";
import { Account } from "starknet";
import { type Burner } from "@dojoengine/create-burner";
import { handleBurnerChange, handleNewBurner, handleClearBurners } from "./handlers";
import {
handleBurnerChange,
handleNewBurner,
handleClearBurners,
} from "./handlers";
let entityId: Entity;
let account: Account;
let position: ComponentStore;
let moves: ComponentStore;
let burners: Burner[]
$: ({ clientComponents, torii, burnerManager, client } = $dojoStore);
$: if ($accountStore) account = $accountStore;
let burners: Burner[];
$: if (torii && account) entityId = torii.poseidonHash([account.address])
$: ({ clientComponents, torii, burnerManager, client } = $dojoStore);
$: if ($accountStore) account = $accountStore;
$: if (dojoStore) position = componentValueStore(clientComponents.Position, entityId);
$: if (dojoStore) moves = componentValueStore(clientComponents.Moves, entityId);
$: if ($burnerStore) burners = $burnerStore
$: if (torii && account)
entityId = torii.poseidonHash([account.address]) as Entity;
$: if (dojoStore)
position = componentValueStore(clientComponents.Position, entityId);
$: if (dojoStore)
moves = componentValueStore(clientComponents.Moves, entityId);
$: if ($burnerStore) burners = $burnerStore;
</script>

<main>
Expand All @@ -40,21 +49,20 @@
select signer:{" "}
<select on:change={handleBurnerChange}>
{#each burners as burner}
<option value={burner.address}>
{burner.address}
</option>
<option value={burner.address}>
{burner.address}
</option>
{/each}
</select>
</div>
<div>
<button on:click={handleClearBurners}>
Clear burners
</button>
<button on:click={handleClearBurners}> Clear burners </button>
</div>
</div>

<div class="card">
<button on:click={() => client.actions.spawn({account})}>Spawn</button>
<button on:click={() => client.actions.spawn({ account })}>Spawn</button
>
<div>
Moves Left: {moves ? `${$moves?.remaining}` : "Need to Spawn"}
</div>
Expand All @@ -66,17 +74,18 @@
</div>

<div>{$moves && $moves.last_direction}</div>

</div>

<div class="card">
<div>
<button
on:click={() =>
position && $position.vec.y > 0
? client.actions.move({account, direction:{ type: "Up" }})
: console.log("Reach the borders of the world.")
}
? client.actions.move({
account,
direction: { type: "Up" },
})
: console.log("Reach the borders of the world.")}
>
Move Up
</button>
Expand All @@ -85,21 +94,31 @@
<button
on:click={() =>
position && $position.vec.x > 0
? client.actions.move({account, direction: { type: "Left" }})
: console.log("Reach the borders of the world.")
}
? client.actions.move({
account,
direction: { type: "Left" },
})
: console.log("Reach the borders of the world.")}
>
Move Left
</button>
<button
on:click={() => client.actions.move({account, direction: { type: "Right" }})}
on:click={() =>
client.actions.move({
account,
direction: { type: "Right" },
})}
>
Move Right
</button>
</div>
<div>
<button
on:click={() => client.actions.move({account, direction: { type: "Down" }})}
on:click={() =>
client.actions.move({
account,
direction: { type: "Down" },
})}
>
Move Down
</button>
Expand Down
4 changes: 2 additions & 2 deletions examples/example-vite-svelte-recs/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export function handleBurnerChange(event: Event) {
accountStore.set(burnerManager.getActiveAccount());
}

export async function handleNewBurner(event: Event) {
export async function handleNewBurner() {
burnerManager = get(dojoStore).burnerManager;
await burnerManager.create();
burnerStore.set(burnerManager.list());
accountStore.set(burnerManager.getActiveAccount());
}

export function handleClearBurners(event: Event) {
export function handleClearBurners() {
burnerManager = get(dojoStore).burnerManager;
burnerManager.clear();
burnerStore.set(burnerManager.list());
Expand Down
4 changes: 1 addition & 3 deletions examples/example-vite-svelte-recs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { setup } from "./dojo/setup";
import { dojoConfig } from "../dojoConfig";
import { accountStore, burnerStore, dojoStore } from "./stores";

// Create a writable store for the setup result

async function initApp() {
// Update the store with the setup result
// Set up dojo
let setupRes = await setup(dojoConfig);
dojoStore.set(setupRes);
burnerStore.set(setupRes.burnerManager.list());
Expand Down
2 changes: 1 addition & 1 deletion examples/example-vite-svelte-recs/src/stores.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable, derived } from "svelte/store";
import { writable } from "svelte/store";
import { type SetupResult } from "./dojo/setup";
import { Account } from "starknet";
import { type Burner } from "@dojoengine/create-burner";
Expand Down
Loading

0 comments on commit e283447

Please sign in to comment.