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

refactor: remove lod scripts #35

Merged
merged 3 commits into from
Dec 30, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Changed
### Deprecated
### Removed
- Remove LOD scripts ([#35](https://github.com/MechanicalFlower/Marble/pull/35))
### Fixed
- Correct loading of sound effects for the menu ([#27](https://github.com/MechanicalFlower/Marble/pull/27))
- Include `override.cfg` in each export presets ([#28](https://github.com/MechanicalFlower/Marble/pull/28))
Expand Down
32 changes: 3 additions & 29 deletions scenes/marble.tscn
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
[gd_scene load_steps=12 format=3 uid="uid://4g5aorgnd1hu"]
[gd_scene load_steps=9 format=3 uid="uid://4g5aorgnd1hu"]

[ext_resource type="Script" path="res://scripts/marble.gd" id="1"]
[ext_resource type="Material" uid="uid://5gxm1ehx7waa" path="res://resources/materials/xray_marble.tres" id="2"]
[ext_resource type="Script" path="res://scripts/lod/lod_spatial.gd" id="2_5e2c6"]
[ext_resource type="Script" path="res://scripts/roll_sound.gd" id="4"]
[ext_resource type="AudioStream" uid="uid://3hc6gfblh3gf" path="res://assets/sounds/sfx/roll.wav" id="4_d1o80"]
[ext_resource type="AudioStream" uid="uid://b7ga03rbxi6qs" path="res://assets/sounds/sfx/hit.wav" id="6_iicuw"]
[ext_resource type="AudioStream" uid="uid://c44julexev4dj" path="res://assets/sounds/explosion/bomb.ogg" id="7_1gve1"]

[sub_resource type="SphereMesh" id="1"]
radius = 0.3
height = 0.6

[sub_resource type="SphereMesh" id="5"]
radius = 0.3
height = 0.6
radial_segments = 32
rings = 16

[sub_resource type="SphereMesh" id="4"]
radius = 0.3
height = 0.6
Expand All @@ -33,24 +22,9 @@ max_contacts_reported = 10000
contact_monitor = true
script = ExtResource("1")

[node name="LODSpatial" type="Node3D" parent="."]
script = ExtResource("2_5e2c6")

[node name="Ball-0" type="MeshInstance3D" parent="LODSpatial"]
mesh = SubResource("1")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("2")

[node name="Ball-1" type="MeshInstance3D" parent="LODSpatial"]
visible = false
mesh = SubResource("5")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("2")

[node name="Ball-2" type="MeshInstance3D" parent="LODSpatial"]
visible = false
[node name="Ball" type="MeshInstance3D" parent="."]
unique_name_in_owner = true
mesh = SubResource("4")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("2")

[node name="CollisionShape" type="CollisionShape3D" parent="."]
Expand Down
51 changes: 0 additions & 51 deletions scripts/lod/lod_particles.gd

This file was deleted.

85 changes: 0 additions & 85 deletions scripts/lod/lod_spatial.gd

This file was deleted.

20 changes: 13 additions & 7 deletions scripts/main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class_name Main

extends Node

enum State { MODE_START, MODE_PAUSE, MODE_MARBLE }
Expand Down Expand Up @@ -77,7 +76,7 @@ func _unhandled_input(event):
)

else:
print("Could not place start marble")
printerr("No marble to focus on!")

KEY_ESCAPE:
if _mode != State.MODE_START and _mode != State.MODE_PAUSE:
Expand Down Expand Up @@ -114,19 +113,21 @@ func _unhandled_input(event):
break


# Reset marble positions
func reset_position() -> void:
_positions = []
for i in range(7):
for j in range(2):
_positions.append([i, j])


# Try placing a new marble on the start line
func try_place_start_marble() -> Marble:
var piece = get_highest_piece()
if piece == null:
return null
if len(_positions) == 0:
print("There are limited places to ensure equality among the marbles.")
printerr("There are limited places to ensure equality among the marbles.")
return null
randomize()
var position = _positions.pop_at(randi() % len(_positions))
Expand All @@ -150,6 +151,7 @@ func try_place_start_marble() -> Marble:
return new_marble


# Get the highest piece in the race
func get_highest_piece() -> Piece:
var pieces = _race.get_children()
if len(pieces) == 0:
Expand All @@ -161,8 +163,9 @@ func get_highest_piece() -> Piece:
return highest_piece


# Replace cameras with a new one
func replace_camera(new_camera, old_cameras) -> void:
# Ensure old cameras are remove from the current scene
# Ensure old cameras are removed from the current scene
for camera in old_cameras:
if camera.is_inside_tree():
remove_from_tree(camera)
Expand All @@ -171,6 +174,7 @@ func replace_camera(new_camera, old_cameras) -> void:
add_child(new_camera)


# Set the game mode
func set_mode(mode):
var start_a_new_race = false

Expand All @@ -182,19 +186,19 @@ func set_mode(mode):
for marble in _marbles:
marble.pause()

# Ensure timer is reset
# Ensure the timer is reset
_race_has_started = false
_timer.set_wait_time(10)
_timer.stop()

# Ensure that the pause menu is close
# Ensure that the pause menu is closed
if _pause_menu.visible:
_pause_menu.close()

_mode = mode

if _mode == State.MODE_MARBLE:
# If no marbles exists
# If no marbles exist
if start_a_new_race:
await Fade.fade_out(1, Color.BLACK, "Diamond", false, false).finished

Expand Down Expand Up @@ -250,6 +254,7 @@ func set_mode(mode):
replace_camera(_rotation_camera, [_cinematic_camera])


# Remove a node from the scene tree
static func remove_from_tree(node):
node.get_parent().remove_child(node)

Expand Down Expand Up @@ -311,6 +316,7 @@ func _process(delta):
replace_camera(_rotation_camera, [_cinematic_camera])


# Handle victory conditions on explosion mode
func explosion_victory(_last_marble: Marble) -> bool:
var marble_exploded_count := 0
var tmp_marble = null
Expand Down
18 changes: 9 additions & 9 deletions scripts/marble.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var _checkpoint_count := 0
@onready var _name := get_node(^"%Name") as Label3D
@onready var _bomb_sound = get_node(^"%BombSound")
@onready var _score = get_node(^"%Score")
@onready var _ball_mesh := get_node(^"%Ball")


func _ready() -> void:
Expand All @@ -23,16 +24,15 @@ func _ready() -> void:

# Set material color
var color = Color(randf(), randf(), randf())
for i in range(3):
var x_ray_material: StandardMaterial3D = (
get_node("LODSpatial/Ball-%d" % i).get_active_material(0)
)
x_ray_material.set_albedo(color)
var toon_material: StandardMaterial3D = x_ray_material.get_next_pass()
toon_material.set_albedo(color)
var x_ray_material: StandardMaterial3D = (
_ball_mesh.get_active_material(0)
)
x_ray_material.set_albedo(color)
var toon_material: StandardMaterial3D = x_ray_material.get_next_pass()
toon_material.set_albedo(color)
# toon_material.set_shader_parameter(&"albedo", color)
x_ray_material.set_next_pass(toon_material)
get_node("LODSpatial/Ball-%d" % i).set_surface_override_material(0, x_ray_material)
x_ray_material.set_next_pass(toon_material)
_ball_mesh.set_surface_override_material(0, x_ray_material)

# Set collision mask
var collision_enabled = SettingsManager.get_value(&"marbles", &"collision_enabled") as bool
Expand Down
Loading