Skip to content

Commit

Permalink
Added Chess and placeholders for Go and World
Browse files Browse the repository at this point in the history
  • Loading branch information
Zequez committed Nov 12, 2024
1 parent 6500d82 commit 65fe598
Show file tree
Hide file tree
Showing 10 changed files with 2,517 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ui/src/GameSpace/ConfigMenu/ConfigMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
export let onMoveZ: (z: 'top' | 'bottom' | 'up' | 'down') => void;
export let onRemoveEl: () => void;
export let onClose: () => void;
export let onDuplicate: () => void;
export let el: GElement;
export let gameSpace: GameSpaceSyn;
Expand Down Expand Up @@ -50,6 +51,8 @@
}
$: resolvedEl = { ...el, lock: resolvedLock } as any;
$: console.log(el.wals);
</script>

<div
Expand Down Expand Up @@ -94,4 +97,5 @@
onRemoveAttachment={handleRemoveAttachment}
locked={resolvedLock.wals}
/>
<button on:click={() => onDuplicate()}>Duplicate</button>
</div>
19 changes: 14 additions & 5 deletions ui/src/GameSpace/GameSpace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import SpaceConfigurator from './sidebar/SpaceConfigurator.svelte';
import ConfigMenu from './ConfigMenu';
import { tooltip } from '~/shared/tooltip';
import { cloneDeep } from 'lodash';
import { uuid } from '~/lib/util';
export let gameSpace: GameSpaceSyn;
export let asAsset: boolean = false;
Expand Down Expand Up @@ -67,13 +69,19 @@
function handleRemoveElement(id: string) {
gameSpace.change({ type: 'remove-element', uuid: id });
closeContextMenu();
}
// Handle closing the context menu if an item was deleted
$: {
if (contextMenuState && !$state.elements.find((e) => e.uuid === contextMenuState.id)) {
closeContextMenu();
}
function handleDuplicateElement(id: string) {
const el = $state.elements.find((el) => el.uuid === id);
if (!el) return;
const newEl = cloneDeep(el);
newEl.uuid = uuid();
newEl.x += 5;
newEl.y += 5;
console.log(newEl);
gameSpace.change({ type: 'add-element', element: newEl });
contextMenuState = { id: newEl.uuid, x: contextMenuState.x + 5, y: contextMenuState.y + 5 };
}
function handleAddElementFromLibrary(element: LibraryElement, x?: number, y?: number) {
Expand Down Expand Up @@ -186,6 +194,7 @@
onUpdateEl={handleUpdateElement}
onMoveZ={(z) => gameSpace.change({ type: 'move-z', uuid: contextMenuState.id, z })}
onRemoveEl={() => handleRemoveElement(contextMenuState.id)}
onDuplicate={() => handleDuplicateElement(contextMenuState.id)}
/>
{/if}
{/if}
13 changes: 9 additions & 4 deletions ui/src/HomePage2/GamesList.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { get, derived } from 'svelte/store';
import { zip } from 'lodash';
import { getContext, defaultSpaces } from '~/store';
import { getContext, presets } from '~/store';
import GamesListItem from './GamesListItem.svelte';
import DefaultGameItem from './DefaultGameItem.svelte';
Expand Down Expand Up @@ -30,9 +30,11 @@
.map(([gameSpace, _]) => gameSpace);
});
$: allNames = derived(gameDocsStates, ($states) => $states.map(($state) => $state.name));
$: allNames = derived(gameDocsStates, ($states) =>
$states.filter((s) => s).map(($state) => $state?.name),
);
$: unimportedGlobalLibrary = derived(allNames, ($names) => {
return Object.values(defaultSpaces).filter((space) => $names.indexOf(space.name) === -1);
return Object.values(presets).filter((space) => $names.indexOf(space.name) === -1);
});
</script>

Expand All @@ -46,7 +48,10 @@
{#if tag === 'library' && $unimportedGlobalLibrary.length > 0}
<h2 class="text-center py4 text-lg">Global library</h2>
{#each $unimportedGlobalLibrary as gameSpace (gameSpace.name)}
<DefaultGameItem {gameSpace} onImport={() => store.createGameSpace(gameSpace)} />
<DefaultGameItem
{gameSpace}
onImport={() => store.createGameSpace({ ...gameSpace, creator: store.pubKey })}
/>
{/each}
{/if}
</div>
2 changes: 2 additions & 0 deletions ui/src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
type EntryHash,
} from '@holochain/client';

export { v1 as uuid } from 'uuid';

export const hashEqual = (a: EntryHash, b: EntryHash): boolean => {
if (!a || !b) {
return !a && !b;
Expand Down
2 changes: 1 addition & 1 deletion ui/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { createRootStore, type RootStore, setContext, getContext } from './rootS
export { type GameSpaceSyn } from './gameSpaceStore';
export type { GameSpace, LockConfig, GElementBase, GElement } from './types';
export { type LibraryElement, createElement, LIBRARY } from './library';
export * as defaultSpaces from './defaultSpaces';
export * as presets from './presets';
Loading

0 comments on commit 65fe598

Please sign in to comment.