From 4490c607ab694f46b5ae8cfc160cedebe6f74e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20H=C3=BCbner?= Date: Sun, 27 Feb 2022 12:35:13 +0000 Subject: [PATCH] Adding types for vrld/hump (#33) * add binding for vector-light.lua in vrld/hump * add binding for vector.lua in vrld/hump * add binding for camera.lua in vrld/hump * add binding for signal.lua in vrld/hump * add binding for timer.lua in vrld/hump * add ..(crude) binding for gamestate.lua in vrld/hump * update camera.lua with pre-existing smoothing functions, module callable to create an instance, varargs to lockX, lockY, varargs to SmoothingFUnction. * update signal.lua to have signatures that match global form as well --- types/hump/camera.d.tl | 47 ++++++++++++++++++++++++++++++ types/hump/gamestate.d.tl | 20 +++++++++++++ types/hump/signal.d.tl | 28 ++++++++++++++++++ types/hump/timer.d.tl | 56 ++++++++++++++++++++++++++++++++++++ types/hump/vector-light.d.tl | 39 +++++++++++++++++++++++++ types/hump/vector.d.tl | 54 ++++++++++++++++++++++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 types/hump/camera.d.tl create mode 100644 types/hump/gamestate.d.tl create mode 100644 types/hump/signal.d.tl create mode 100644 types/hump/timer.d.tl create mode 100644 types/hump/vector-light.d.tl create mode 100644 types/hump/vector.d.tl diff --git a/types/hump/camera.d.tl b/types/hump/camera.d.tl new file mode 100644 index 0000000..fa40bed --- /dev/null +++ b/types/hump/camera.d.tl @@ -0,0 +1,47 @@ +local record camera + + type DrawFunction = function() + type SmoothingFunction = function(x: number, y: number, ...: any): number, number + + record smooth + none: function(): SmoothingFunction + linear: function(speed: number): SmoothingFunction + damped: function(stiffness: number): SmoothingFunction + end + + new: function(x: number, y: number, zoom: number, rot: number): camera + + move: function(self: camera, dx: number, dy: number): camera + lookAt: function(self: camera, x: number, y: number): camera + position: function(self: camera): number, number + + rotate: function(self: camera, angle: number): camera + rotateTo: function(self: camera, angle: number): camera + + zoom: function(self: camera, mul: number): camera + zoomTo: function(self: camera, zoom: number): camera + + attach: function(self: camera) + detach: function(self: camera) + + draw: function(self: camera, func: DrawFunction) + worldCoords: function(self: camera, x: number, y: number): number, number + cameraCoords: function(self: camera, x: number, y: number): number, number + mousePosition: function(self: camera): number, number + + lockX: function(self: camera, x: number, smoother: SmoothingFunction, ...: any) + lockY: function(self: camera, y: number, smoother: SmoothingFunction, ...: any) + lockPosition: function(self: camera, x: number, y: number, smoother: SmoothingFunction, ...: any) + lockWindow: function(self: camera, x: number, y: number, x_min: number, x_max: number, y_min: number, y_max: number, smoother: SmoothingFunction, ...: any) + + -- module is callable as a function to create a new camera + metamethod __call: function(self: camera, x: number, y: number, zoom: number, rot: number): camera + + smoother: SmoothingFunction + scale: number + x: number + y: number + +end + +return camera \ No newline at end of file diff --git a/types/hump/gamestate.d.tl b/types/hump/gamestate.d.tl new file mode 100644 index 0000000..b8c13ae --- /dev/null +++ b/types/hump/gamestate.d.tl @@ -0,0 +1,20 @@ +local record gamestate + + new: function(): gamestate + + switch: function(to: table, ...: any): any... + current: function(): table + + push: function(to: table, ...: any): any... + pop: function(): any... + + registerEvents: function() + registerEvents: function({string}) + + -- hardcoded love lifecycle functions here, just the very basics :I + update: function(dt: number) + draw: function() + +end + +return gamestate \ No newline at end of file diff --git a/types/hump/signal.d.tl b/types/hump/signal.d.tl new file mode 100644 index 0000000..7040c6a --- /dev/null +++ b/types/hump/signal.d.tl @@ -0,0 +1,28 @@ +local record signal + + new: function(self: signal): signal + + register: function(s: string, f: function): function + register: function(self: signal, s: string, f: function): function + + emit: function(s: string, ...: any) + emit: function(self: signal, s: string, ...: any) + + remove: function(...: function) + remove: function(self: signal, ...: function) + + clear: function(s: string) + clear: function(self: signal, s: string) + + emitPattern: function(p: string, ...: any) + emitPattern: function(self: signal, p: string, ...: any) + + removePattern: function(p: string, ...: function) + removePattern: function(self: signal, p: string, ...: function) + + clearPattern: function(p: string) + clearPattern: function(self: signal, p: string) + +end + +return signal \ No newline at end of file diff --git a/types/hump/timer.d.tl b/types/hump/timer.d.tl new file mode 100644 index 0000000..8dcbf22 --- /dev/null +++ b/types/hump/timer.d.tl @@ -0,0 +1,56 @@ +local record timer + + enum TweenType + "linear" + "quad" + "cubic" + "quart" + "quint" + "sine" + "expo" + "circ" + "back" + "bounce" + "elastic" + end + + type CallbackFunction = function() + type DeltaCallbackFunction = function(dt: number) + type WaitFunction = function(seconds: number) + type Handle = table + + new: function(): timer + + script: function(func: WaitFunction) + script: function(self: timer, func: WaitFunction) + + after: function(self: timer, delay: number, func: CallbackFunction): Handle + after: function(delay: number, func: CallbackFunction): Handle + + every: function(delay: number, func: CallbackFunction): Handle + every: function(self: timer, delay: number, func: CallbackFunction): Handle + + during: function(delay: number, func: DeltaCallbackFunction): Handle + during: function(self: timer, delay: number, func: DeltaCallbackFunction): Handle + + during: function(delay: number, func: DeltaCallbackFunction, after: CallbackFunction): Handle + during: function(self: timer, delay: number, func: DeltaCallbackFunction, after: CallbackFunction): Handle + + cancel: function(handle: Handle) + cancel: function(self: timer, handle: Handle) + + clear: function() + clear: function(self: timer) + + update: function(dt: number) + update: function(self: timer, dt: number) + + tween: function(duration: number, subject: table, target: table, method: TweenType): Handle + tween: function(self: timer, duration: number, subject: table, target: table, method: TweenType): Handle + + tween: function(duration: number, subject: table, target: table, method: TweenType, after: function, ...: any): Handle + tween: function(self: timer, duration: number, subject: table, target: table, method: TweenType, after: function, ...: any): Handle + +end + +return timer \ No newline at end of file diff --git a/types/hump/vector-light.d.tl b/types/hump/vector-light.d.tl new file mode 100644 index 0000000..839aa66 --- /dev/null +++ b/types/hump/vector-light.d.tl @@ -0,0 +1,39 @@ +local record vector_light + + str: function(x: number, y: number) + + fromPolar: function(angle: number, radius: number): number, number + toPolar: function(x: number, y: number): number, number + randomDirection : function(len_min: number, len_max: number): number, number + + -- arithmetic + mul: function(s: number, x: number, y: number): number, number + div: function(s: number, x: number, y: number): number, number + idiv: function(s: number, x: number, y: number): number, number + add: function(x1: number, y1: number, x2: number, y2: number): number, number + sub: function(x1: number, y1: number, x2: number, y2: number): number, number + permul: function(x1: number, y1: number, x2: number, y2: number): number, number + dot: function(x1: number, y1: number, x2: number, y2: number): number + cross: function(x1: number, y1: number, x2: number, y2: number): number + det: function(x1: number, y1: number, x2: number, y2: number): number + + -- relation + eq: function(x1: number, y1: number, x2: number, y2: number): boolean + le: function(x1: number, y1: number, x2: number, y2: number): boolean + lt: function(x1: number, y1: number, x2: number, y2: number): boolean + + -- misc operations + len: function(x: number, y: number): number + len2: function(x: number, y: number): number + dist: function(x1: number, y1: number, x2: number, y2: number): number + dist2: function(x1: number, y1: number, x2: number, y2: number): number + normalize: function(x: number, y: number): number + rotate: function(phi: number, x: number, y: number): number, number + perpendicular: function(x: number, y: number): number, number + project: function(x: number, y: number, u: number, v: number): number, number + mirror: function(x: number, y: number, u: number, v: number): number, number + angleTo: function(x: number, y: number, u: number, v: number): number + trim: function(max_length: number, x: number, y: number): number, number +end + +return vector_light \ No newline at end of file diff --git a/types/hump/vector.d.tl b/types/hump/vector.d.tl new file mode 100644 index 0000000..fcfd3d0 --- /dev/null +++ b/types/hump/vector.d.tl @@ -0,0 +1,54 @@ +local record vector + + new: function(x: number, y: number): vector + fromPolar: function(angle: number, radius: number): vector + randomDirection: function(len_min: number, len_max: number): vector + + isvector: function(self: any): boolean + clone: function(self: vector): vector + unpack: function(self: vector): number, number + permul: function(self: vector, other: vector): vector + + len: function(self: vector): number + toPolar: function(self: vector): number, number + len2: function(self: vector): number + + dist: function(self: vector, other: vector): number + dist2: function(self: vector, other: vector): number + + normalized: function(self: vector): vector + normalizeInPlace: function(self: vector): vector + rotated: function(self: vector, angle: number): vector + rotateInPlace: function(self: vector, angle: number): vector + + perpendicular: function(self: vector): vector + projectOn: function(self: vector, v: vector): vector + mirrorOn: function(self: vector, v: vector): vector + cross: function(self: vector, other: vector): number + angleTo: function(self: vector, other: vector): number + + trimmed: function(self: vector, max_length: number): vector + trimInPlace: function(self: vector, max_length: number): vector + + metamethod __call: function(self: vector, x: number, y: number): vector + + metamethod __add: function(self: vector, other: vector): vector + metamethod __sub: function(self: vector, other: vector): vector + + metamethod __mul: function(self: vector, other: vector): vector + metamethod __mul: function(self: vector, scalar: number): vector + + metamethod __div: function(self: vector, other: vector): vector + metamethod __div: function(self: vector, scalar: number): vector + metamethod __idiv: function(self: vector, scalar: number): vector + + metamethod __eq: function(self: vector, other: vector): boolean + metamethod __lt: function(self: vector, other: vector): boolean + metamethod __le: function(self: vector, other: vector): boolean + + x: number + y: number + +end + +return vector \ No newline at end of file