-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(AUTO) Merge pull request #32 from GsLogiMaker/fix/refactor-core-comp…
…onents Refactor core 2D components and modules
- Loading branch information
github-actions[bot]
committed
Nov 29, 2024
1 parent
fcaa9ac
commit cb30a2d
Showing
12 changed files
with
25 additions
and
242 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |