Skip to content

Commit

Permalink
refacto: review and clean up the code a little
Browse files Browse the repository at this point in the history
/spend 30m
  • Loading branch information
Goutte committed Jan 4, 2024
1 parent 26df773 commit d00a6f8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
12 changes: 6 additions & 6 deletions addons/goutte.animated_shape_2d/editor/shape_frame_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ func get_editor_node_from_path(path: Array) -> Node:
return node


# ______ _
# | ____| | |
# | |____ _____ _ __ | |_ ___
# | __\ \ / / _ \ '_ \| __/ __|
# | |___\ V / __/ | | | |_\__ \
# |______\_/ \___|_| |_|\__|___/
# _ _ _
# | | (_) | |
# | | _ ___| |_ ___ _ __ ___ _ __ ___
# | | | / __| __/ _ \ '_ \ / _ \ '__/ __|
# | |____| \__ \ || __/ | | | __/ | \__ \
# |______|_|___/\__\___|_| |_|\___|_| |___/
#


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@tool
extends Control

## Bottom panel for the Editor, shown along with Output, Debugger, etc.
## Dedicated to editing a single AnimatedShape2D.
## Will show a list of animation names, and frames for each animation.

const FRAME_SCENE := preload("./shape_frame_editor.tscn")

@onready var animation_names_item_list: ItemList = %AnimationNamesItemList
Expand All @@ -19,6 +23,14 @@ var zoom_level := 1.0: set = set_zoom_level
## Customizable background color of previews.
var background_color := Color.WEB_GRAY

## Button Group for the various frames, so that only one is selected at a time.
## We assign this procedurally because assigning it in the scene did not work.
var frames_button_group: ButtonGroup

## Array of ShapeFrameEditor currently shown, for the selected animation.
## These are the children of frames_container, except when config is missing.
var frames_list := Array() # of ShapeFrameEditor


signal frame_selected(animation_name: String, frame_index: int)
signal frame_deselected(animation_name: String, frame_index: int)
Expand All @@ -33,8 +45,8 @@ func configure(
func clear():
self.animation_names_item_list.deselect_all()
self.animation_names_item_list.clear()
clear_shape_frames()
self.animated_shape = null
clear_shape_frames()


func clear_shape_frames():
Expand Down Expand Up @@ -114,10 +126,6 @@ func rebuild_animation_names_item_list(
self.animation_names_item_list.item_selected.emit(selected_index)


var frames_button_group: ButtonGroup
var frames_list := Array() # of ShapeFrameEditor


func rebuild_view_of_animation(animation_name: String):
clear_shape_frames()

Expand Down
2 changes: 1 addition & 1 deletion addons/goutte.animated_shape_2d/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Animated Shape 2D"
description="Helps making animated shapes to go with your animated sprites. This allows you to fully configure a CollisionShape2D for each frame of each animation of an AnimatedSprite2D. It also comes with an Editor, and supports linked frames that you can edit together, any type of shape, and various fallback mechanisms."
author="Goutte"
version="1.2.1"
version="1.3.0"
script="plugin.gd"
29 changes: 14 additions & 15 deletions addons/goutte.animated_shape_2d/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extends EditorPlugin
#
# This plugin adds the following to the Editor:
# - An AnimatedShape2D Node you can add to your scenes in order to configure
# a CollisionShape2D with dynamic values per frame of an AnimatedSprite.
# This is very handy for making variable Hurtboxes, Solidboxes, or Hitboxes.
# a CollisionShape2D with dynamic values per frame of an AnimatedSprite2D.
# This is very handy for making dynamic Hurtboxes, Solidboxes, or Hitboxes.
# - A GUI for editing a ShapeFrame2D, similar to the SpriteFrames GUI.
#

Expand Down Expand Up @@ -33,6 +33,18 @@ func _exit_tree():
remove_control_from_bottom_panel(self.bottom_panel_control)


func update_bottom_panel(animated_shape: AnimatedShape2D):
if animated_shape == null:
self.bottom_panel_button.button_pressed = false
self.bottom_panel_button.visible = false
self.bottom_panel_control.clear()
return

self.bottom_panel_button.visible = true
self.bottom_panel_button.button_pressed = true
self.bottom_panel_control.rebuild_gui(animated_shape)


func on_inspector_edited_object_changed():
var edited_object := get_editor_interface().get_inspector().get_edited_object()
if edited_object is ShapeFrame2D:
Expand All @@ -48,16 +60,3 @@ func on_inspector_edited_object_changed():
animated_shape = edited_object as AnimatedShape2D
update_bottom_panel(animated_shape)


func update_bottom_panel(animated_shape: AnimatedShape2D):
if animated_shape == null:
self.bottom_panel_button.button_pressed = false
self.bottom_panel_button.visible = false
self.bottom_panel_control.clear()
return

self.bottom_panel_button.visible = true
self.bottom_panel_button.button_pressed = true
self.bottom_panel_control.rebuild_gui(animated_shape)


1 change: 1 addition & 0 deletions addons/goutte.animated_shape_2d/shape_frame_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class_name ShapeFrame2D
## Each frame of each animation of an AnimatedSprite2D will be matched to one
## of these, in a Dictionary in ShapeFrames2D.


## Position of the collision shape in its parent.
@export var position := Vector2.ZERO:
set(value):
Expand Down
10 changes: 0 additions & 10 deletions addons/goutte.animated_shape_2d/shape_frames_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ func remove_shape_frame(animation_name: StringName, frame: int):
animation_data[frame] = null


## Returns the shape for the specified animation name and frame.
## This should return null if there is no Shape2D for the animation and frame.
## Legacy (not performant, since we usually fetch the shape_frame before this).
#func get_shape(animation_name: StringName, frame: int) -> Shape2D:
#var frame_data := get_shape_frame(animation_name, frame)
#if null != frame_data:
#return frame_data.get_shape()
#return null


# Example of a tentative procedural API to make this.
# Prefer using the Editor for now.
#static func make_dummy() -> ShapeFrames2D:
Expand Down

0 comments on commit d00a6f8

Please sign in to comment.