reneator / godot-skill-tree Goto Github PK
View Code? Open in Web Editor NEWThis is just quickly made skill-tree in godot using tool-scripts. It refreshes the connections as you make changes to the nodes in the skill-tree
License: MIT License
This is just quickly made skill-tree in godot using tool-scripts. It refreshes the connections as you make changes to the nodes in the skill-tree
License: MIT License
Activation logic as in: When the skill-tree-node is learnt, the logic behind it is activated or at least broadcasts its activation. Including an id, so you could have effects/traits etc. that get activated as soon as a skill-node is learnt/active
I might separrate this ticket into multiple ones depending on topic. Right now this is mainly to keep notes:
As this skill-tree could be used for other things, like "weapon-leveling" "crafting-recipe-tree" "weapon-upgrade-tree" i would try to keep it generalized in a certain way. For this i have an idea to enable multiple nodes connections and the way i can define those:
(done)
~~
A node can have multiple predecessors, for which he can set up how the requirements work:
(solved by talent-rows)
This can work by having to maybe define a number of the "previous_nodes_required" or something like that.
I could do this,k by enabling the player to to define another skill-tree-node in the inspector, which would then get locked as this node gets leveled. I could also do this in a way, that it would cascade down the path and lock up all the other nodes as well.
optionals:
A node can have the cost of the previous node or node's object:
for example a weapon_upgrade-tree might require the weapon of the lower tier as a cost (as in consume it). Or maybe there is a simpler solution to it, by having the user define the item as part of the cost directly/by hand.
Maybe also have a locking-preview
Adding a cost-object that the Developer can extend upon which will have the required methods (like api):
Skill_Tree_Node.tscn and Skill_Tree_Test.tscn refer to Outline_Shader.tres, but it isn't included in the repo
Thanks for making this!
@tool
extends TextureButton
@export var previous_nodes_paths : Array[NodePath] = []#set set_previous_nodes_paths
#var previous_nodes_paths : set = set_previous_nodes_paths
var previous_nodes
@export var tree_node_line_scene: PackedScene
enum PREVIOUS_NODES_TYPE {ANY,ALL}
@export var previous_nodes_type: PREVIOUS_NODES_TYPE #any -> one skill being learned unlocks it, all -> all previous nodes have to be learned
@export var talent_row_id: String
var talent_row_nodes = []
@export var max_row_selections: int = 1
var current_row_selections_count = 0
@export var texture: Texture2D: set = set_texture
@export var on_learned_shader: ShaderMaterial
@export var _tooltip_text: String
@export var unlocked: bool = false: set = set_unlocked
@export var learned: bool = false
@export var active_tint: Color = Color(1,1,1,1)
@export var inactive_tint: Color = Color(0.6,0.6,0.6,1)
var active = false
@warning_ignore("unused_signal")
signal on_learned(node)
@warning_ignore("unused_signal")
signal on_unlocked()#node: Node)
func set_previous_nodes_paths(_paths):
previous_nodes_paths = _paths
initialize_previous_nodes_connection()
refresh_lines()
func _init():
texture_normal = texture
#tooltip_text = "Hola!" #_tooltip_text
func _ready():
tooltip_text = _tooltip_text
initialize_talent_row()
initialize_previous_nodes_connection()
refresh_lines()
func initialize_talent_row():
if Engine.is_editor_hint():
return
if not talent_row_id:
return
var group_name = "talent_row_%s" % talent_row_id
add_to_group(group_name)
var talent_row_skill_nodes = get_tree().get_nodes_in_group(group_name)
for node in talent_row_skill_nodes:
node.add_talent_row_node(self)
add_talent_row_node(node)
func add_talent_row_node(node):
if node == self:
return
if not node in talent_row_nodes:
talent_row_nodes.append(node)
node.connect("on_learned", Callable(self, "on_talent_row_learned"))
func on_talent_row_learned(_node):
current_row_selections_count += 1
if max_row_selections <= current_row_selections_count:
set_unlocked(false)
func initialize_previous_nodes_connection():
previous_nodes = []
for previous_node_path in previous_nodes_paths:
previous_nodes.append(get_node_or_null(previous_node_path))
for previous_node in previous_nodes:
if not previous_node:
return
#print("previous_node.name == ", previous_node.name)
previous_node.connect("on_learned", Callable(self, "_on_on_learned"))
#func _on_on_unlocked(node: Node) -> void:
#if get_path_to(node) in previous_nodes_paths:
#unlocked = true #set_unlocked()
#func on_learned(previous_node):
#check_unlocked()
func _on_on_learned(_node: Variant) -> void:
#print("_node.name == ", _node.name)
#pass
check_unlocked()
func check_unlocked():
match previous_nodes_type:
PREVIOUS_NODES_TYPE.ANY:
#print("Previous node type == ANY")
for previous_node in previous_nodes:
#print("previous_node.name == ", previous_node.name)
if previous_node.learned:
#print("Previous ANY type node unlocked node or nodes!")
set_unlocked(true)
return
return
PREVIOUS_NODES_TYPE.ALL:
#print("\n\nPrevious node type == ALL")
var _unlocked : = true
for previous_node in previous_nodes:
#print("previous_node.name == ", previous_node.name)
#print("previous_node.learned == ", previous_node.learned)
_unlocked = _unlocked && previous_node.learned
#print("Previous ALL type node unlocked status == ", unlocked)
set_unlocked(_unlocked)
func set_unlocked(_unlocked: bool):
unlocked = _unlocked
disabled = !unlocked
set_active(unlocked)
#emit_signal("on_unlocked", self)
print("Skill_Node %s unlocked" % name)
func set_active(_active):
active = _active
if active:
modulate = active_tint
else:
modulate = inactive_tint
func set_texture(_texture):
texture = _texture
texture_normal = texture
var lines #previous_node : line2D
func refresh_lines(): #this sets the line2d to be connected with the previous_nodes
if not lines:
lines = {}
if Engine.is_editor_hint(): # deletes old lines if we are in the editor
for node in lines:
var line = lines[node]
print("line freed")
line.queue_free()
lines = {}
for previous_node in previous_nodes:
refresh_line(previous_node)
#for the line to properly show behind the line2d the lowest nodes have to be the lowest in the tree
func refresh_line(previous_node):
if not previous_node:
return
var line = lines.get(previous_node)
if not line:
print("Line added")
line = tree_node_line_scene.instantiate()
line.position = size / 2
lines[previous_node] = line
add_child(line)
var target_pos = previous_node.global_position
var line_point = target_pos - global_position
var points = line.points
if points.size() > 1:
points.remove(1)
points.append(line_point)
line.points = points
func _get_tooltip_text():
return tooltip_text
func _on_TextureButton_pressed():
if not unlocked:
return
if learned:
return
learned = true
emit_signal("on_learned", self)
$LearnedColor.show()
print("Skill_Node %s learned" % name)
Make it so,, that the developer has a method into which he can add additional checks and conditions which will be directly used to check if the skill is unlocked or not.
Add load_state(save_dict) and save_dict() methods as to make it possible for the skill-tree-nodes to save their current state (unlocked/learned)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.