small racing game im working on
Diffstat (limited to 'ui/trackbutton.gd')
| -rw-r--r-- | ui/trackbutton.gd | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/ui/trackbutton.gd b/ui/trackbutton.gd index c046098..35f211f 100644 --- a/ui/trackbutton.gd +++ b/ui/trackbutton.gd @@ -1,8 +1,37 @@ extends Control -func init(t: float, n: String) -> void: - $VBoxContainer/name.text = n - if t < 0: - $VBoxContainer/time.text = "no time set" +const trackloader_scn = preload("res://scenes/track.tscn") +const thumbnail_path = "user://%s.thumb" + +signal pressed + +func init(t: TrackResource, g: GhostData) -> void: + %name.text = t.name + if g == null: + %time.text = "no time set" + else: + %time.text = GameTimer.format_precise(g.time) + var p: String = thumbnail_path % t.name + if FileAccess.file_exists(p) and Time.get_unix_time_from_system() - FileAccess.get_modified_time(p) < 40000: # ~5days + print("loading thumb") + var f := FileAccess.open(p, FileAccess.READ) + var img := Image.new() + var e := img.load_png_from_buffer(f.get_buffer(f.get_length())) + if e != OK: + print("error: ", e) + return + (%thumb as TextureRect).texture = ImageTexture.create_from_image(img) else: - $VBoxContainer/time.text = GameTimer.format_precise(t) + print("making thumb") + %port.add_child(IntroCam.new(t, null)) + var trackloader: TrackLoader = trackloader_scn.instantiate() + trackloader.track = t + %port.add_child(trackloader) + await RenderingServer.frame_post_draw + trackloader.queue_free() + var img: Image = %port.get_texture().get_image() + img.save_png(p) + (%thumb as TextureRect).texture = ImageTexture.create_from_image(img) + + + |