-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export special objects to ppen; improve SpecialObject typings
- Loading branch information
1 parent
a72a735
commit bfcab9a
Showing
5 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,76 @@ | ||
import type { Coordinate } from "ol/coordinate"; | ||
import { Course } from "./course"; | ||
|
||
export interface SpecialObject { | ||
interface SpecialObjectBase { | ||
id: number; | ||
kind: string; | ||
isAllCourses: boolean; | ||
locations: Coordinate[]; | ||
} | ||
|
||
interface LineObject extends SpecialObjectBase { | ||
kind: "line"; | ||
color?: string; | ||
lineWidth?: string; | ||
} | ||
|
||
interface WhiteOutObject extends SpecialObjectBase { | ||
kind: "white-out"; | ||
} | ||
|
||
interface DescriptionsObject extends SpecialObjectBase { | ||
kind: "descriptions"; | ||
} | ||
|
||
export type SpecialObject = LineObject | WhiteOutObject | DescriptionsObject; | ||
|
||
export function toPpen(object: SpecialObject, courses: Course[]) { | ||
return { | ||
type: "special-object", | ||
attrs: { | ||
id: object.id, | ||
kind: object.kind, | ||
}, | ||
children: [ | ||
...object.locations.map((l) => ({ | ||
type: "location", | ||
attrs: { | ||
x: l[0], | ||
y: l[1], | ||
}, | ||
})), | ||
...appearance(object), | ||
{ | ||
type: "courses", | ||
attrs: { | ||
all: object.isAllCourses, | ||
}, | ||
children: !object.isAllCourses | ||
? courses | ||
.filter((c) => c.specialObjects.some((o) => o.id === object.id)) | ||
.map((c) => ({ | ||
type: "course", | ||
attrs: { course: c.id }, | ||
})) | ||
: [], | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
function appearance(object: SpecialObject) { | ||
if (object.kind === "line") { | ||
return [ | ||
{ | ||
type: "appearance", | ||
attrs: { | ||
"line-kind": "single", | ||
color: object.color, | ||
"line-width": object.lineWidth, | ||
}, | ||
}, | ||
]; | ||
} else { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters