Skip to content

Instantly share code, notes, and snippets.

View anthonyec's full-sized avatar
🐢
eat the food and live

Anthony Cossins anthonyec

🐢
eat the food and live
View GitHub Profile
@anthonyec
anthonyec / position.gd
Created March 25, 2023 17:48
Get mouse position relative to window in Godot
# Usually you can do:
get_viewport().get_mouse_position()
# For a window you can do:
@onready var window: Window = %Window
window.get_mouse_position()
@anthonyec
anthonyec / gamepad_debugger.gd
Last active April 11, 2024 13:44
Godot gamepad input visualisation for debugging (GDScript 2)
@tool
extends Control
@export var device: int = 0
func _process(delta: float) -> void:
queue_redraw()
func _draw() -> void:
# Set the size, the layout isn't dynamic and based on something I sketched!
@anthonyec
anthonyec / requestAnimationFrame.js
Created December 12, 2022 16:19
Request animation frame instead of setInterval
const FPS = 60;
let lastFrameTime = 0;
function update() {
const diff = Date.now() - lastFrameTime;
if (diff > (1000 / FPS)) {
// DO STUFF HERE.
@anthonyec
anthonyec / alternate.test.ts
Last active October 17, 2022 14:54
Alternate indices generator
describe("alternate", () => {
it("counts up when starting index is at the start", () => {
expect(Array.from(alternate(0, 10))).toStrictEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
it("counts down indices when starting index is at the end", () => {
expect(Array.from(alternate(10, 10))).toStrictEqual([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
})
it("counts up when starting index is negatively out of bounds", () => {
@anthonyec
anthonyec / tween_and_yield.gd
Created September 4, 2022 11:10
Tween and yield
var tween = create_tween()
tween.set_trans(Tween.TRANS_SINE)
tween.tween_property(foot, "translation", home.transform.origin, move_duration)
yield(tween, "finished")
@anthonyec
anthonyec / journalctl_commands.md
Created March 21, 2022 09:49
Useful commands for getting logs off a remote server

Export all logs to a file

journalctl > all_logs.txt

Download logs from remote server

scp : 
const getDifferenceBetweenAmounts = (transactionA, transactionB) => {
return Math.abs(transactionA.amount - transactionB.amount);
};
const categorizeSimilarTransactions = (transactions) => {
return transactions.map((transaction) => {
if (transaction.category) {
return transaction;
}
@anthonyec
anthonyec / infiniteLineIntersection.js
Created September 13, 2021 14:01
Get the intersection point of 2 lines segments casted infinitely
function infiniteLineIntersection(line1Start, line1End, line2Start, line2End) {
const denominator =
(line2End.y - line2Start.y) * (line1End.x - line1Start.x) -
(line2End.x - line2Start.x) * (line1End.y - line1Start.y);
const noIntersection = denominator === 0;
if (noIntersection) {
return null;
}
@anthonyec
anthonyec / godot_local_vector_up.md
Last active December 19, 2020 16:52
Local Vector directions in Godot
self.global_transform.basis.y.normalized()

is the local equivialant to

Vector3.UP
https://google.com/ 🌐 Google
http://yahoo.com/ ☁️ Yahoo