Skip to content

Commit

Permalink
Some static typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed May 12, 2024
1 parent ea1a6b9 commit 386c906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 11 additions & 9 deletions addons/zylann.hterrain/hterrain_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,10 @@ func _edit_add_map(map_type: int) -> int:
_logger.debug(str("Adding map of type ", get_channel_name(map_type)))
while map_type >= len(_maps):
_maps.append([])
var maps = _maps[map_type]
var map = HT_Map.new(_get_free_id(map_type))
var maps : Array = _maps[map_type]
var map := HT_Map.new(_get_free_id(map_type))
map.image = Image.create(_resolution, _resolution, false, get_channel_format(map_type))
var index = len(maps)
var index := maps.size()
var default_color = _get_map_default_fill_color(map_type, index)
if default_color != null:
map.image.fill(default_color)
Expand All @@ -769,14 +769,15 @@ func _edit_add_map(map_type: int) -> int:
return index


# Editor-only. Used for undo/redo.
func _edit_insert_map_from_image_cache(map_type: int, index: int, image_cache, image_id: int):
if _edit_disable_apply_undo:
return
_logger.debug(str("Adding map of type ", get_channel_name(map_type),
" from an image at index ", index))
while map_type >= len(_maps):
_maps.append([])
var maps = _maps[map_type]
var maps : Array = _maps[map_type]
var map := HT_Map.new(_get_free_id(map_type))
map.image = image_cache.load_image(image_id)
maps.insert(index, map)
Expand All @@ -792,24 +793,25 @@ func _edit_remove_map(map_type: int, index: int):


func _get_free_id(map_type: int) -> int:
var maps = _maps[map_type]
var id = 0
var maps : Array = _maps[map_type]
var id := 0
while _get_map_by_id(map_type, id) != null:
id += 1
return id


func _get_map_by_id(map_type: int, id: int) -> HT_Map:
var maps = _maps[map_type]
var maps : Array = _maps[map_type]
for map in maps:
if map.id == id:
return map
return null


func get_image(map_type: int, index := 0) -> Image:
var maps = _maps[map_type]
return maps[index].image
var maps : Array = _maps[map_type]
var map : HT_Map = maps[index]
return map.image


func get_texture(map_type: int, index := 0, writable := false) -> Texture:
Expand Down
4 changes: 3 additions & 1 deletion addons/zylann.hterrain/hterrain_detail_layer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ func _enter_tree():
#if _auto_pick_index_on_enter_tree:
# _auto_pick_index_on_enter_tree = false
# _auto_pick_index()


# Register this detail layer in the terrain node (this does not create a new layer)
terrain._internal_add_detail_layer(self)

_update_material()
Expand All @@ -207,6 +208,7 @@ func _exit_tree():
var terrain = _get_terrain()
if terrain != null:
terrain.transform_changed.disconnect(_on_terrain_transform_changed)
# Unregister from terrain
terrain._internal_remove_detail_layer(self)
_update_material()
for k in _chunks.keys():
Expand Down

0 comments on commit 386c906

Please sign in to comment.