Minor improvements

This commit is contained in:
2024-09-01 12:41:08 +02:00
parent 0d37e456cb
commit 21b694d4b6
9 changed files with 83 additions and 34 deletions

View File

@@ -1,12 +1 @@
extends Node2D
@onready var gui: Gui = $Interface/Gui
@onready var planter: Planter = $Planter
func _ready() -> void:
pass # Replace with function body.
func _on_planter_seed_list_updated() -> void:
pass # Replace with function body.

View File

@@ -15,11 +15,11 @@ func set_area(need : Array):
zone_grad.set_color(0, Color.BLACK)
zone_grad.set_color(1, Color.BLACK)
var min = (float(need[0]) + GameTerrain.LEVELS_NUMBER/2)/GameTerrain.LEVELS_NUMBER
var max = (float(need[1]) + GameTerrain.LEVELS_NUMBER/2)/GameTerrain.LEVELS_NUMBER
var min_value = (float(need[0]) + float(GameTerrain.LEVELS_NUMBER)/2)/GameTerrain.LEVELS_NUMBER
var max_value = (float(need[1]) + float(GameTerrain.LEVELS_NUMBER)/2)/GameTerrain.LEVELS_NUMBER
zone_grad.add_point(min, Color(0,0,0,0))
zone_grad.add_point(max, Color.BLACK)
zone_grad.add_point(min_value, Color(0,0,0,0))
zone_grad.add_point(max_value, Color.BLACK)
var texture := GradientTexture1D.new()

View File

@@ -44,7 +44,7 @@ func check_terrain_viability() -> bool:
return false
var presence := GameTerrain.get_stat(position, GameTerrain.Stats.PRESENCE)
presence += GameTerrain.LEVELS_NUMBER / 2
presence += float(GameTerrain.LEVELS_NUMBER) / 2
if presence < parameter.presence_need[0] or presence > parameter.presence_need[1]:
return false

View File

@@ -27,7 +27,7 @@ func _ready() -> void:
seed_queue.push_front(randi_range(0, plants.size() - 1))
seed_list_updated.emit()
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
var space := get_world_2d().direct_space_state
var parameters = PhysicsPointQueryParameters2D.new()
parameters.position = camera.get_global_mouse_position()

View File

@@ -16,26 +16,24 @@ const MAP_RATIO = 8;
var sum := 0.0
signal terrain_updated
func _ready():
setup_texture(Vector3i(0, 0, -5))
func map_to_pixel(
position : Vector2
pos : Vector2
) -> Vector2i :
return Vector2i(
int(position.x / MAP_RATIO),
int(position.y / MAP_RATIO)
int(pos.x / MAP_RATIO),
int(pos.y / MAP_RATIO)
)
func is_on_map(position: Vector2) -> bool:
return position.x >= 0 and position.x <= TERRAIN_SIZE.x * MAP_RATIO and position.y >= 0 and position.y <= TERRAIN_SIZE.y * MAP_RATIO
func is_on_map(pos: Vector2) -> bool:
return pos.x >= 0 and pos.x <= TERRAIN_SIZE.x * MAP_RATIO and pos.y >= 0 and pos.y <= TERRAIN_SIZE.y * MAP_RATIO
func color_value_to_level(
color_value : float
) -> int:
return roundi(color_value*LEVELS_NUMBER) - LEVELS_NUMBER/2
return roundi(color_value*LEVELS_NUMBER) - float(LEVELS_NUMBER)/2
func color_to_levels(
color: Color
@@ -52,11 +50,11 @@ func level_to_color_value(
var limited_level = max(
min(
level,
LEVELS_NUMBER/2
float(LEVELS_NUMBER)/2
),
-LEVELS_NUMBER/2
-float(LEVELS_NUMBER)/2
)
return float(limited_level+LEVELS_NUMBER/2)/LEVELS_NUMBER
return float(limited_level+float(LEVELS_NUMBER)/2)/LEVELS_NUMBER
func levels_to_color(
levels: Vector3i
@@ -159,7 +157,6 @@ func setup_texture(
update_texture()
func update_texture():
emit_signal("terrain_updated")
texture.update(image)
func get_texture():