Skip to content

Commit

Permalink
Fix fileHash null typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruptein committed Dec 29, 2024
1 parent 01cb82e commit ef815ba
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions client/src/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface ApiAsset {
id: AssetId;
name: string;
owner: string;
fileHash?: string;
children?: ApiAsset[];
fileHash: string | null;
children: ApiAsset[] | null;
shares: ApiAssetShare[];
}
export interface ApiAssetShare {
Expand Down
4 changes: 2 additions & 2 deletions client/src/assets/ui/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function onDrop(event: DragEvent): Promise<void> {
}
}

function startDrag(event: DragEvent, file: AssetId, assetHash?: string): void {
function startDrag(event: DragEvent, file: AssetId, assetHash: string | null): void {
if (event.dataTransfer === null) return;
if (!canEdit(file, false)) {
return;
Expand Down Expand Up @@ -148,7 +148,7 @@ async function stopDrag(event: DragEvent, target: AssetId): Promise<void> {

export interface DragComposable {
dragState: Ref<number>;
startDrag: (event: DragEvent, file: AssetId, fileHash?: string) => void;
startDrag: (event: DragEvent, file: AssetId, fileHash: string | null) => void;
moveDrag: (event: DragEvent) => void;
leaveDrag: (event: DragEvent) => void;
onDragEnd: (event: DragEvent) => void;
Expand Down
2 changes: 1 addition & 1 deletion client/src/dashboard/games/CreateGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function create(): Promise<void> {
async function setLogo(): Promise<void> {
const data = await modals.assetPicker();
if (data === undefined || data.fileHash === undefined) return;
if (data === undefined || data.fileHash === null) return;
logo.path = data.fileHash;
logo.id = data.id;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/dashboard/games/GameList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function setLogo(): Promise<void> {
logo: data.id,
});
if (success.ok) {
state.focussed.logo = data.fileHash;
state.focussed.logo = data.fileHash ?? undefined;
}
}
Expand Down
3 changes: 1 addition & 2 deletions client/src/game/dropAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export async function handleDropEvent(event: DragEvent): Promise<void> {
// External files are dropped
if (!transferInfo && event.dataTransfer.files.length > 0) {
for (const asset of await assetSystem.upload(event.dataTransfer.files, { target: () => assetState.raw.root })) {
if (asset.fileHash !== undefined)
await dropHelper({ assetHash: asset.fileHash, assetId: asset.id }, location);
if (asset.fileHash !== null) await dropHelper({ assetHash: asset.fileHash, assetId: asset.id }, location);
}
} else if (transferInfo) {
const assetInfo = JSON.parse(transferInfo) as {
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/ui/settings/floor/PatternSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const backgroundPattern = computed(() => getPattern(props.pattern) ?? defaultPat
async function setPatternImage(): Promise<void> {
const data = await modals.assetPicker();
if (data === undefined || data.fileHash === undefined) return;
if (data === undefined || data.fileHash === null) return;
emit("update:pattern", patternToString({ ...backgroundPattern.value, hash: data.fileHash }));
}
Expand Down
22 changes: 14 additions & 8 deletions client/src/game/ui/settings/shape/ExtraSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const showSvgSection = computed(() => gameState.reactive.isDm && activeShapeStor
async function uploadSvg(): Promise<void> {
const asset = await modals.assetPicker();
if (asset === undefined || asset.fileHash === undefined) return;
if (asset === undefined || asset.fileHash === null) return;
const shape = getShape(activeShapeStore.state.id!);
if (shape === undefined) return;
Expand Down Expand Up @@ -165,18 +165,24 @@ function applyDDraft(): void {
<template>
<div class="panel restore-panel">
<template v-if="showSvgSection">
<div class="spanrow header">{{ t('game.ui.selection.edit_dialog.extra.lighting_vision') }}</div>
<div class="spanrow header">{{ t("game.ui.selection.edit_dialog.extra.lighting_vision") }}</div>
<template v-if="!hasPath">
<label for="edit_dialog-extra-upload_walls">{{ t('game.ui.selection.edit_dialog.extra.upload_walls') }} (svg)</label>
<button id="edit_dialog-extra-upload_walls" @click="uploadSvg">{{ t('common.upload') }}</button>
<label for="edit_dialog-extra-upload_walls">
{{ t("game.ui.selection.edit_dialog.extra.upload_walls") }} (svg)
</label>
<button id="edit_dialog-extra-upload_walls" @click="uploadSvg">{{ t("common.upload") }}</button>
</template>
<template v-else>
<label for="edit_dialog-extra-upload_walls">{{ t('game.ui.selection.edit_dialog.extra.remove_walls') }} (svg)</label>
<button id="edit_dialog-extra-upload_walls" @click="removeSvg">{{ t('common.remove') }}</button>
<label for="edit_dialog-extra-upload_walls">
{{ t("game.ui.selection.edit_dialog.extra.remove_walls") }} (svg)
</label>
<button id="edit_dialog-extra-upload_walls" @click="removeSvg">{{ t("common.remove") }}</button>
</template>
<template v-if="hasDDraftInfo">
<label for="edit_dialog-extra-upload_walls">{{ t('game.ui.selection.edit_dialog.extra.apply_draft_info') }}</label>
<button id="edit_dialog-extra-upload_walls" @click="applyDDraft">{{ t('common.apply') }}</button>
<label for="edit_dialog-extra-upload_walls">
{{ t("game.ui.selection.edit_dialog.extra.apply_draft_info") }}
</label>
<button id="edit_dialog-extra-upload_walls" @click="applyDDraft">{{ t("common.apply") }}</button>
</template>
</template>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/ui/settings/shape/PropertySettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function changeAsset(): Promise<void> {
if (!owned.value) return;
if (activeShapeStore.state.id === undefined) return;
const data = await modals.assetPicker();
if (data === undefined || data.fileHash === undefined) return;
if (data === undefined || data.fileHash === null) return;
const shape = getShape(activeShapeStore.state.id);
if (shape === undefined || shape.type !== "assetrect") return;
(shape as Asset).setImage(getImageSrcFromHash(data.fileHash, { addBaseUrl: false }), true);
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/ui/settings/shape/VariantSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function addVariant(): Promise<void> {
const shape = getShape(vState.id!)!;
if (asset.fileHash === undefined) {
if (asset.fileHash === null) {
console.error("Missing fileHash for new variant");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion server/generate_types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sed -i 's/"VisionBlock"/VisionBlock/g' ../client/src/apiTypes.ts
sed -i 's/"GridModeLabelFormat"/GridModeLabelFormat/g' ../client/src/apiTypes.ts
sed -i '1s/^/'\
'import type { AssetId } from ".\/assets\/models";\n'\
'import type { GlobalId } from ".\/game\/id";\n'\
'import type { GlobalId } from ".\/core\/id";\n'\
'import type { LayerName } from ".\/game\/models\/floor";\n'\
'import type { Role } from ".\/game\/models\/role";\n'\
'import type { AuraId } from ".\/game\/systems\/auras\/models";\n'\
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/models/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class ApiAsset(TypeIdModel):
# The name of the asset can be shown differently depending on sharing state
name: str
owner: str
fileHash: str | None
fileHash: str | None = Field(..., noneAsNull=True)
# If specified, this provides the list of children for this asset
# This should only be provided for folders (i.e. assets without a fileHash)
# And is only provided in specific calls
children: list["ApiAsset"] | None
children: list["ApiAsset"] | None = Field(..., noneAsNull=True)
shares: list[ApiAssetShare] # Info on users that this specific asset is shared with


Expand Down

0 comments on commit ef815ba

Please sign in to comment.