Skip to content

Commit

Permalink
(AUTO) Merge pull request #32 from GsLogiMaker/fix/refactor-core-comp…
Browse files Browse the repository at this point in the history
…onents

Refactor core 2D components and modules
  • Loading branch information
github-actions[bot] committed Nov 29, 2024
1 parent fcaa9ac commit cb30a2d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 242 deletions.
Binary file modified bin/libglecs.linux.template_debug.x86_64.so
Binary file not shown.
Binary file modified bin/libglecs.windows.template_debug.x86_64.dll
Binary file not shown.
68 changes: 14 additions & 54 deletions examples/asteroids/asteroids.gd
Original file line number Diff line number Diff line change
@@ -1,64 +1,24 @@

extends Node2D

var world:= GFWorld()

var world:= GFWorld.new()

var texture:= load("res://icon.png")

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var e:= GFEntity.spawn().set_name("Test")
e.add_component(RenderableSprite2D, [texture])

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

class RenderableSprite2D extends GFComponent:
static func _get_members() -> Dictionary: return {
texture = null,
rid = RID(),
}
GFEntity.spawn(world) \
.set_name("Test") \
.add_component(GFTexture2D, [texture]) \
.add_component(GFCanvasItem) \
.add_component(GFPosition2D)

world.start_rest_api()

func _register(world:GFWorld):
# On add
world.observer_builder("flecs/core/OnAdd") \
.with(RenderableSprite2D) \
.for_each(func(sprite:RenderableSprite2D):
await Engine.get_main_loop().process_frame
var texture:= sprite.get_texture()
if sprite.get_texture() == null:
return
var rid:= RenderingServer.canvas_item_create()
sprite.set_rid(rid)
RenderingServer.canvas_item_set_parent(rid, Engine.get_main_loop().current_scene.get_canvas_item())
RenderingServer.canvas_item_add_texture_rect(
rid,
Rect2(-texture.get_size() / 2, texture.get_size()),
texture,
)
)

# On set
world.observer_builder("flecs/core/OnSet") \
.with(RenderableSprite2D) \
.for_each(func(sprite:RenderableSprite2D):
var texture:= sprite.get_texture()
var rid:= sprite.get_rid()
RenderingServer.canvas_item_clear(rid)
RenderingServer.canvas_item_add_texture_rect(
rid,
Rect2(-texture.get_size() / 2, texture.get_size()),
sprite.get_texture(),
)
)

func get_rid() -> RID:
return getm(&"rid")
func set_rid(v:RID) -> void:
setm(&"rid", v)

func get_texture() -> Texture2D:
return getm(&"texture")
func set_texture(v:Texture2D) -> void:
setm(&"texture", v)
func _process(delta: float) -> void:
world.progress(delta)
world.lookup("Test") \
.get_component(GFPosition2D) \
.set_vec(get_global_mouse_position())
2 changes: 1 addition & 1 deletion examples/asteroids/asteroids.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dglcrfdcbfvvf"]

[ext_resource type="Script" path="res://examples/asteroids/asteroids.gd" id="1_i0ls5"]
[ext_resource type="Script" path="res://addons/glecs/examples/asteroids/asteroids.gd" id="1_i0ls5"]

[node name="Asteroids" type="Node2D"]
script = ExtResource("1_i0ls5")
Expand Down
58 changes: 0 additions & 58 deletions gd/std/2d/canvas_item.gd

This file was deleted.

29 changes: 0 additions & 29 deletions gd/std/2d/position2d.gd

This file was deleted.

25 changes: 0 additions & 25 deletions gd/std/2d/rotation2d.gd

This file was deleted.

26 changes: 0 additions & 26 deletions gd/std/2d/scale2d.gd

This file was deleted.

27 changes: 0 additions & 27 deletions gd/std/2d/texture2d.gd

This file was deleted.

7 changes: 0 additions & 7 deletions gd/std/rendering/render.gd

This file was deleted.

14 changes: 0 additions & 14 deletions gd/std/std.gd

This file was deleted.

11 changes: 10 additions & 1 deletion plugin.gd
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
@tool
extends EditorPlugin
extends EditorPlugin

const modules:= preload("./gd/modules.gd")

func _enter_tree() -> void:
add_autoload_singleton("_glecs_modules", "./gd/modules.gd")


func _exit_tree() -> void:
remove_autoload_singleton("_glecs_modules")

0 comments on commit cb30a2d

Please sign in to comment.