Score hardcoded autoload, pretty score shader

This commit is contained in:
Luke Hubmayer-Werner 2019-12-11 01:10:31 +10:30
parent 92b83416a3
commit ac867937ea
4 changed files with 97 additions and 49 deletions

50
Menu.gd
View File

@ -75,9 +75,41 @@ func save_score():
file.close()
scorescreen_saved = true
func load_score(filename):
var rootdir = "user://scores"
var dir = Directory.new()
dir.make_dir_recursive(rootdir)
var file = File.new()
var err = file.open(rootdir + "/" + filename, File.READ)
if err != OK:
print(err)
return err
var result_json = JSON.parse(file.get_as_text())
file.close()
if result_json.error != OK:
print("Error: ", result_json.error)
print("Error Line: ", result_json.error_line)
print("Error String: ", result_json.error_string)
return result_json.error
var result = result_json.result
var data = {}
for key in result.score_data:
var value = {}
for k2 in result.score_data[key]:
if k2 == "MISS":
value[k2] = result.score_data[key][k2]
else:
value[int(k2)] = result.score_data[key][k2]
data[int(key)] = value
scorescreen_score_data = data
scorescreen_song_key = result.song_key
scorescreen_saved = true
set_menu_mode(MenuMode.SCORE_SCREEN)
func _ready():
scan_library()
$"/root/main/NoteHandler".connect("finished_song", self, "finished_song")
load_score("20191210T235010.json")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@ -256,10 +288,12 @@ func _draw_score_screen(center: Vector2) -> Array:
break
else:
score_idx += 1
# $ScoreText.draw_string_centered(ScoreFont, Vector2(x_score, y1), Rules.SCORE_STRINGS[score_idx], Color(1.0, 1.0, 1.0))
# $ScoreText.draw_string_centered(TitleFont, Vector2(x_score, y1+y_spacing*3), "%2.3f%%"%(overall_score*100.0), Color(1.0, 1.0, 1.0))
draw_string_centered(ScoreFont, Vector2(x_score, y1), Rules.SCORE_STRINGS[score_idx], Color(1.0, 1.0, 1.0))
draw_string_centered(TitleFont, Vector2(x_score, y1+y_spacing*3), "%2.3f%%"%(overall_score*100.0), Color(1.0, 1.0, 1.0))
# draw_string_centered(ScoreFont, Vector2(x_score, y1), Rules.SCORE_STRINGS[score_idx], Color(1.0, 1.0, 1.0))
# draw_string_centered(TitleFont, Vector2(x_score, y1+y_spacing*3), "%2.3f%%"%(overall_score*100.0), Color(1.0, 1.0, 1.0))
$ScoreText.position = Vector2(x_score, y1)
$ScoreText.score = Rules.SCORE_STRINGS[score_idx]
$ScoreText.score_sub = "%2.3f%%"%(overall_score*100.0)
$ScoreText.update()
draw_string_centered(TitleFont, Vector2(x, y2+y_spacing*4), "Early : Late", Color(0.95, 0.95, 1.0))
draw_string_centered(TitleFont, Vector2(x, y2+y_spacing*5), "%3d%% : %3d%%"%[notecount_early*100/notecount_total, notecount_late*100/notecount_total], Color(0.95, 0.95, 1.0))
@ -291,8 +325,8 @@ func _draw():
if menu_mode_prev_fade_timer > 0.0:
var progress = 1.0 - menu_mode_prev_fade_timer/menu_mode_prev_fade_timer_duration
var center_prev = lerp(center, Vector2(0.0, 700.0), progress)
var center_next = lerp(Vector2(0.0, -700.0), center, progress)
var center_prev = lerp(center, Vector2(0.0, 900.0), progress)
var center_next = lerp(Vector2(0.0, -900.0), center, progress)
match menu_mode_prev:
MenuMode.SONG_SELECT:
_draw_song_select(center_prev)
@ -360,6 +394,10 @@ func touch_score_screen(touchdict):
if touchdict.has("next_menu"):
SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0)
set_menu_mode(touchdict.next_menu)
$ScoreText.score = ""
$ScoreText.score_sub = ""
# TODO: time this to coincide with the menu going fully offscreen
$ScoreText.update()
elif touchdict.has("action"):
SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0)
if touchdict.action == "save":

16
ScoreText.gd Normal file
View File

@ -0,0 +1,16 @@
extends Node2D
var score = ""
var score_sub = ""
var TitleFont := preload("res://assets/MenuTitleFont.tres")
var ScoreFont := preload("res://assets/MenuScoreFont.tres")
func draw_string_centered(font, position, string, color := Color.white):
draw_string(font, Vector2(position.x - font.get_string_size(string).x/2.0, position.y + font.get_ascent()), string, color)
func _draw():
if score:
draw_string_centered(ScoreFont, Vector2(0, 0), score, Color(1.0, 1.0, 1.0))
if score_sub:
draw_string_centered(TitleFont, Vector2(0, 128), score_sub, Color(1.0, 1.0, 1.0))

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://main.gd" type="Script" id=1]
[ext_resource path="res://video.gd" type="Script" id=2]
@ -8,9 +8,11 @@
[ext_resource path="res://shaders/notelines.shader" type="Shader" id=6]
[ext_resource path="res://shaders/notemesh.shader" type="Shader" id=7]
[ext_resource path="res://Menu.gd" type="Script" id=8]
[ext_resource path="res://Bezel.gd" type="Script" id=9]
[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=10]
[ext_resource path="res://InputHandler.gd" type="Script" id=11]
[ext_resource path="res://shaders/scoretext.tres" type="Material" id=9]
[ext_resource path="res://ScoreText.gd" type="Script" id=10]
[ext_resource path="res://Bezel.gd" type="Script" id=11]
[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=12]
[ext_resource path="res://InputHandler.gd" type="Script" id=13]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 6 )
@ -77,15 +79,17 @@ material = SubResource( 2 )
script = ExtResource( 8 )
[node name="ScoreText" type="Node2D" parent="Menu"]
material = ExtResource( 9 )
script = ExtResource( 10 )
[node name="Bezel" type="Node2D" parent="."]
script = ExtResource( 9 )
script = ExtResource( 11 )
[node name="InputHandler" type="Label" parent="."]
margin_left = -960.0
margin_top = -540.0
margin_right = 960.0
margin_bottom = 540.0
custom_fonts/font = ExtResource( 10 )
custom_fonts/font = ExtResource( 12 )
text = "Fingers on the screen:"
script = ExtResource( 11 )
script = ExtResource( 13 )

View File

@ -5,49 +5,39 @@ code = "shader_type canvas_item;
//render_mode unshaded;
uniform float bps;
uniform vec4 star_color : hint_color;
uniform vec4 held_color : hint_color;
uniform vec2 screen_size;
//uniform vec4 star_color : hint_color;
//uniform vec4 held_color : hint_color;
//void vertex() {
//}
// All components are in the range [0…1], including hue.
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void fragment() {
vec4 sample = texture(TEXTURE, UV);
float wave_scale = 0.015;
float timescale = 0.2;
float t = TIME * timescale;
vec3 hsv;
// hsv.x = 0.5 + 0.5*sin(wave_scale*FRAGCOORD.x+TIME*3.0);
// hsv.y = 0.5 + 0.5*sin(wave_scale*FRAGCOORD.y+TIME*2.5);
// hsv.z = 0.5 + 0.5*sin(wave_scale*FRAGCOORD.x+wave_scale*FRAGCOORD.y*cos(TIME*0.01)+TIME*3.5);
hsv.x = mod(wave_scale*wave_scale*FRAGCOORD.x+t*1.3 + 0.33*sin(wave_scale*FRAGCOORD.y+t*0.5) + 0.33*sin(wave_scale*FRAGCOORD.x+t*0.25), 1.0);
hsv.y = 0.5 + 0.25*sin(wave_scale*FRAGCOORD.y+t*2.5) + 0.25*cos(wave_scale*FRAGCOORD.x+t*3.5);
hsv.z = 0.75 + 0.25*sin(wave_scale*FRAGCOORD.x+wave_scale*FRAGCOORD.y*cos(t*0.01)+t*1.5);
if (COLOR.x >= 0.5) COLOR.rgb = hsv2rgb(hsv); else COLOR.rgb = vec3(1.0) - hsv2rgb(hsv);
float color_scale = sample.r;
float bright_scale = (sample.g+sample.b)/2.0;
float dist = distance(FRAGCOORD.xy, screen_size/2.0);
float dist_norm = dist*1.8 / screen_size.y;
if (COLOR.rgb == star_color.rgb){
// Star ripple
COLOR.rg += dist_norm*0.33;
COLOR.rgb *= mix(abs(0.5-mod(TIME*bps*2.0+dist_norm, 1.0)), 1.0, 0.75);
COLOR.rgb *= color_scale; // Preserve black outlines
COLOR.rgb = mix(COLOR.rgb, vec3(1.0), bright_scale); // Preserve white outlines
} else if (COLOR.rgb == held_color.rgb){
// Hold note being held, flashy effects
COLOR.b *= mix(2.0*abs(0.5-mod(TIME*bps*2.0+dist_norm, 1.0)), 1.0, 0.35);
COLOR.g *= mix(1.0 - 2.0*abs(0.5-mod(TIME*bps*0.5+dist_norm, 1.0)), 0.0, 0.35);
COLOR.r *= mix(abs(0.5-mod(TIME*bps, 1.0)), 1.0, 0.85);
if (color_scale < 0.5){ // Make black outlines shine
COLOR.rgb = mix(COLOR.rgb, vec3(mix(dist_norm, abs(0.5-mod(TIME*bps*8.0, 1.0)), 0.33)), 1.0-(color_scale*2.0));
}
COLOR.rgb = mix(COLOR.rgb, vec3(1.0), 0.33); // brighten overall
COLOR.rgb = mix(COLOR.rgb, vec3(0.25), bright_scale); // Invert white outlines
} else {
COLOR.gb += 0.1;
COLOR.rgb *= mix(abs(0.5-mod(TIME*bps, 1.0)), 1.0, 0.85);
COLOR.rgb *= color_scale; // Preserve black outlines
COLOR.rgb = mix(COLOR.rgb, vec3(1.0), bright_scale); // Preserve white outlines
}
// if (color_scale < 0.5){ // Make black outlines shine
// COLOR.rgb = mix(COLOR.rgb, vec3(mix(dist_norm, abs(0.5-mod(TIME*bps*8.0, 1.0)), 0.33)), 1.0-(color_scale*2.0));
// }
// COLOR.rgb = mix(COLOR.rgb, vec3(1.0), 0.1); // brighten overall
// COLOR.rgb = mix(COLOR.rgb, vec3(0.25), color_scale); // Invert white outlines
COLOR.a = clamp(COLOR.a*texture(TEXTURE, UV).a, 0.0, 1.0);
COLOR.a = clamp(texture(TEXTURE, UV).a, 0.0, 1.0);
}"
[resource]
shader = SubResource( 1 )
shader_param/bps = null
shader_param/star_color = null
shader_param/held_color = null
shader_param/screen_size = null