Skip to content

Commit

Permalink
fixes MrEliptik#25 by moving the qr code creation to the button
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEliptik committed Sep 4, 2024
1 parent 9f63e55 commit 6ac3c08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
15 changes: 2 additions & 13 deletions scenes/app/scripts/app.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ var curr_game_btn: Button = null
@onready var update_checker := UpdateChecker.new()
@onready var global_shortcut: GlobalShortcut

var qr_generator: QrCode = null

var relaunch_on_crash: bool = false:
set(value):
relaunch_on_crash = value
Expand Down Expand Up @@ -54,10 +52,6 @@ func _ready() -> void:

SignalBus.shortcut_close_game_pressed.connect(func(): stop_game(pid_watching))

#configure QR generator
qr_generator = QrCode.new()
qr_generator.error_correct_level = QrCode.ErrorCorrectionLevel.LOW

if games.is_empty():
no_game_found.visible = true

Expand Down Expand Up @@ -263,13 +257,8 @@ func on_game_btn_focused(who: Button) -> void:
not_playable.visible = not playable
description.text += who.properties["description"]

# Also works in .ini has no "qr_url" property
var qr_url: String = who.properties.get("qr_url") if who.properties.get("qr_url") else ""
if not qr_url.is_empty():
var time_before: float = Time.get_ticks_usec()
var texture: ImageTexture = qr_generator.get_texture(qr_url)
print("QR gen (ms): ", (Time.get_ticks_usec() - time_before)/1000.0)
qr_rect.texture = texture
if who.qr_texture != null:
qr_rect.texture = who.qr_texture
qr_container.visible = true
qr_label.text = who.properties["qr_label"]
else:
Expand Down
13 changes: 13 additions & 0 deletions scenes/game_button/scripts/game_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ signal focused(who: Button)
var game_name: String
var properties: Dictionary
var tween: Tween
var qr_texture: ImageTexture = null

@onready var capsule: TextureRect = $Capsule
@onready var cross = $Cross
Expand All @@ -13,7 +14,12 @@ var tween: Tween
@onready var platform: Label = $InfoContainer/PlatformContainer/Platform
@onready var player_nb: Label = $InfoContainer/PlayerContainer/PlayerNb

@onready var qr_generator = QrCode.new()

func _ready() -> void:
#configure QR generator
qr_generator.error_correct_level = QrCode.ErrorCorrectionLevel.LOW

pivot_offset = size / 2.0

cross.visible = false
Expand All @@ -37,6 +43,13 @@ func _ready() -> void:

if properties.has("players_nb"):
player_nb.text = properties["players_nb"]

# Also works in .ini has no "qr_url" property
var qr_url: String = properties.get("qr_url") if properties.get("qr_url") else ""
if not qr_url.is_empty():
var time_before: float = Time.get_ticks_usec()
qr_texture = qr_generator.get_texture(qr_url)
print("QR gen (ms): ", (Time.get_ticks_usec() - time_before)/1000.0)

func load_image_texture(path: String) -> ImageTexture:
var capsule_im: Image = Image.new()
Expand Down

0 comments on commit 6ac3c08

Please sign in to comment.