From 6058ab8b492543483a6d060db8edccc42d3bfd42 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 14 Nov 2022 16:53:39 +0100 Subject: [PATCH] Class design mockup. I think this will fix every issue with the current paint module. It's main downside will be that it will depend on the editor a lot more, so it will need to have more code if it needs to run in-app (not that much more code though, and mostly copy paste level stuff). --- game/Node2D.tscn | 3 -- game/PaintCanvas.gd | 21 ++++++++ game/PaintCurve.gd | 11 +++++ game/PaintGroup.gd | 7 +++ game/PaintNode.gd | 8 +++ game/PaintProject.gd | 27 ++++++++++ game/PaintProjectMockup.tscn | 96 ++++++++++++++++++++++++++++++++++++ game/PaintRenderer.gd | 9 ++++ game/Paintfilter.gd | 7 +++ game/editor.gd | 18 +++++++ 10 files changed, 204 insertions(+), 3 deletions(-) delete mode 100644 game/Node2D.tscn create mode 100644 game/PaintCanvas.gd create mode 100644 game/PaintCurve.gd create mode 100644 game/PaintGroup.gd create mode 100644 game/PaintNode.gd create mode 100644 game/PaintProject.gd create mode 100644 game/PaintProjectMockup.tscn create mode 100644 game/PaintRenderer.gd create mode 100644 game/Paintfilter.gd create mode 100644 game/editor.gd diff --git a/game/Node2D.tscn b/game/Node2D.tscn deleted file mode 100644 index b171e8d..0000000 --- a/game/Node2D.tscn +++ /dev/null @@ -1,3 +0,0 @@ -[gd_scene format=2] - -[node name="Node2D" type="Node2D"] diff --git a/game/PaintCanvas.gd b/game/PaintCanvas.gd new file mode 100644 index 0000000..28bdfc4 --- /dev/null +++ b/game/PaintCanvas.gd @@ -0,0 +1,21 @@ +extends Node2D + +# Canvas that can be used to draw on + +# Should probably store it's actual data in an lz4 compressed poolvector property +# like what voxelman does + +# Undo history should be handled by the editor itself + +# It could use the paint module's actions for manipulation + +# it could have a drag and drop image property so things can be dropped into it + +# could be "infinite", so ti does not need to mess with resizes -> needs chunks though +# if needed this should likely be an another class, like an InifinePaintCanvas or ChunkedPaintCanvas + +# better for now: +# it could have it's own size -> when added to the tree it should copy the size of it's +# parent paint project +# then it should have a resize button with properties, ot it's sidebar module should have a button +# + popup to handle resizes diff --git a/game/PaintCurve.gd b/game/PaintCurve.gd new file mode 100644 index 0000000..3026b79 --- /dev/null +++ b/game/PaintCurve.gd @@ -0,0 +1,11 @@ +extends Path2D + +export(int, "append,union,sub,simdiff,etc...") var operation : int = 0 + +# The renderer should process each child one by one in tree order +# A render needs to start with a curve with an append operation +# apply all non append curves to the last append curve +# render it when out of children or when the next append curve is reached + +# It could just render only one append curves aswell, it could warn if you have more than one +# This will need testing diff --git a/game/PaintGroup.gd b/game/PaintGroup.gd new file mode 100644 index 0000000..e542f3f --- /dev/null +++ b/game/PaintGroup.gd @@ -0,0 +1,7 @@ +extends Node2D + +# Collects all child PaintNodes and renders them to it's texture +# updates tex when a child changes +# PaintNodes will need to signal their parents when they changed + +# update should run in process to save potential cycles diff --git a/game/PaintNode.gd b/game/PaintNode.gd new file mode 100644 index 0000000..be8e056 --- /dev/null +++ b/game/PaintNode.gd @@ -0,0 +1,8 @@ +extends Node +# PaintNode +# base class for paint related classes + +# should inherit either Node2D or CanvasItem directly +# Node2D is probably better + +# diff --git a/game/PaintProject.gd b/game/PaintProject.gd new file mode 100644 index 0000000..43c10a0 --- /dev/null +++ b/game/PaintProject.gd @@ -0,0 +1,27 @@ +tool +extends Node2D #PaintNode + +export(Vector2i) var image_size : Vector2i = Vector2i(64, 64) + +export(String) var image_file_name : String +export(int, "png") var image_type : int + +# manages Grid, and BG's size +# also lets you hide them, so custom ones can be created +# could have an api to register backgorund layers and then it will resize them + +# Image size will only affect rendering at the end when saving the image + +func save_image() -> void: + pass + +func _get_property_list() -> Array: + return [ + { + "type": TYPE_NIL, + "name": "save_image", + "hint": PROPERTY_HINT_BUTTON, + "hint_string": "save_image:Save/EditorIcons" + } + + ] diff --git a/game/PaintProjectMockup.tscn b/game/PaintProjectMockup.tscn new file mode 100644 index 0000000..643694d --- /dev/null +++ b/game/PaintProjectMockup.tscn @@ -0,0 +1,96 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://PaintProject.gd" type="Script" id=1] +[ext_resource path="res://PaintCanvas.gd" type="Script" id=2] +[ext_resource path="res://PaintRenderer.gd" type="Script" id=3] +[ext_resource path="res://PaintCurve.gd" type="Script" id=4] +[ext_resource path="res://PaintGroup.gd" type="Script" id=5] +[ext_resource path="res://Paintfilter.gd" type="Script" id=6] + +[sub_resource type="Curve2D" id=1] +_data = { +"points": PoolVector2Array( -126.479, 82.1171, 126.479, -82.1171, 239, 28, 0, 0, 0, 0, 461, 58, 0, 0, 0, 0, 491, 198, 0, 0, 0, 0, 494, 346, 0, 0, 0, 0, 107, 431, 0, 0, 0, 0, 43, 257, 0, 0, 0, 0, 201, 99, 0, 0, 0, 0, 242, 75, 0, 0, 0, 0, 214, 282, 0, 0, 0, 0, 329, 186, 0, 0, 0, 0, 368, 121, 0, 0, 0, 0, 338, 82, 0, 0, 0, 0, 284, 62, 0, 0, 0, 0, 239, 28 ) +} + +[node name="PaintProject (PaintNode)" type="Node2D"] +script = ExtResource( 1 ) +save_image = null + +[node name="Grid (hidden)" type="Node" parent="."] + +[node name="BG (hidden)" type="Node" parent="."] + +[node name="PaintCanvas" type="Node2D" parent="."] +script = ExtResource( 2 ) + +[node name="PaintCanvas2" type="Node2D" parent="."] + +[node name="PaintGroup" type="Node2D" parent="."] + +[node name="PaintCanvas3" type="Node2D" parent="PaintGroup"] + +[node name="PaintCanvas4" type="Node2D" parent="PaintGroup"] + +[node name="PaintGroup" type="Node2D" parent="PaintGroup"] +script = ExtResource( 5 ) + +[node name="PaintCurveRender" type="Node2D" parent="PaintGroup/PaintGroup"] +__meta__ = { +"_editor_description_": "I'm hoping to use the built in svg renderer to rasterize curves. If it works, it will be a huge timesave. Should foreach children and apply them one by one based on their operation setting." +} + +[node name="PaintCurve" type="Path2D" parent="PaintGroup/PaintGroup/PaintCurveRender"] +curve = SubResource( 1 ) +script = ExtResource( 4 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="PaintPathObject" type="Node2D" parent="PaintGroup/PaintGroup"] +__meta__ = { +"_editor_description_": "Maybe" +} + +[node name="PaintCurveRender2" type="Node2D" parent="PaintGroup/PaintGroup"] + +[node name="PaintCurve" type="Path2D" parent="PaintGroup/PaintGroup/PaintCurveRender2"] +curve = SubResource( 1 ) +script = ExtResource( 4 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="PaintCurve1" type="Path2D" parent="PaintGroup/PaintGroup/PaintCurveRender2"] +curve = SubResource( 1 ) +script = ExtResource( 4 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="PaintCurve2" type="Path2D" parent="PaintGroup/PaintGroup/PaintCurveRender2"] +curve = SubResource( 1 ) +script = ExtResource( 4 ) +__meta__ = { +"_editor_description_": "Union'd with PaintCurve1." +} +operation = 1 + +[node name="PaintGroup" type="Node2D" parent="PaintGroup/PaintGroup"] + +[node name="PaintCanvas6" type="Node2D" parent="PaintGroup/PaintGroup/PaintGroup"] + +[node name="PaintCanvas7" type="Node2D" parent="PaintGroup/PaintGroup/PaintGroup"] + +[node name="PaintCanvas7" type="Node2D" parent="PaintGroup"] + +[node name="PaintRenderer" type="Node2D" parent="PaintGroup"] +script = ExtResource( 3 ) + +[node name="PaintFilter" type="Node2D" parent="PaintGroup"] +script = ExtResource( 6 ) + +[node name="PaintCanvas8" type="Node2D" parent="PaintGroup/PaintFilter"] + +[node name="PaintCanvas9" type="Node2D" parent="PaintGroup/PaintFilter"] + +[node name="PaintCanvas10" type="Node2D" parent="PaintGroup/PaintFilter"] diff --git a/game/PaintRenderer.gd b/game/PaintRenderer.gd new file mode 100644 index 0000000..e0bcd5a --- /dev/null +++ b/game/PaintRenderer.gd @@ -0,0 +1,9 @@ +extends Node2D + +# inherith from PaintNode + +# could be a thin base class for things that just render something +# like noises etc +# could have one for MMMaterial interp + +# over PaintNode they would just store and remember their parent PaintProject's size diff --git a/game/Paintfilter.gd b/game/Paintfilter.gd new file mode 100644 index 0000000..c15562d --- /dev/null +++ b/game/Paintfilter.gd @@ -0,0 +1,7 @@ +extends Node2D + +# inherits from PaintGroup +# Same as PaintGroup except applies a filter to it's output +# good for non destructive editing + +# Could also do resampling, resizing, shringking etc diff --git a/game/editor.gd b/game/editor.gd new file mode 100644 index 0000000..70ee778 --- /dev/null +++ b/game/editor.gd @@ -0,0 +1,18 @@ +extends Node + +# Paint editor module + +# Sidebar + +# 1 class +# by default it should have the color grid, and a color chooser, and module support +# modules could be added for paintnode derived classes +# it just forwards the currect selction to hem so they can +# handle whether they want to be shown for a particular class + +# should have customizable location (left / right) Voxelman has the code + +# Other + +# the top file new etc menu is not needed, as now all of that are going to be handled via nodes and +# the editor's functionality