Skip to content

Commit

Permalink
Merge branch 'feature-kids'
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Jan 23, 2020
2 parents d0cfc9f + a9c9e9b commit 44139a8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 213 deletions.
34 changes: 34 additions & 0 deletions icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
196 changes: 5 additions & 191 deletions src/Branch.tscn
Original file line number Diff line number Diff line change
@@ -1,203 +1,17 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://assets/antler.jpg" type="Texture" id=1]

[sub_resource type="GDScript" id=1]
script/source = "extends Control

# Declare member variables here. Examples:
# var a = 2
# var b = \"text\"

var child
var parents = []

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

func setIndividuals(_child, _parents):
if _child:
child = _child
if _parents:
parents = _parents

calcPositions()

func calcPositions():
var parent_positions = []
var child_positions = []
var child_box_size

if child:
child_box_size = Vector2(0, child.getRect().size.y/2)
child_positions.append(child.rect_position - child_box_size/1.5)
else:
child_box_size = Vector2(0, 200)
child_positions.append(0)

if parents[0]:
parent_positions.append(parents[0].rect_position + child_box_size/2)
else:
parent_positions.append(0)

if parents[1]:
parent_positions.append(parents[1].rect_position + child_box_size/2)
else:
parent_positions.append(0)

setPosition(child_positions, parent_positions)


func setPosition(childrenpos, parentspos):

if !childrenpos[0]:
if parentspos[0] and parentspos[1]:
childrenpos[0] = parentspos[0] + (parentspos[0] - parentspos[1])/2
else:
printerr(\"cannot render branch without parents or children\")
return false

rect_position = childrenpos[0]

if has_node(\"LineLeft\"):

var connector_right = get_node(\"LineRight\")
var connector_left = get_node(\"LineLeft\")
var relative_right = Vector2(0,0)
var relative_left = Vector2(0,0)

if parentspos[0]:
relative_left = parentspos[0] - childrenpos[0]

if parentspos[1]:
relative_right = parentspos[1] - childrenpos[0]

connector_right.width = 140
connector_left.width = 140

if relative_right != Vector2(0,0):
connector_right.points = PoolVector2Array(get_points(Vector2(0, 0), relative_right))
connector_right.show()
else:
connector_right.hide()

if relative_left != Vector2(0,0):
connector_left.points = PoolVector2Array(get_points(Vector2(0, 0), relative_left))
connector_left.show()
else:
connector_left.hide()

#
# get_node(\"Line2D\").position = childrenpos[0]
#
# var maxpoints = get_node(\"Line2D\").points.size()
#
# if parentspos[0]:
# get_points
# get_node(\"Line2D\").points[0] = parentspos[0] - childrenpos[0]
#
# if parentspos[1]:
# get_node(\"Line2D\").points[maxpoints-1] = parentspos[1] - childrenpos[0]
else:

var connector_right = get_node(\"ConnectorRight\")
var connector_left = get_node(\"ConnectorLeft\")
var relative_right = Vector2(0,0)
var relative_left = Vector2(0,0)

if parentspos[0]:
relative_left = parentspos[0] - childrenpos[0]

if parentspos[1]:
relative_right = parentspos[1] - childrenpos[0]

var all_polygons

if relative_right != Vector2(0,0):
all_polygons = get_polygons(Vector2(0, 0), relative_right)
connector_right.polygon = PoolVector2Array(all_polygons[0])
connector_right.uv = PoolVector2Array(all_polygons[1])
connector_right.show()
else:
connector_right.hide()

if relative_left != Vector2(0,0):
all_polygons = get_polygons(relative_left, Vector2(0, 0))
connector_left.polygon = PoolVector2Array(all_polygons[0])
connector_left.uv = PoolVector2Array(all_polygons[1])
connector_left.show()
else:
connector_left.hide()

func get_points(from: Vector2, to: Vector2):
var points = []

var step_width = 80

var polycount = max(1, floor(from.distance_to(to) / step_width))
step_width = floor((to-from).x / polycount)

var new_point

# print(\"from: \", from, \" to: \", to, \" polycount: \", polycount, \" ratio: \", ratio, \" thickness: \", thickness)

randomize()

# way from top left to top middle
for i in range(polycount+1):
new_point = lerp(from, to, i/polycount) + rand_vector()
points.append(new_point)

return points

func get_polygons(from : Vector2, to : Vector2):
var polygon_points = []
var uv_points = []

var step_width = 80
var thickness

var polycount = max(1, floor(from.distance_to(to) / step_width))
step_width = floor((to-from).x / polycount)

var ratio = from.distance_to(to) / to.distance_to(from)

thickness = clamp(abs(ratio), 0.6, 2) * sign(ratio) * 100

var new_point

# print(\"from: \", from, \" to: \", to, \" polycount: \", polycount, \" ratio: \", ratio, \" thickness: \", thickness)

randomize()

# way from top left to top middle
for i in range(polycount+1):
new_point = lerp(from, to, i/polycount) + rand_vector()
polygon_points.append(new_point)
uv_points.append(new_point + rand_vector(-20, 20))

# and back from bottom middle to bottom left
for i in range(polycount+1):
new_point = lerp(to, from, i/polycount) + rand_vector() + Vector2(0, thickness)* sign(ratio)
polygon_points.append(new_point)
uv_points.append(new_point + rand_vector(-20, 20))

return [polygon_points, uv_points]


func rand_vector(rand_min = -8, rand_max = 8):
return Vector2(floor(rand_range(rand_min,rand_max)), floor(rand_range(rand_min,rand_max)))"
[ext_resource path="res://src/Branch.gd" type="Script" id=1]
[ext_resource path="res://assets/antler.jpg" type="Texture" id=2]

[node name="Branch" type="Control"]
script = SubResource( 1 )
script = ExtResource( 1 )

[node name="LineLeft" type="Line2D" parent="."]
z_index = -1
points = PoolVector2Array( -50, -10, -44.1667, -3.81437, -35.1922, -2.68076, -28.0621, -0.232655, -19.9627, -0.744202, -12.9715, 2.23981, -7.34454, 6.24692, -1.29124, 9.40145, 0, 10 )
width = 80.0
default_color = Color( 1, 1, 1, 1 )
texture = ExtResource( 1 )
texture = ExtResource( 2 )
texture_mode = 1
begin_cap_mode = 2
end_cap_mode = 2
Expand All @@ -208,7 +22,7 @@ z_index = -1
points = PoolVector2Array( 0, 10, 3.22741, 8.97517, 9.02493, 4.71229, 15.7603, 2.41033, 22.3251, 0.449406, 28.2079, 0.619923, 35.2843, -0.573685, 44.4921, -3.81347, 48.9255, -7.47955, 50, -10 )
width = 80.0
default_color = Color( 1, 1, 1, 1 )
texture = ExtResource( 1 )
texture = ExtResource( 2 )
texture_mode = 1
begin_cap_mode = 2
end_cap_mode = 2
Expand Down
1 change: 0 additions & 1 deletion src/Branch2.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[ext_resource path="res://src/Branch.gd" type="Script" id=1]
[ext_resource path="res://assets/antler.jpg" type="Texture" id=2]


[node name="Branch" type="Control"]
script = ExtResource( 1 )

Expand Down
54 changes: 42 additions & 12 deletions src/Tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ func _enter_tree():
poi.setScale( 1 )
poi.setLevel(0)
add_child(poi)
# elements, that should be moved to the center of the tree
# after alle other elements has been placed
move_to_center.append(poi)

# partner of poi goes to the right
# renderPartners(id, level, column, side, scale):
renderPartners(poi.uid, 0, 0, 1, 1)

# siblings of poit goes to the left
# renderSiblings(id, level, column, side):
renderSiblings(poi.uid, 0, 0, -1)

level_counts['level0'] = [0]

# render parents and grandparents
# renderParents(child, level, column = 0):
renderParents(poi, -1)

func _exit_tree():
Expand All @@ -42,6 +51,8 @@ func _exit_tree():
# get_child(i).queue_free()
remove_child(get_child(i))
level_counts = {}
move_to_center = []
rect_position = Vector2(0,0)

# Called when the node enters the scene tree for the first time.
func _ready():
Expand Down Expand Up @@ -96,17 +107,6 @@ func renderParents(child, level, column = 0):
side *= -1
renderBranch(child, individuals, level)

# not in use
func renderChildren(id, level):
var individuals = findChildren(id)
if individuals:
for individual in individuals:
if individual:
individual.setPosition( getFreePosition(level) )
individual.setLevel(level)
add_child(individual)
renderChildren(individual.uid, level+1)

func renderPartners(id, level, column, side, scale):
var individuals = findPartners(id)
var i = 1
Expand All @@ -124,15 +124,44 @@ func renderPartners(id, level, column, side, scale):
add_child(individual)
if level == 0:
move_to_center.append(individual)

# children are always coming from the individual in the tree
# therefor we could spare this information,
# and only show the link from which partner (who is on the tree) the kid is
# TODO
# right now only for POI kids
# maybe limit it to individual.uid AND current id (otherwise kids brought to the marrage are also listed)
# if level == 0:
# renderChildren(individual.uid, level+1, newcolumn, side)

i += 1



# TODO - branches between partner of siblings
# var family = individuals.duplicate()
# family.append(findIndividual(id))
# renderBranch(null, family)

return i-1

func renderChildren(id, level, column, side):
var individuals = findChildren(id)
if individuals:
var i = 1
for individual in individuals:
if individual:
var newcolumn = getFreePosition(level, column+ i * side, [0,0], 0)

individual.setPosition( calcPosition(level, newcolumn) )
individual.setScale( 0.65 )
individual.setLevel(level)
add_child(individual)
if level == 0:
move_to_center.append(individual)
#renderChildren(individual.uid, level+1)
i += 1

func renderSiblings(id, level, column, side):
var individuals = findSiblings(id)
if individuals:
Expand Down Expand Up @@ -247,7 +276,8 @@ func setFamilyField(index, field, value):
func addIndividual(id, personname, birth, death, occupation, location, gender):
# var node = Individual.new();
var node = Individual.instance();
node.node_init(id, personname, birth, death, occupation, location, gender, '..\\icon.png', '..')
#node.node_init(id, personname, birth, death, occupation, location, gender, '..\\icon.png', '..')
node.node_init(id, personname, birth, death, occupation, location, gender, '', '')
_individuals.append(node)
return _individuals.size()-1

Expand Down
3 changes: 2 additions & 1 deletion src/autoloads/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func read_config():
var err = config.load("settings.cfg")
if err == OK: # if not, something went wrong with the file loading
print("loading settings.cfg")
familytreeFilename = config.get_value("familytree", "filename", "Stammbaum.ged")
#familytreeFilename = config.get_value("familytree", "filename", "Stammbaum.ged")
familytreeFilename = config.get_value("familytree", "filename", "")
familytreeDirectory = config.get_value("familytree", "directory", "_familytree/")
familytreeServer = config.get_value("familytree", "server", "")
personOfInterest = config.get_value("familytree", "poi", "I1")
Expand Down
Loading

0 comments on commit 44139a8

Please sign in to comment.