Skip to content

Commit

Permalink
impl: coordinate_object
Browse files Browse the repository at this point in the history
  • Loading branch information
gnlow committed Dec 4, 2023
1 parent 519802a commit 4663315
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ export class Entry {
this.textures = Object.fromEntries(await Promise.all(
this.project.objects.map(({sprite}) =>
sprite.pictures.map(
async ({id, fileurl, filename, imageType}) => {
async ({id, fileurl, filename, imageType, name}) => {
const url = `/image/${
filename
? (filename + `.${imageType}`)
: fileurl.substring(1)
}`
await Assets.load(url)
const texture = Texture.from(url)
texture.label = name
return [
id,
texture,
Expand Down Expand Up @@ -407,6 +408,39 @@ export class Entry {
calc_rand(a: number, b: number) {
return Math.random() * (b - a) + a
}
coordinate_object(
targetId: string,
type:
| "x"
| "y"
| "rotation"
| "direction"
| "picture_index"
| "size"
| "picture_name",
obj: EntrySprite,
) {
const target =
targetId == "self"
? obj
: this.objects[targetId]
switch (type) {
case "x":
return target.x - 240
case "y":
return -target.y + 135
case "rotation":
return target.rotation
case "direction":
throw "Unimplemented: direction"
case "picture_index":
return target.currentTextureIndex
case "size":
return target.size
case "picture_name":
return target.texture.label
}
}
calc_operation(
n: number,
op:
Expand Down Expand Up @@ -444,7 +478,6 @@ export class Entry {
case "factorial": throw "Unimplemented: factorial"
default: return Math[op](n)
}

}
get_project_timer_value() {
return this.timer.time / 1000
Expand Down

0 comments on commit 4663315

Please sign in to comment.