Skip to content

Instantly share code, notes, and snippets.

View fenix-hub's full-sized avatar
🕹️

Nicolò Santilio fenix-hub

🕹️
View GitHub Profile
@fenix-hub
fenix-hub / iso8601_parser.gd
Last active November 19, 2022 18:46
Parse an ISO8601 Time Period definition to a GDScript Dictionary
extends Resource
var regex_str: String = "((?<repeat>R[0-9]+)\/)?P((?<years>[0-9]+)Y)?((?<months>[0-9]+)M)?((?<weeks>[0-9]+)W)?((?<days>[0-9]+)D)?(T((?<hours>[0-9]+)H)?((?<minutes>[0-9]+)M)?((?<seconds>[0-9]+\.?[0-9]+)?S)?)?"
var regex: RegEx.new()
class _init() -> void:
regex.compile(regex_str)
func parse_iso(iso_string: String) -> RegExMatch:
@fenix-hub
fenix-hub / #description.md
Last active May 15, 2024 19:56
GDScript JSON <> Class Serializer/Deserializer

You can find usages in the GDScript Unirest plugin

This is a fast serializer/deserializer written in GDScript to convert a JSON (Dictionary) to a class, using something similar to the Reflection concecpt. json_to_class can be used to convert a Dictionary to a Class. All keys in the Dictionary will be treated as variables and their types will be guessed in the best way possible. A class (defined by the class_name keyword) must extend Reference or Object or be an inner class, or else Godot will not able to see its properties. It is also possible to deserialize a JSON key to a class property with a different name using the export hint as a variable name.

example usage:

@fenix-hub
fenix-hub / #DevTools Collection
Last active February 15, 2023 14:00
A collection of DevTools I'm finding online
This is a collection of several DevTools.
By DevTools I mean platforms, frameworks, specifications and standards I'm acknowledging thorugh my IT experiences.
@fenix-hub
fenix-hub / dateToUnixTimestamp.gd
Last active February 11, 2022 19:21
Converts an ISO 8601 Date String to UNIX Timestamp int
# The best option is always to confront dates based on their UNIX value
# With these scripts, you'll get something like "16778909182". Put it in the Array and sort it with the others.
var timestamp: String = "2021-08-04T16:45:35.603Z"
# Using String, Arrays and Dictionary
var datetime: PoolStringArray = timestamp.split("T")
var date: PoolStringArray = datetime[0].split("-")
var time: PoolStrngArray = datetime[1].split(":")
var unix_timestamp: int = OS.get_unix_time_from_datetime({year=date[0],month=date[1],day=date[2],hour=time[0],minute=time[1],second=time[2].substr(0,2)}
"""
This example uses a simple scene with a Control node as the root and a single Button as a child,
but could be applied to any case scenario.
"""
extends Control
func _ready():
$Button.connect("pressed", self, "on_pressed", [$Button.name, $Button.text, $Button.CUSTOM_VAR])
# @CUSTOM_VAR if the button has its own script

TileMap Collision Detection Script

Collision detection .gd script for 2D bodies and tilemaps

Questo codice può essere applicato per PhysicsBody2D ereditati da KinematicBody2D e RigidBody2D (quest'ultimo con l'accortezza di rendere true il parametro collision_monitor e determinare il numero di collisioni che si vogliono rilevare)

E' comunque possibile rilevare le collisioni sia con le funzioni che i Body2D implementano, sia con i segnali che questi emettono (come ad esempio body_entered)

KinematicBody2D Se il corpo si muove attraverso la funzione move_and_slide è possibile ottenere una o più collisioni attraverso il metodo get_slide_collision in questa maniera: