fix minimap colors

This commit is contained in:
Antti Hakkarainen 2023-02-14 11:29:05 +02:00
parent 57d47c5eed
commit 63ea78592a
10 changed files with 155 additions and 92 deletions

View file

@ -44,8 +44,8 @@ func _unhandled_input(event):
camera_zoom_in()
if event.is_action_pressed("camera_zoom_out"):
camera_zoom_out()
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if !is_panning_camera and event.pressed:
is_panning_camera = true
if is_panning_camera and !event.pressed:

View file

@ -22,7 +22,6 @@ var exit_thread = false
var _timer:Timer
func _exit_tree():
mutex.lock()
exit_thread = true
@ -35,6 +34,22 @@ func _exit_tree():
func _init() -> void:
self.name = "ChunkHandler"
func _on_main_worldgen_ready():
thread.start(start_chunkgen, Thread.PRIORITY_NORMAL)
# chunk cleanup timer
_timer = Timer.new()
add_child(_timer)
_timer.connect("timeout", _on_timer_timeout, 0)
_timer.set_wait_time(0.05)
_timer.set_one_shot(false)
_timer.start()
func _on_timer_timeout():
clean_up_chunks()
func _process(_delta):
update_chunks()
@ -46,17 +61,7 @@ func _ready():
exit_thread = false
thread = Thread.new()
thread.start(start_chunkgen, Thread.PRIORITY_NORMAL)
_timer = Timer.new()
add_child(_timer)
_timer.connect("timeout", _on_timer_timeout, 0)
_timer.set_wait_time(0.05)
_timer.set_one_shot(false)
_timer.start()
func _on_timer_timeout():
clean_up_chunks()
func start_chunkgen():
while true:

View file

@ -3,7 +3,7 @@ extends Control
# var view = get_node("../View")
signal button_pressed(button_name)
@onready var debug_info = get_node(Globals.DEBUGINFO_NODE)
@onready var debug_info = get_node("DebugContainer/" + Globals.DEBUGINFO_NODE)
@onready var minimap:Minimap
# name, position

View file

@ -1,10 +1,31 @@
# File contains global variables or constants so they all are in one place instead
# of a million files. So you can adjust them easily from one place if needed.
# of a million files. So you can adjust them "easily" from one place if needed.
extends Node
var chunks_loaded:int = 0
var worlgen_ready:bool = false
###################################
# FILE PATHS #
###################################
const SCENE_PATH:String = "res://scenes/"
const ART_PATH:String = "res://art/"
const SCRIPT_PATH:String = "res://scripts"
###################################
# MINIMAP SETTINGS #
###################################
var minimap_colors:Dictionary = {
Globals.TILE_WATER : Color8(42, 31, 255),
Globals.TILE_TERRAIN: Color8(148, 113, 71),
Globals.TILE_FOREST: Color8(0,123,19),
"default": Color8(255,0,255),
}
###################################
# CHUNK AND TERRAIN SETTINGS #
@ -29,10 +50,15 @@ var map_terrain_data:Array[Array] = [[]]
# preprocess and store exact tile for every map cell to speed up setting tiles
var map_tile_data:Array[Array] = [[]]
###################################
# CAMERA SETTINGS #
###################################
# GAME WINDOW DEFAULT SIZE
const DEFAULT_X_RES:int = 1920
const DEFAULT_Y_RES:int = 1080
# current camera zoom level
var CAMERA_ZOOM_LEVEL: float = 1.0
var CAMERA_POSITION
@ -44,10 +70,10 @@ const CAMERA_ZOOM_FACTOR: float = 0.1
const CAMERA_ZOOM_DURATION: float = 0.1
const CAMERA_PAN_MULTI:float = 2.0
# FILE PATHS
const SCENE_PATH:String = "res://scenes/"
const ART_PATH:String = "res://art/"
const SCRIPT_PATH:String = "res://scripts"
###################################
# UI ELEMENT SETTINGS #
###################################
# NODE NAMES
const WORLD_NODE:String = "World"
@ -58,10 +84,6 @@ const GUI_BUILD_BUTTON_SIZE_X: int = 50
const GUI_BUILD_BUTTON_SIZE_Y: int = 50
const GUI_BUILD_BUTTON_SIZE: Vector2i = Vector2i(GUI_BUILD_BUTTON_SIZE_X,GUI_BUILD_BUTTON_SIZE_Y)
# GAME WINDOW DEFAULT SIZE
const DEFAULT_X_RES:int = 1920
const DEFAULT_Y_RES:int = 1080
# maybe should use int for these instead for faster matching?
const TYPE_RESIDENTIAL:String = "residential"
const TYPE_COMMERCIAL:String = "commercial"
@ -72,9 +94,14 @@ const TYPE_POWERPLANT:String = "powerplant"
const TYPE_ROADS:String = "roads"
const TYPE_DEMOLISH:String = "demolish"
###################################
# WORLD GENERATION SETTINGS #
###################################
# city map generation file should have black ground (0,0,0) and white water (1,1,1)
const GROUND_TILE_COLOR_IN_MAP_FILE: Color = Color(0,0,0,1)
const WATER_TILE_COLOR_IN_MAP_FILE: Color = Color(1,1,1,1)
const GROUND_TILE_COLOR_IN_MAP_FILE: Color = Color(0,0,0)
const WATER_TILE_COLOR_IN_MAP_FILE: Color = Color(1,1,1)
# min and max sizes for a map so the map won't be unreasonably small or large
const MAP_MIN_HEIGHT:int = 128
@ -135,6 +162,11 @@ var td = {
"key": [Vector2i(0,0)]
}
}
###################################
# GAME ERORR MESSAGES #
###################################
# error messages
const ERROR_BUILDING_TYPE_NOT_SET:String = "Building type not set, while trying to place building."

View file

@ -20,11 +20,9 @@ var map_filenames:Array = [
"res://maps/tampere_256px.png",
"res://maps/tampere_10x10km_4096px.png"
]
var map_filename:String = map_filenames[2]
var _world_generator:WorldGenerator
var _chunk_handler:ChunkHandler
#var _2d_camera:CameraZoom2D
var map_filename:String = map_filenames[4]
var _world_generator:WorldGenerator
func _init():
# DisplayServer.window_set_size(
@ -36,21 +34,16 @@ func _init():
# Called when the node enters the scene tree for the first time.
func _ready():
# create a new world and worldgenerator
# create a new world with worldgenerator
_world_generator = WorldGenerator.new()
#_2d_camera = CameraZoom2D.new()
# add chunk handler if worldgen was successful
if _world_generator.generate_world(map_filename):
Globals.worlgen_ready = true
else:
push_error("World generation failed :-(")
_chunk_handler = ChunkHandler.new()
add_child(_chunk_handler)
if !_world_generator.generate_world(map_filename):
push_error("World generation failed :-(")
quit_game()
# connections are made from GUI
# tell other classes they can start working after loading is done
emit_signal("worldgen_ready")
# center camera to world map
emit_signal(
"set_camera_position",
@ -60,6 +53,5 @@ func _ready():
func quit_game():
get_tree().get_root().propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
#SceneTree.quit

View file

@ -1,5 +1,5 @@
class_name Minimap
extends Node
extends Control
@onready var minimap_texture:ImageTexture = null
@onready var sprite:Sprite2D
@ -15,15 +15,14 @@ func _process(_delta):
func _on_main_worldgen_ready():
print("test")
self.generate_minimap()
self.set_minimap()
func generate_minimap() -> void:
func generate_minimap() -> void:
var image = Image.new()
print(Globals.map_size)
image = Image.create(Globals.map_size, Globals.map_size, false, Image.FORMAT_RGB8)
image = Image.create(Globals.map_size, Globals.map_size, false, Image.FORMAT_RGBAF)
image.resize(Globals.map_size, Globals.map_size)
for y in Globals.map_size:
for x in Globals.map_size:
@ -31,24 +30,35 @@ func generate_minimap() -> void:
match Globals.map_terrain_data[y][x]:
Globals.TILE_WATER:
color = Color(0,0,255)
Globals.TILE_TERRAIN:
color = Color(148,113,71)
color = Globals.minimap_colors.get(Globals.TILE_WATER)
Globals.TILE_TERRAIN:
color = Globals.minimap_colors.get(Globals.TILE_TERRAIN)
Globals.TILE_FOREST:
color = Color(0,255,0)
color = Globals.minimap_colors.get(Globals.TILE_FOREST)
_: #default
color = Color(255,0,255)
color = Globals.minimap_colors.get("default")
image.set_pixel(x, y, color)
minimap_texture = ImageTexture.create_from_image(image)
minimap_texture = ImageTexture.create_from_image(image)
func set_minimap() -> void:
sprite = self.get_child(1)
sprite.texture = minimap_texture
sprite.set_scale(Vector2i(2,2))
sprite.set_position(Vector2(0, 0))
# Assuming the area has a child CollisionShape2D with a RectangleShape resource
var area_size = self.get_rect()
area_size = area_size.size
# The size of a sprite is determined from its texture
var texture_size = sprite.texture.get_size()
# Calculate which scale the sprite should have to match the size of the area
var sx = area_size.x / texture_size.x
var sy = area_size.y / texture_size.y
sprite.scale = Vector2(sx, sy)

View file

@ -101,7 +101,7 @@ func generate_world(filename) -> bool:
return false
if (image.get_size().x / image.get_size().y) != 1:
push_error("Error: image size was invalidin world generator")
push_error("Error: image size was invalid in world generator")
return false
image_size = image.get_size()