Skip to content

Commit

Permalink
Updating for new project, slight ergonomic improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
QueenOfSquiggles committed Mar 29, 2024
1 parent e9e2bcc commit 9f1c64b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
assets/
doc/
!doc/.gdignore

debug/
target/

Cargo.lock
sqore_release.zip
*.json
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqore"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions scenes/prefabs/sqore_options_menu/sqore_options_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://dnbbxlomwl1pr"]

[ext_resource type="Script" path="res://addons/sqore/scenes/prefabs/sqore_options_menu/sqore_options_menu.gd" id="1_6met4"]
[ext_resource type="Script" path="res://addons/sqore/scenes/prefabs/sqore_options_menu/gameplay.gd" id="2_n73id"]
[ext_resource type="Script" path="res://addons/squiggles-core/scenes/prefabs/sqore_options_menu/sqore_options_menu.gd" id="1_6met4"]
[ext_resource type="Script" path="res://addons/squiggles-core/scenes/prefabs/sqore_options_menu/gameplay.gd" id="2_n73id"]

[node name="SqoreOptionsMenu" type="VBoxContainer"]
anchors_preset = 15
Expand Down
12 changes: 8 additions & 4 deletions sqore.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ macos.release.arm64 = "res://addons/sqore/target/release/libsqore.dylib"

[icons]

;; camera.rs
;; scene/camera.rs

CameraBrain3D = "res://addons/sqore/assets/icons/camera_brain.svg"
VirtualCamera3D = "res://addons/sqore/assets/icons/virtual_camera.svg"

;; interaction.rs

InteractRaycast3D = "res://addons/sqore/assets/icons/interaction_raycast3d.svg"
InteractArea3D = "res://addons/sqore/assets/icons/interaction_area3d.svg"
InteractionObjectArea3D = "res://addons/sqore/assets/icons/interact_object_area3d.svg"
Expand All @@ -41,6 +39,12 @@ FiniteStateMachine = "res://addons/sqore/assets/icons/fsm.svg"
FiniteState = "res://addons/sqore/assets/icons/fsm_state.svg"
FiniteSubStateMachine = "res://addons/sqore/assets/icons/fsm_sub_state.svg"

;; utility_nodes/gui_interact.rs
;; scene/utility_nodes

GuiInteract = "res://addons/sqore/assets/icons/gui_interact.svg"

;; scene/gui

CollapsingVBoxContainer = "res://addons/sqore/assets/icons/collapseable_panel.svg"
LabelledHSlider = "res://addons/sqore/assets/icons/labelled_hslider.svg"

35 changes: 29 additions & 6 deletions src/editor/editor_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ use crate::scene::serialization::SqoreSerialized;
struct SqoreEditorUtils {
tool_items: Option<Gd<PopupMenu>>,
base: Base<EditorPlugin>,
menu_callbacks: Vec<Callable>,
}

#[godot_api]
impl IEditorPlugin for SqoreEditorUtils {
fn enter_tree(&mut self) {
let menu = PopupMenu::new_alloc();
let mut menu = PopupMenu::new_alloc();
menu.connect(
StringName::from("id_pressed"),
Callable::from_object_method(&self.to_gd(), "on_menu_item"),
);
self.base_mut()
.add_tool_submenu_item("Sqore".to_godot(), menu.clone());
self.tool_items = Some(menu);
Expand Down Expand Up @@ -54,10 +59,17 @@ impl IEditorPlugin for SqoreEditorUtils {

fn exit_tree(&mut self) {}
}

#[godot_api]
impl SqoreEditorUtils {
const DOC_ENTRY_INDEX: &'static str = "res://addons/sqore/doc/sqore/index.html";

fn humanize_text(input: &str) -> String {
let (f, b) = input.split_at(1);
let front: String = f.to_uppercase();
let back: String = b.replace('_', " ");
front + back.as_str()
}

/// registers a callable command in both the tools dropdown pane of the editor and the command palette for quick access
fn register_tool_item(
&mut self,
Expand All @@ -67,13 +79,24 @@ impl SqoreEditorUtils {
command_palette: &mut Gd<EditorCommandPalette>,
) {
let fname = ("sqore_core/".to_string() + name).to_godot();
let hname = Self::humanize_text(name);
if let Some(mut menu_items) = self.tool_items.clone() {
menu_items.add_item(name.to_godot());
let index = menu_items.get_item_count() - 1;
menu_items.set_item_tooltip(index, description.to_godot())
menu_items.set_item_text(index, hname.clone().into());
menu_items.set_item_tooltip(index, description.to_godot());
self.menu_callbacks.push(func.clone());
} else {
self.base_mut()
.add_tool_menu_item(fname.clone(), func.clone());
}
command_palette.add_command(hname.to_godot(), fname, func);
}

#[func]
fn on_menu_item(&mut self, index: u32) {
if let Some(callable) = self.menu_callbacks.get(index as usize) {
callable.callv(Array::new());
}
self.base_mut()
.add_tool_menu_item(fname.clone(), func.clone());
command_palette.add_command(name.to_godot(), fname, func);
}
}
2 changes: 1 addition & 1 deletion src/scene/gui/collapsable_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl CollapsingVBoxContainer {
let mut children: Vec<Gd<Node>> = self.base_mut().get_children().iter_shared().collect();
if let Some(btn) = &self.heading {
let btn_base = &btn.clone().upcast::<Node>();
children = children.into_iter().filter(|p| p != btn_base).collect();
children.retain(|p| p != btn_base);
}
for child in children {
if let Ok(control) = &mut child.clone().try_cast::<Control>() {
Expand Down
5 changes: 5 additions & 0 deletions src/scene/state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! # State Machines
//! For Godot 4.2 earlier, you have to manually remember the functions "tick", "on_enter", and "on_exit" as those are the string name values that are checked for in the states.
//! > From Godot 4.3+, support for virtual functions will have been reached which will allow a refactor that makes extending the base class functions significantly easier.
//!
//! For now just remember to keep your function names in order and everything should be fine
use godot::prelude::*;

const METHOD_TICK: &str = "tick";
Expand Down

0 comments on commit 9f1c64b

Please sign in to comment.