Repository navigation
Expand file tree
/
Copy pathmap-image.ts
More file actions
60 lines (57 loc) · 1.86 KB
/
Copy pathmap-image.ts
File metadata and controls
60 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { z } from 'zod';
import type { Immutable } from 'immer';
import { uuid, type UUID, uuidSchema } from '../utils/uuid.js';
import { versionedElementModelSchema } from '../marketplace/models/versioned-element-model.js';
import type { MapImageTemplate } from './map-image-template.js';
import { positionSchema } from './utils/position/position.js';
import {
type ImageProperties,
imagePropertiesSchema,
} from './utils/image-properties.js';
import type { MapCoordinates } from './utils/position/map-coordinates.js';
import { newMapPositionAt } from './utils/position/map-position.js';
export const mapImageSchema = z.strictObject({
...versionedElementModelSchema.shape,
id: uuidSchema,
type: z.literal('mapImage'),
templateId: uuidSchema,
position: positionSchema,
image: imagePropertiesSchema,
/**
* Determines the rendering order among other mapImages.
* A smaller number means the mapImage is behind another one.
* The index can also be negative.
* MapImages with the same zIndex don't have a defined order.
*/
zIndex: z.int(),
/**
* Whether the UI should prevent position changes of the map image by drag&drop
*/
isLocked: z.boolean(),
scoutableId: uuidSchema.nullable(),
});
export type MapImage = Immutable<z.infer<typeof mapImageSchema>>;
export function newMapImage(
templateId: UUID,
topLeft: MapCoordinates,
image: ImageProperties,
isLocked: boolean,
zIndex: number
): MapImage {
return {
id: uuid(),
type: 'mapImage',
templateId,
position: newMapPositionAt(topLeft),
image,
isLocked,
zIndex,
scoutableId: null,
};
}
export function newMapImageFromTemplate(
template: MapImageTemplate,
topLeft: MapCoordinates
): MapImage {
return newMapImage(template.id, topLeft, template.image, false, 0);
}