Dataclasses

An asset by 3ddelano
The page banner background of a mountain and forest
Dataclasses thumbnail image
Dataclasses thumbnail image
Dataclasses hero image

Quick Information

0 ratings
Dataclasses icon image
3ddelano
Dataclasses

Easy dataclasses with helpful features for Godot Engine.(similar to Python's dataclasses)Features- Customization options- Create object from Dictionary- Serialize to Dictionary- Better printing of objectExamples, Customization and Docshttps://github.com/3ddelano/dataclasses-godot

Supported Engine Version
3.2
Version String
1.0.2
License Version
MIT
Support Level
community
Modified Date
2 years ago
Git URL
Issue URL

Dataclasses Godot Plugin

(Get it from Godot Asset Library - Dataclasses on AssetLibrary)

Easy to use dataclasses with helpful features

(similar to Python's dataclasses)

Godot3
Dataclasses logo

Features

  • Customization options
  • Create object from Dictionary
  • Serialize to Dictionary
  • Better printing of object

Installation

  • From Asset Library

    Search for "Dataclasses" in the AssetLib tab in Godot and click Download. Once it has downloaded click Install. In the popup that opens, click Install again. (You dont need to enable the plugin in ProjectSettings)

  • Manual Installation

    Copy the contents of addons/dataclasses-godot into the addons/ folder in the same directory as your project. (You dont need to enable the plugin in ProjectSettings)

Quick Start

# Main.gd
extends Control

class MyClass:
    extends Dataclass
    func _init().("MyClass"): pass

    # Compulsory
    var some_int: int
    var some_array: Array

    # Optional
    var optional_dict = null


func _ready():
    # Better printing of objects
    var obj = MyClass.new()
    obj.optional_dict = {foo = "bar"}
    print(obj)

    # Create object from Dictionary
    print(MyClass.new().from_dict({some_int = 123456789}))

    # Serialize to Dictionary
    print(MyClass.new().from_dict({some_array = [1,2,3,4, 5]}).to_dict())

Documentation

Class: Dataclass

Properties

Type Name Defaults Description
String _name_ "" Name of the class to display when printing
String _options_ Default values mentioned in Customization Options to customize behaviour of the dataclass

Methods

Returns Definition Description
self from_dict(dict: Dictionary) Create object from Dictionary
Dictionary to_dict() Serialize object to Dictionary

Customization

  • sort_keys: true

    Whether to sort properties when printing

  • include_null_in_dict: true

    Whether to include properties with null values in the to_dict() method

  • include_null_in_print: true

    Whether to include properties with null values when printing

  • print_newline: false

    Whether to print properties on newlines when printing

Customization Examples

  • Print properties of the object on newline
    # Main.gd
    class MyClass:
        extends Dataclass
        func _init().("MyClass", {print_newline = true}): pass
    
        var some_int: int
        var some_array: Array
    
    func _ready():
        print(MyClass.new())
    

Run res://sample/Sample.tscn for an example

Other Projects

Support the project development

Buy Me A Coffee

Want to support in other ways? Contact me on Discord: @3ddelano#6033

For doubts / help / bugs / problems / suggestions do join: 3ddelano Cafe Discord server

Easy dataclasses with helpful features for Godot Engine.
(similar to Python's dataclasses)

Features
- Customization options
- Create object from Dictionary
- Serialize to Dictionary
- Better printing of object

Examples, Customization and Docs
https://github.com/3ddelano/dataclasses-godot

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Dataclasses icon image
3ddelano
Dataclasses

Easy dataclasses with helpful features for Godot Engine.(similar to Python's dataclasses)Features- Customization options- Create object from Dictionary- Serialize to Dictionary- Better printing of objectExamples, Customization and Docshttps://github.com/3ddelano/dataclasses-godot

Supported Engine Version
3.2
Version String
1.0.2
License Version
MIT
Support Level
community
Modified Date
2 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers