diff --git a/project/blocky_game/blocks/block.gd b/project/blocky_game/blocks/block.gd index 00b1144..3158079 100644 --- a/project/blocky_game/blocks/block.gd +++ b/project/blocky_game/blocks/block.gd @@ -15,7 +15,7 @@ class BaseInfo: var transparent := false var backface_culling := true # TODO Rename `variants` - var voxels := [] + var voxels := PackedInt32Array() var base_info := BaseInfo.new() diff --git a/project/blocky_game/blocks/blocks.gd b/project/blocky_game/blocks/blocks.gd index a2b8dd4..476171d 100644 --- a/project/blocky_game/blocks/blocks.gd +++ b/project/blocky_game/blocks/blocks.gd @@ -17,14 +17,14 @@ const ROTATION_Y_POSITIVE_X = 1 const ROTATION_Y_NEGATIVE_Z = 2 const ROTATION_Y_POSITIVE_Z = 3 -const _opposite_y_rotation = [ +const _opposite_y_rotation : Array[int] = [ ROTATION_Y_POSITIVE_X, ROTATION_Y_NEGATIVE_X, ROTATION_Y_POSITIVE_Z, ROTATION_Y_NEGATIVE_Z ] -const _y_dir = [ +const _y_dir : Array[Vector3] = [ Vector3(-1, 0, 0), Vector3(1, 0, 0), Vector3(0, 0, -1), @@ -194,17 +194,17 @@ func _create_block(params: Dictionary): block = Block.new() # Fill in base info - var base_info = block.base_info + var base_info := block.base_info base_info.id = len(_blocks) for i in len(params.voxels): - var vname = params.voxels[i] - var id = _voxel_library.get_voxel_index_from_name(vname) + var vname : String = params.voxels[i] + var id := _voxel_library.get_voxel_index_from_name(vname) if id == -1: push_error("Could not find voxel named {0}".format([vname])) assert(id != -1) params.voxels[i] = id - var rm = RawMapping.new() + var rm := RawMapping.new() rm.block_id = base_info.id rm.variant_index = i if id >= len(_raw_mappings): @@ -219,7 +219,7 @@ func _create_block(params: Dictionary): base_info.backface_culling = params.backface_culling if base_info.directory != "": base_info.gui_model_path = str(ROOT, "/", params.directory, "/", params.gui_model) - var sprite_path = str(ROOT, "/", params.directory, "/", params.name, "_sprite.png") + var sprite_path := str(ROOT, "/", params.directory, "/", params.name, "_sprite.png") base_info.sprite_texture = load(sprite_path) _blocks.append(block) @@ -232,7 +232,7 @@ func _notification(what): print("Deleting blocks.gd") -static func _defaults(d, defaults): +static func _defaults(d: Dictionary, defaults: Dictionary): for k in defaults: if not d.has(k): d[k] = defaults[k] diff --git a/project/blocky_game/gui/block_sprite_generator.gd b/project/blocky_game/gui/block_sprite_generator.gd index 9ec6d46..9a27779 100644 --- a/project/blocky_game/gui/block_sprite_generator.gd +++ b/project/blocky_game/gui/block_sprite_generator.gd @@ -1,12 +1,13 @@ extends Node const Blocks = preload("../blocks/blocks.gd") +const Block = Blocks.Block -const _materials = [ - preload("res://blocky_game/blocks/terrain_material.tres"), - preload("res://blocky_game/blocks/terrain_material_transparent.tres"), - preload("res://blocky_game/blocks/terrain_material_foliage.tres") -] +#const _materials : Array[Material] = [ + #preload("res://blocky_game/blocks/terrain_material.tres"), + #preload("res://blocky_game/blocks/terrain_material_transparent.tres"), + #preload("res://blocky_game/blocks/terrain_material_foliage.tres") +#] @onready var _viewport : SubViewport = $SubViewport @onready var _mesh_instance : MeshInstance3D = $SubViewport/MeshInstance3D @@ -23,15 +24,15 @@ func _process(_delta): print("Block ", _current_block_id) if _current_block_id != -1: - var block : Blocks.Block = _blocks.get_block(_current_block_id) + var block : Block.BaseInfo = _blocks.get_block(_current_block_id).base_info if block.directory != "": # Grab result of previous render var viewport_texture := _viewport.get_texture() var im := viewport_texture.get_image() im.convert(Image.FORMAT_RGBA8) var fpath := \ - str(Blocks.ROOT, "/", block.directory, "/", block.name, "_sprite.png") - var err = im.save_png(fpath) + str(Blocks.ROOT, "/", block.directory, "/", block.name, "_sprite2.png") + var err := im.save_png(fpath) if err != OK: push_error(str("Could not save ", fpath, ", error ", err)) else: @@ -41,13 +42,13 @@ func _process(_delta): if _current_block_id < _blocks.get_block_count(): # Setup next block for rendering - var block = _blocks.get_block(_current_block_id) + var block : Block.BaseInfo = _blocks.get_block(_current_block_id).base_info if block.directory != "": - var gui_mesh = load(block.gui_model_path) + var gui_mesh : Mesh = load(block.gui_model_path) _mesh_instance.mesh = gui_mesh var lib := _blocks.get_model_library() - var model = lib.get_voxel(block.voxels[0]) - var mat = _materials[model.material_id] + var model := lib.get_model(block.voxels[0]) + var mat := model.get_material_override(0) _mesh_instance.material_override = mat else: diff --git a/project/blocky_game/gui/block_sprite_generator.tscn b/project/blocky_game/gui/block_sprite_generator.tscn index 936c083..8136be0 100644 --- a/project/blocky_game/gui/block_sprite_generator.tscn +++ b/project/blocky_game/gui/block_sprite_generator.tscn @@ -1,14 +1,29 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=5 format=3 uid="uid://0tp72w52ddwh"] -[ext_resource path="res://blocky_game/gui/block_sprite_generator.gd" type="Script" id=1] +[ext_resource type="Script" path="res://blocky_game/gui/block_sprite_generator.gd" id="1"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ga5ik"] +sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) +ground_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) + +[sub_resource type="Sky" id="Sky_lbffk"] +sky_material = SubResource("ProceduralSkyMaterial_ga5ik") + +[sub_resource type="Environment" id="Environment_vbpqs"] +background_mode = 2 +sky = SubResource("Sky_lbffk") +tonemap_mode = 2 +glow_enabled = true [node name="Node" type="Node"] -script = ExtResource( 1 ) +script = ExtResource("1") + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_vbpqs") [node name="SubViewport" type="SubViewport" parent="."] -size = Vector2(128, 128) transparent_bg = true -render_target_v_flip = true +size = Vector2i(128, 128) render_target_update_mode = 3 [node name="Camera3D" type="Camera3D" parent="SubViewport"] @@ -22,9 +37,6 @@ size = 1.62453 [node name="CSGBox3D" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.5, 0.5) visible = false -width = 1.0 -height = 1.0 -depth = 1.0 [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(0.90295, -0.173518, -0.393157, 0.424509, 0.502534, 0.753162, 0.0668873, -0.846966, 0.527423, 3.45617, 1.75451, 0)