Profectus/src/features/grids/Grid.vue

61 lines
1.9 KiB
Vue
Raw Normal View History

2021-06-11 23:38:16 -05:00
<template>
2022-01-13 22:25:47 -06:00
<div
v-if="isVisible(visibility)"
:style="{
visibility: isHidden(visibility) ? 'hidden' : undefined
}"
2022-12-10 19:33:24 +01:00
class="table-grid"
2022-01-13 22:25:47 -06:00
>
2022-12-10 19:33:24 +01:00
<div v-for="row in unref(rows)" class="row-grid" :class="{ mergeAdjacent }" :key="row">
<GridCell
v-for="col in unref(cols)"
:key="col"
v-bind="gatherCellProps(unref(cells)[row * 100 + col])"
/>
</div>
</div>
2021-06-11 23:38:16 -05:00
</template>
2022-01-24 22:23:30 -06:00
<script lang="ts">
2022-03-03 21:39:48 -06:00
import "components/common/table.css";
import themes from "data/themes";
import { isHidden, isVisible, Visibility } from "features/feature";
2022-06-26 19:17:22 -05:00
import type { GridCell } from "features/grids/grid";
2022-03-03 21:39:48 -06:00
import settings from "game/settings";
import { processedPropType } from "util/vue";
import { computed, defineComponent, unref } from "vue";
2022-01-24 22:25:34 -06:00
import GridCellVue from "./GridCell.vue";
2021-06-11 23:38:16 -05:00
2022-01-24 22:25:34 -06:00
export default defineComponent({
props: {
visibility: {
type: processedPropType<Visibility | boolean>(Number, Boolean),
2022-01-24 22:25:34 -06:00
required: true
},
rows: {
type: processedPropType<number>(Number),
2022-01-24 22:25:34 -06:00
required: true
},
cols: {
type: processedPropType<number>(Number),
2022-01-24 22:25:34 -06:00
required: true
},
cells: {
type: processedPropType<Record<string, GridCell>>(Object),
2022-01-24 22:25:34 -06:00
required: true
}
},
components: { GridCell: GridCellVue },
2022-01-24 22:25:34 -06:00
setup() {
const mergeAdjacent = computed(() => themes[settings.theme].mergeAdjacent);
function gatherCellProps(cell: GridCell) {
const { visibility, onClick, onHold, display, title, style, canClick, id } = cell;
return { visibility, onClick, onHold, display, title, style, canClick, id };
}
return { unref, gatherCellProps, Visibility, mergeAdjacent, isVisible, isHidden };
2022-01-24 22:25:34 -06:00
}
2022-01-24 22:23:30 -06:00
});
2021-06-11 23:38:16 -05:00
</script>