Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic overmap #15

Merged
merged 23 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LevelGenerator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func generate_level():
if level_name == "":
get_level_json()
else:
get_custom_level_json("user://levels/" + level_name)
get_custom_level_json("./Mods/Core/Maps/" + level_name)


var level_number = 0
Expand Down Expand Up @@ -125,6 +125,7 @@ func load_tiles_material():
var texture := load("res://Mods/Core/Tiles/" + file_name) # Load the .png file as a texture
var material := StandardMaterial3D.new()
material.albedo_texture = texture # Set the texture of the material
material.uv1_scale = Vector3(3,2,1)
tile_materials[file_name] = material # Add the material to the dictionary
file_name = dir.get_next()
else:
Expand Down
1 change: 1 addition & 0 deletions Mods/Core/Maps/urbanroad.json

Large diffs are not rendered by default.

Binary file added Mods/Core/OvermapTiles/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/OvermapTiles/1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b1rxkkr3qwoa1"
path="res://.godot/imported/1.png-113fc203e924f41987258f7bf69b8dab.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/OvermapTiles/1.png"
dest_files=["res://.godot/imported/1.png-113fc203e924f41987258f7bf69b8dab.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added Mods/Core/OvermapTiles/arcstones1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/OvermapTiles/arcstones1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://br51vko5o7o6e"
path="res://.godot/imported/arcstones1.png-f1c80d77cdb940353593822e678fe7c8.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/OvermapTiles/arcstones1.png"
dest_files=["res://.godot/imported/arcstones1.png-f1c80d77cdb940353593822e678fe7c8.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added Mods/Core/OvermapTiles/forestunderbrushscale5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/OvermapTiles/forestunderbrushscale5.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://d0gnamhtqsiv3"
path="res://.godot/imported/forestunderbrushscale5.png-9156c85412ee766dbe54fbf681864d15.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/OvermapTiles/forestunderbrushscale5.png"
dest_files=["res://.godot/imported/forestunderbrushscale5.png-9156c85412ee766dbe54fbf681864d15.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added Mods/Core/OvermapTiles/rockyfloor4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/OvermapTiles/rockyfloor4.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://ivc6violj6vr"
path="res://.godot/imported/rockyfloor4.png-91f26024c21cf174dcff99a521b7fd55.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/OvermapTiles/rockyfloor4.png"
dest_files=["res://.godot/imported/rockyfloor4.png-91f26024c21cf174dcff99a521b7fd55.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
1 change: 1 addition & 0 deletions Mods/Core/Tiles/Tiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"categories":["Ground"],"description":"Field of grass","id":"grass_plain","imagePath":"res://Mods/Core/Tiles/1.png","name":"Plain grass\t"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_00","imagePath":"res://Mods/Core/Tiles/woodboards.png","name":"Low quality wood floor"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_01","imagePath":"res://Mods/Core/Tiles/woodboards1.png","name":"Low quality wood floor"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_02","imagePath":"res://Mods/Core/Tiles/woodboards2.png","name":"Low quality wood floor"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_dark_00","imagePath":"res://Mods/Core/Tiles/woodboards3.png","name":"Low quality wood floor"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_dark_01","imagePath":"res://Mods/Core/Tiles/woodboards4.png","name":"Low quality wood floor"},{"categories":["Floor"],"description":"The floor is old and the boards are crooked","id":"floor_wood_shabby_dark_02","imagePath":"res://Mods/Core/Tiles/woodboards5.png","name":"Low quality wood floor"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on","id":"road_asphalt_basic","imagePath":"res://Mods/Core/Tiles/asphalt_basic.png","name":"Basic asphalt road"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has diagonal markings","id":"road_asphalt_diagonal","imagePath":"res://Mods/Core/Tiles/asphalt_diag_middle.png","name":"Asphalt road with diagonal markings"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has markings indicating a west turn","id":"road_asphalt_turn_west","imagePath":"res://Mods/Core/Tiles/asphalt_horizontal_middle_downleft.png","name":"Asphalt road with markings turning west"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has markings indicating a east turn","id":"road_asphalt_turn_east","imagePath":"res://Mods/Core/Tiles/asphalt_horizontal_middle_upright.png","name":"Asphalt road with markings turning east"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has vertical markings","id":"road_asphalt_vertical","imagePath":"res://Mods/Core/Tiles/asphalt_middle.png","name":"Asphalt road with vertical markings"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has markings indicating a north turn","id":"road_asphalt_turn_north","imagePath":"res://Mods/Core/Tiles/asphalt_middle_downleft.png","name":"Asphalt road with markings turning north"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has horizontal markings","id":"road_asphalt_horizontal","imagePath":"res://Mods/Core/Tiles/asphalt_middle_horizontal.png","name":"Asphalt road with horizontal markings"},{"categories":["Road"],"description":"A smooth surface for vehicles to drive on. It has markings indicating a south turn","id":"road_asphalt_turn_south","imagePath":"res://Mods/Core/Tiles/asphalt_middle_upright.png","name":"Asphalt road with markings turning south"},{"categories":["Floor","Urban"],"description":"A stone floor wihere the stones are shaped like an arch. Used in an urban environement.","id":"arc_stones_floor","imagePath":"res://Mods/Core/Tiles/arcstones.png","name":"Arc stones floor"},{"categories":["Ground"],"description":"Field of grass","id":"grass_plain_01","imagePath":"res://Mods/Core/Tiles/basegrass1.png","name":"Plain grass\t"}]
139 changes: 139 additions & 0 deletions Scenes/ContentManager/Custom_Editors/Scripts/TerrainTileEditor.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
extends Control

#This scene is intended to be used inside the content editor
#It is supposed to edit exactly one tile
#It expects to save the data to a JSON file that contains all tile data from a mod
#To load data, provide the name of the tile data file and an ID


@onready var tileBrush: PackedScene = preload("res://Scenes/ContentManager/Mapeditor/tilebrush.tscn")

@export var tileImageDisplay: TextureRect = null
@export var IDTextLabel: Label = null
@export var NameTextEdit: TextEdit = null
@export var DescriptionTextEdit: TextEdit = null
@export var CategoriesList: Control = null
@export var tileSelector: Popup = null
@export var tileBrushList: HFlowContainer = null
@export var tilePathStringLabel: Label = null

#The JSON file to be edited
var contentSource: String = "":
set(value):
contentSource = value
load_tile_data()
load_Brush_List()

#This function will find an item in the contentSource JSOn file with an iD that is equal to self.name
#If an item is found, it will set all the elements in the editor with the corresponding values
func load_tile_data():
if not FileAccess.file_exists(contentSource):
return

var file = FileAccess.open(contentSource, FileAccess.READ)
var data = JSON.parse_string(file.get_as_text())
file.close()

for item in data:
if item["id"] == self.name:
if tileImageDisplay != null and item.has("imagePath"):
tileImageDisplay.texture = load(item["imagePath"])
tilePathStringLabel.text = item["imagePath"]
if IDTextLabel != null:
IDTextLabel.text = str(item["id"])
if NameTextEdit != null and item.has("name"):
NameTextEdit.text = item["name"]
if DescriptionTextEdit != null and item.has("description"):
DescriptionTextEdit.text = item["description"]
if CategoriesList != null and item.has("categories"):
CategoriesList.clear_list()
for category in item["categories"]:
CategoriesList.add_item_to_list(category)
break


#The editor is closed, destroy the instance
#TODO: Check for unsaved changes
func _on_close_button_button_up():
queue_free()

#This function takes all data fro the form elements and writes it to the contentSource JSON file.
func _on_save_button_button_up():
var file = FileAccess.open(contentSource, FileAccess.READ_WRITE)
var data = JSON.parse_string(file.get_as_text())
file.close()

for item in data:
if item["id"] == IDTextLabel.text:
item["imagePath"] = tileImageDisplay.texture.resource_path
item["name"] = NameTextEdit.text
item["description"] = DescriptionTextEdit.text
item["categories"] = CategoriesList.get_items()
break

file = FileAccess.open(contentSource, FileAccess.WRITE)
file.store_string(JSON.stringify(data))
file.close()


#When the tileImageDisplay is clicked, the user will be prompted to select an image from
# "res://Mods/Core/Tiles/". The texture of the tileImageDisplay will change to the selected image
func _on_tile_image_display_gui_input(event):
if event is InputEventMouseButton and event.pressed:
tileSelector.show()


# this function will read all files in "res://Mods/Core/Tiles/" and for each file it will create a texturerect and assign the file as the texture of the texturerect. Then it will add the texturerect as a child to $HSplitContainer/EntitiesContainer/TilesList
func load_Brush_List():
var tilesDir = "res://Mods/Core/Tiles/"

var dir = DirAccess.open(tilesDir)
if dir:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
var extension = file_name.get_extension()

if !dir.current_is_dir():
if extension == "png":
# Create a TextureRect node
var brushInstance = tileBrush.instantiate()

# Load the texture from file
var texture: Resource = load(tilesDir + file_name)

# Assign the texture to the TextureRect
brushInstance.set_tile_texture(texture)
brushInstance.set_meta("path", tilesDir + file_name)
brushInstance.tilebrush_clicked.connect(tilebrush_clicked)

# Add the TextureRect as a child to the TilesList
tileBrushList.add_child(brushInstance)
file_name = dir.get_next()
else:
print_debug("An error occurred when trying to access the path.")
dir.list_dir_end()

#Called after the user selects a tile in the popup textbox and presses OK
func _on_ok_button_up():
tileSelector.hide()
var children = tileBrushList.get_children()
for child in children:
if child.selected:
tileImageDisplay.texture = load(child.get_meta("path"))
tilePathStringLabel.text = child.get_meta("path")

#Called after the users presses cancel on the popup asking for a tile
func _on_cancel_button_up():
tileSelector.hide()

func deselect_all_brushes():
var children = tileBrushList.get_children()
for child in children:
child.set_selected(false)

#Mark the clicked tilebrush as selected, but only after deselecting all other brushes
func tilebrush_clicked(tilebrush: Control) -> void:
deselect_all_brushes()
# If the clicked brush was not select it, we select it. Otherwise we deselect it
tilebrush.set_selected(true)
Loading