Skip to content

Commit

Permalink
[fix] format
Browse files Browse the repository at this point in the history
  • Loading branch information
theludovyc committed Sep 8, 2024
1 parent be23667 commit 6501d89
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 87 deletions.
5 changes: 0 additions & 5 deletions Script/Gui/ConfirmDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ func _ready():

func popup_confirm(confirm_text:String, on_ok_pressed:Callable):
dialog_text = confirm_text

var button_pressed_signal:Signal = get_ok_button().pressed

if current_callable.is_valid() and current_callable != on_ok_pressed:
button_pressed_signal.disconnect(current_callable)

button_pressed_signal.connect(on_ok_pressed)

current_callable = on_ok_pressed

popup_centered_clamped()
21 changes: 0 additions & 21 deletions addons/rakugo_game_template/Autoloads/AppSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,34 @@ var busses_volume := {}

func _ready():
var err = config_file.load(CONFIG_FILE_LOCATION)

if err != OK:
return

#load input_events
if config_file.has_section(INPUT_SECTION):
var action_names = config_file.get_section_keys(INPUT_SECTION)

for action_name in action_names:
if not InputMap.has_action(action_name):
push_error("Action: " + action_name + ", does not exist in the InputMap !")
continue

InputMap.action_erase_events(action_name)
InputMap.action_add_event(
action_name,
config_file.get_value(INPUT_SECTION, action_name))

#audio
if config_file.has_section(AUDIO_SECTION):
if config_file.get_value(AUDIO_SECTION, MUTE_SETTING, false):
AudioServer.set_bus_mute(MASTER_BUS_INDEX, true)

var dictio = config_file.get_value(AUDIO_SECTION, BUSSES_VOLUME, {})

for bus_index in dictio:
AudioServer.set_bus_volume_db(bus_index, linear_to_db(dictio[bus_index]))

#video
if config_file.has_section(VIDEO_SECTION):
var main_window = get_window()

if config_file.get_value(VIDEO_SECTION, FULLSCREEN_ENABLED, is_master_muted()):
main_window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN

if config_file.has_section_key(VIDEO_SECTION, SCREEN_RESOLUTION):
var res_value = config_file.get_value(VIDEO_SECTION, SCREEN_RESOLUTION)

main_window.content_scale_size = res_value

if main_window.mode != Window.MODE_EXCLUSIVE_FULLSCREEN:
main_window.size = res_value

Expand All @@ -76,39 +64,30 @@ func reset_to_default_inputs() -> void:
# Audio
func set_bus_volume_from_linear(bus_index : int, linear : float) -> void:
AudioServer.set_bus_volume_db(bus_index, linear_to_db(linear))

busses_volume[bus_index] = linear

config_file.set_value(AUDIO_SECTION, BUSSES_VOLUME, busses_volume)

func is_master_muted() -> bool:
return AudioServer.is_bus_mute(MASTER_BUS_INDEX)

func set_mute(mute_flag : bool) -> void:
AudioServer.set_bus_mute(MASTER_BUS_INDEX, mute_flag)

config_file.set_value(AUDIO_SECTION, MUTE_SETTING, mute_flag)

# Video
func set_fullscreen(value:bool):
var main_window = get_window()

main_window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN if value else Window.MODE_WINDOWED

if main_window.mode == Window.MODE_WINDOWED:
main_window.size = config_file.get_value(VIDEO_SECTION, SCREEN_RESOLUTION,
Vector2i(
ProjectSettings.get_setting("display/window/size/viewport_width"),
ProjectSettings.get_setting("display/window/size/viewport_height")))

config_file.set_value(VIDEO_SECTION, FULLSCREEN_ENABLED, value)

func set_resolution(value : Vector2i) -> void:
var main_window = get_window()

main_window.content_scale_size = value

if main_window.mode != Window.MODE_EXCLUSIVE_FULLSCREEN:
main_window.size = value

config_file.set_value(VIDEO_SECTION, SCREEN_RESOLUTION, value)
4 changes: 0 additions & 4 deletions addons/rakugo_game_template/Autoloads/SceneLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ func get_resource():
func change_scene_to_resource() -> void:
var current_tree = get_tree()
current_tree.paused = true

Transitions.transition(Transitions.transition_type.Diamond)
await Transitions.animation_player.animation_finished

var err = current_tree.change_scene_to_packed(get_resource())
if err:
push_error("failed to change scenes: %d" % err)
current_tree.quit()

Transitions.transition(Transitions.transition_type.Diamond, true)
await Transitions.animation_player.animation_finished

current_tree.paused = false

func change_scene_to_loading_screen() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void fragment() {
float ratio = 1.0 / size_ratio;
float dist = distance(vec2(location_x, location_y), vec2(mix(0.5, UV.x, ratio), UV.y));
float alpha_total = (1.0 - step(size, dist));
if (invert == true) {
if (invert) {
alpha_total = 1.0 - alpha_total;
}
COLOR.a = alpha_total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ uniform float progress : hint_range(0, 1);
// Size of each diamond, in pixels.
uniform float diamondPixelSize = 10.0;



void fragment() {

float xFraction = fract(FRAGCOORD.x / diamondPixelSize);
float yFraction = fract(FRAGCOORD.y / diamondPixelSize);
float xDistance = abs(xFraction - 0.5);
float yDistance = abs(yFraction - 0.5);
if (xDistance + yDistance + UV.x + UV.y > progress * 4.0) {
discard;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ void fragment() {
COLOR = vec4(0.0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ void fragment() {
float alpha3 = step(size + location_y, mix(0.5, UV.y, ratio_height));
float alpha4 = step(size - location_y, mix(0.5, 1.0-UV.y, ratio_height));
float alpha_total = alpha1 * alpha2 * alpha3 * alpha4;
if (invert == true) {
if (invert) {
alpha_total = 1.0 - alpha_total;
}
COLOR.a = alpha_total;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ uniform bool invert_xy = false;

void fragment() {
float which_axis = UV.x;
if (invert_xy == true) {
if (invert_xy) {
which_axis = UV.y;
}
COLOR.a = (1.0 - step(size * wipe_direction, which_axis * wipe_direction));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ func screen_ratio ():
func transition (transition_name:transition_type, reverse :bool = false) :
stop_mouse.mouse_filter = Control.MOUSE_FILTER_STOP
color_rect.show()

var transition_name_str :String

match transition_name:
transition_type.Swipe:
transition_name_str = "Swipe"
Expand All @@ -28,11 +26,9 @@ func transition (transition_name:transition_type, reverse :bool = false) :
transition_name_str = "Diamond"
transition_type.Line:
transition_name_str = "Line"

if reverse :
animation_player.play_backwards(transition_name_str)
return

animation_player.play(transition_name_str)

func _on_animation_finished(anim_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,35 @@ extends Node
func get_one_audio_stream(array:Array):
if array.is_empty():
return null

if array.size() == 1:
return array[0]

return array.pick_random()


func _on_event(audio_array:Array):
audio_stream_player.stream = get_one_audio_stream(audio_array)
audio_stream_player.play()


func _on_event_pressed():
_on_event(audio_streams_pressed)


func _on_event_hovered():
_on_event(audio_streams_hovered)


func _connect_stream_player(node : Node, signal_name : StringName, callable:Callable, unbind_count:int = 0) -> void:
if unbind_count > 0:
callable = callable.unbind(unbind_count)

if not node.is_connected(signal_name, callable):
node.connect(signal_name, callable)


func connect_ui_sounds(node: Node) -> void:
if node is Button:
_connect_stream_player(node, &"mouse_entered", _on_event_hovered)
_connect_stream_player(node, &"pressed", _on_event_pressed)

if node is OptionButton:
_connect_stream_player(node, &"item_selected", _on_event_pressed, 1)
elif node is TabBar:
Expand All @@ -50,17 +51,16 @@ func connect_ui_sounds(node: Node) -> void:
elif node is LineEdit:
_connect_stream_player(node, &"mouse_entered", _on_event_hovered)
_connect_stream_player(node, &"text_submitted", _on_event_pressed)



func _on_node_added(node:Node):
if not node is Control:
return

connect_ui_sounds(node)


func _ready():
if audio_streams_pressed.is_empty() and audio_streams_hovered.is_empty():
return

audio_stream_player.bus = audio_bus

get_tree().node_added.connect(_on_node_added)
2 changes: 0 additions & 2 deletions addons/rakugo_game_template/rakugo_game_template.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func _enter_tree():
add_autoload_singleton("ProjectMusicController", "res://addons/rakugo_game_template/Autoloads/ProjectMusicController.tscn")
add_autoload_singleton("UISoundManager", "res://addons/rakugo_game_template/Autoloads/UISoundManager/UISoundManager.tscn")
add_autoload_singleton("Transitions", "res://addons/rakugo_game_template/Autoloads/Transitions/transitions.tscn")

init_setting_if_empty(RGT_Globals.loading_scene_setting_path, "res://scenes/LoadingScreen/LoadingScreen.tscn")
init_setting_if_empty(RGT_Globals.main_menu_setting_path, "res://scenes/MainMenu/MainMenu.tscn")
init_setting_if_empty(RGT_Globals.first_game_scene_setting_path, "res://scenes/Game/game.tscn")
Expand All @@ -22,7 +21,6 @@ func _exit_tree():
remove_autoload_singleton("ProjectMusicController")
remove_autoload_singleton("UISoundManager")
remove_autoload_singleton("Transitions")

RGT_Globals.loading_scene_setting = null
RGT_Globals.main_menu_setting = null
RGT_Globals.first_game_scene_setting = null
15 changes: 15 additions & 0 deletions addons/rakugo_game_template/scripts/MusicController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ const MINIMUM_VOLUME_DB = -80
if fade_out_duration < 0:
fade_out_duration = 0


@export var fade_in_duration : float = 0.0 :
set(value):
fade_in_duration = value
if fade_in_duration < 0:
fade_in_duration = 0


@export var blend_volume_duration : float = 0.0 :
set(value):
blend_volume_duration = value
if blend_volume_duration < 0:
blend_volume_duration = 0


## Matched stream players with no stream set will stop current playback.
@export var empty_streams_stop_player : bool = true

Expand All @@ -43,6 +46,7 @@ func fade_out( duration : float = 0.0 ):
tween.tween_property(music_stream_player, "volume_db", MINIMUM_VOLUME_DB, duration)
return tween


func fade_in( duration : float = 0.0 ):
if not is_zero_approx(duration):
var target_volume_db = music_stream_player.volume_db
Expand All @@ -51,23 +55,27 @@ func fade_in( duration : float = 0.0 ):
tween.tween_property(music_stream_player, "volume_db", target_volume_db, duration)
return tween


func blend_to( target_volume_db : float, duration : float = 0.0 ):
if not is_zero_approx(duration):
var tween = get_tree().create_tween()
tween.tween_property(music_stream_player, "volume_db", target_volume_db, duration)
return tween
music_stream_player.volume_db = target_volume_db


func stop():
if music_stream_player == null:
return
music_stream_player.stop()


func play():
if music_stream_player == null:
return
music_stream_player.play()


func _fade_out_and_free():
if music_stream_player == null:
return
Expand All @@ -77,28 +85,33 @@ func _fade_out_and_free():
await( tween.finished )
stream_player.queue_free()


func _play_and_fade_in():
if music_stream_player == null:
return
music_stream_player.play()
fade_in( fade_in_duration )


func _is_matching_stream( stream_player : AudioStreamPlayer ) -> bool:
if stream_player.bus != audio_bus:
return false
if music_stream_player == null:
return false
return music_stream_player.stream == stream_player.stream


func _reparent_music_player( stream_player : AudioStreamPlayer ):
stream_player.call_deferred("reparent", self)
music_stream_player = stream_player


func _blend_in_stream_player( stream_player : AudioStreamPlayer ):
_fade_out_and_free()
_reparent_music_player(stream_player)
_play_and_fade_in()


func check_for_music_player( node: Node ) -> void:
if node == music_stream_player : return
if not (node is AudioStreamPlayer and node.autoplay) : return
Expand All @@ -113,11 +126,13 @@ func check_for_music_player( node: Node ) -> void:
return
_blend_in_stream_player(node)


func _ready() -> void:
var tree_node = get_tree()
if not tree_node.node_added.is_connected(check_for_music_player):
tree_node.node_added.connect(check_for_music_player)


func _exit_tree():
var tree_node = get_tree()
if tree_node.node_added.is_connected(check_for_music_player):
Expand Down
Loading

0 comments on commit 6501d89

Please sign in to comment.