-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from OctoD:feat/tag_manager-additional-methods
feat: adds new TagManager methods
- Loading branch information
Showing
8 changed files
with
1,275 additions
and
2 deletions.
There are no files selected for viewing
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 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
267 changes: 267 additions & 0 deletions
267
godot/examples/tag_manager_tagpath_querying/inventory_item.gd
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 |
---|---|---|
@@ -0,0 +1,267 @@ | ||
### HUGE DISCLAIMER | ||
### DO NOT EVER DO SOMETHING LIKE THIS | ||
### This code is just for the sake of the example, doing this on a real game will hurt your feelings and will make your cat to cry | ||
|
||
@tool | ||
|
||
extends TextureRect | ||
|
||
|
||
@export var shared_tag_dictionary: TagDictionary | ||
|
||
|
||
var armor: Array[String] = [ | ||
"helm", | ||
"ring", | ||
"boots", | ||
"chestplate", | ||
"amulet", | ||
"shield" | ||
] | ||
|
||
|
||
var weapon: Array[String] = [ | ||
"axe", | ||
"knife", | ||
"sword", | ||
"wand", | ||
] | ||
|
||
var item_prefix: Array[String] = [ | ||
"shiny", | ||
"rusty", | ||
"broken", | ||
"enchanted", | ||
"mysterious", | ||
"ancient", | ||
"heavy", | ||
"light", | ||
"sharp", | ||
"blunt", | ||
"magical", | ||
"normal", | ||
"common", | ||
"uncommon", | ||
"rare", | ||
"epic", | ||
"legendary", | ||
"mythical", | ||
"godly", | ||
"divine", | ||
"unholy", | ||
"evil", | ||
"good", | ||
"neutral", | ||
"chaotic", | ||
"lawful", | ||
"fire", | ||
"water", | ||
"earth", | ||
"air", | ||
"lightning", | ||
"ice", | ||
"poison", | ||
"acid", | ||
"dark", | ||
"light", | ||
"void", | ||
"spirit", | ||
"mind", | ||
"body", | ||
"heart", | ||
"soul", | ||
"blood", | ||
"bone", | ||
"metal", | ||
"wood", | ||
"stone", | ||
"glass", | ||
"cloth", | ||
"leather", | ||
"chain", | ||
"plate", | ||
"scale", | ||
"feather", | ||
"fur", | ||
"hair", | ||
"claw", | ||
"fang", | ||
"horn", | ||
"tusk", | ||
"eye", | ||
"tooth", | ||
"tongue", | ||
"tail", | ||
"wing", | ||
"hand", | ||
"foot", | ||
"head", | ||
"neck", | ||
"shoulder", | ||
"chest", | ||
"back", | ||
"arm", | ||
"leg", | ||
"waist", | ||
"hip", | ||
"thigh", | ||
"calf", | ||
"ankle", | ||
"elbow", | ||
"wrist", | ||
"finger", | ||
"toe", | ||
"ear", | ||
"nose", | ||
"mouth", | ||
"beard", | ||
"hair", | ||
"scar", | ||
"tattoo", | ||
"mark", | ||
"symbol", | ||
"rune", | ||
"sigil", | ||
"seal", | ||
"charm", | ||
"amulet", | ||
"pendant", | ||
"necklace", | ||
"ring", | ||
"bracelet", | ||
"anklet", | ||
"belt", | ||
"bag", | ||
"pouch", | ||
"backpack", | ||
"scroll", | ||
"book", | ||
"tome", | ||
"grimoire", | ||
"codex", | ||
"tablet" | ||
] | ||
|
||
var item_suffix: Array[String] = [ | ||
"of power", | ||
"of might", | ||
"of strength", | ||
"of endurance", | ||
"of agility", | ||
"of dexterity", | ||
"of speed", | ||
"of haste", | ||
"of quickness", | ||
"of swiftness", | ||
"of accuracy", | ||
"of precision", | ||
"of skill", | ||
"of mastery", | ||
"of expertise", | ||
"of proficiency", | ||
"of knowledge", | ||
"of wisdom", | ||
"of intelligence", | ||
"of insight", | ||
"of perception", | ||
"of awareness", | ||
"of consciousness", | ||
"of enlightenment", | ||
"of clarity", | ||
"of focus", | ||
"of concentration", | ||
"of meditation", | ||
"of contemplation", | ||
"of reflection", | ||
"of thought", | ||
"of memory", | ||
"of recall", | ||
"of recollection", | ||
"of remembrance", | ||
"of forgetfulness", | ||
"of oblivion", | ||
"of amnesia", | ||
"of dementia", | ||
"of madness", | ||
"of insanity", | ||
"of lunacy", | ||
"of delirium", | ||
"of confusion", | ||
"of chaos", | ||
"of disorder", | ||
"of entropy", | ||
"of decay", | ||
"of corruption", | ||
"of pollution", | ||
"of contamination", | ||
"of infection", | ||
"of disease", | ||
"of plague", | ||
"of pestilence", | ||
"of famine", | ||
"of drought", | ||
"of flood", | ||
"of storm", | ||
"of hurricane", | ||
"of tornado", | ||
"of earthquake", | ||
"of volcano", | ||
"of eruption", | ||
"of explosion", | ||
"of implosion", | ||
"of collapse", | ||
"of ruin", | ||
"of destruction", | ||
"of annihilation", | ||
"of obliteration", | ||
"of extermination", | ||
] | ||
|
||
var item_name = "" | ||
var tag = "" | ||
|
||
|
||
func _ready(): | ||
var prefix = _get_item_prefix() | ||
var itemtype = _get_item_type() | ||
var suffix = _get_item_suffix() | ||
|
||
item_name = prefix +" "+ itemtype +" "+ suffix | ||
|
||
%Label.text = item_name | ||
self.tooltip_text = item_name | ||
|
||
tag = "item" | ||
|
||
if armor.has(itemtype): | ||
tag += "." + "armor" | ||
else: | ||
tag += "." + "weapon" | ||
|
||
tag += "." + itemtype | ||
|
||
TagManager.remove_tags(TagManager.get_tags(self), self) | ||
TagManager.add_tag(tag, self) | ||
|
||
register_tag() | ||
|
||
|
||
func _get_item_prefix() -> String: | ||
return item_prefix[randi_range(0, item_prefix.size() - 1)] | ||
|
||
|
||
func _get_item_type() -> String: | ||
var types = armor.duplicate() | ||
|
||
types.append_array(weapon) | ||
|
||
return types[randi_range(0, types.size() - 1)] | ||
|
||
|
||
func _get_item_suffix() -> String: | ||
return item_suffix[randi_range(0, item_suffix.size() - 1)] | ||
|
||
|
||
func register_tag() -> void: | ||
if shared_tag_dictionary and tag: | ||
shared_tag_dictionary.add_tag(tag) |
38 changes: 38 additions & 0 deletions
38
godot/examples/tag_manager_tagpath_querying/inventory_item.tscn
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://bqv5fslvvyqe0"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://c5xjgijg6uw1l" path="res://icon.svg" id="1_0l7ev"] | ||
[ext_resource type="Script" path="res://examples/tag_manager_tagpath_querying/inventory_item.gd" id="1_hngm6"] | ||
|
||
[sub_resource type="LabelSettings" id="LabelSettings_grb1m"] | ||
font_size = 8 | ||
|
||
[node name="TextureRect" type="TextureRect" groups=["octod_ggs_tagged_node_group"]] | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
size_flags_horizontal = 4 | ||
size_flags_vertical = 4 | ||
tooltip_text = "divine chestplate of proficiency" | ||
texture = ExtResource("1_0l7ev") | ||
stretch_mode = 4 | ||
script = ExtResource("1_hngm6") | ||
metadata/octod_ggs_tagged_node = PackedStringArray("item.armor.chestplate") | ||
|
||
[node name="Label" type="Label" parent="."] | ||
unique_name_in_owner = true | ||
layout_mode = 1 | ||
anchors_preset = 12 | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
offset_top = -12.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 0 | ||
text = "divine chestplate of proficiency" | ||
label_settings = SubResource("LabelSettings_grb1m") | ||
horizontal_alignment = 1 | ||
vertical_alignment = 2 | ||
clip_text = true | ||
text_overrun_behavior = 1 |
67 changes: 67 additions & 0 deletions
67
godot/examples/tag_manager_tagpath_querying/tag_manager_tagpath_querying.gd
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@tool | ||
|
||
extends Control | ||
|
||
|
||
@onready var tag_tree: TagTree = %TagTree | ||
@onready var tag_path_selection_container = $InventoryContainer/VBoxContainer/TagPathSelectionContainer | ||
|
||
|
||
func _get_path(tag: String) -> String: | ||
var chunks = tag.split(".") | ||
|
||
chunks.remove_at(chunks.size() - 1) | ||
|
||
return ".".join(PackedStringArray(chunks)) | ||
|
||
|
||
func _get_paths(tag_dictionary: TagDictionary) -> Array[String]: | ||
var out: Array[String] = [] | ||
|
||
for tag in tag_dictionary.tags: | ||
var path = _get_path(tag) | ||
|
||
if !out.has(path): | ||
out.append(path) | ||
|
||
out.sort() | ||
|
||
return out | ||
|
||
|
||
func _ready(): | ||
var tag_dictionary = TagDictionary.new() | ||
|
||
for child in %ItemList.get_children(): | ||
child.shared_tag_dictionary = tag_dictionary | ||
child.register_tag() | ||
|
||
tag_tree.hide_root = true | ||
tag_tree.set_selectable(true) | ||
tag_tree.set_tag_dictionary(tag_dictionary) | ||
tag_tree.set_selected_tags(tag_dictionary.tags) | ||
tag_tree.render_tree() | ||
tag_tree.item_selected.connect(_on_tag_select) | ||
|
||
for path in _get_paths(tag_dictionary): | ||
var button = Button.new() | ||
var tags = tag_dictionary.get_tags_from_path(path) | ||
|
||
button.text = "Hide all " + path + " items" | ||
|
||
button.pressed.connect(func (): | ||
for node in TagManager.get_nodes_in_tag_path(self, path): | ||
node.visible = false | ||
|
||
tag_tree.deselect_many_tags(tags) | ||
) | ||
|
||
tag_path_selection_container.add_child(button) | ||
|
||
|
||
func _on_tag_select() -> void: | ||
var selected_tags = tag_tree.get_selected_tags() | ||
|
||
for child in %ItemList.get_children(): | ||
if child is Control: | ||
child.visible = TagManager.has_some_tags(selected_tags, child) |
Oops, something went wrong.