~kmdodrill/my-brother-lives-in-a-canyon

my-brother-lives-in-a-canyon/src/World.gd -rw-r--r-- 2.3 KiB
80dd997c — Kenneth Dodrill Remove misc prints 1 year, 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extends Spatial

onready var pause_menu = $UI/PauseScreen/PauseMenu
onready var end_menu = $UI/EndScreen/EndMenu
onready var dialogue_system = get_tree().root.get_node("DialogueSystem")
onready var fader = $UI/Fader

var using_steam = false
var ACHIEVEMENTS: Dictionary = {
    "START": false,
    "FINISH": false,
    "CABIN": false,
    "CROSSES": false,
    "DIARY": false,
}

func _ready() -> void:
    get_tree().paused = true
    initialize_steam()
    
func _unhandled_input(event) -> void:
    if get_tree().is_paused() || Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
        return
    
    if event.is_action_pressed("pause"):
        get_tree().set_input_as_handled()
        pause()

func pause() -> void:
    get_tree().paused = true
    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
    pause_menu.show()
    
func resume() -> void:
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    pause_menu.hide()
    pause_menu.release_focus()
    get_tree().paused = false
    
func end() -> void:
    yield(get_tree().create_timer(3.0), "timeout")
    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
    fader.fade_in()
    end_menu.get_node("AnimationPlayer").play("show")
    unlock_steam_achievement("FINISH")

func initialize_steam() -> void:
    var INIT: Dictionary = Steam.steamInit(false)
    
    if INIT['status'] != 1:
        print("Failed to initialize Steam. " + str(INIT['verbal']) + " will not interact with SteamWorks API...")
        return
        
    using_steam = true
    # Get user data once.
    var _response = Steam.connect("current_stats_received", self, "initialize_steam_stats", [], CONNECT_ONESHOT)
    
    initialize_steam_achievements()
    
func initialize_steam_achievements() -> void:
    for achievement in ACHIEVEMENTS.keys():
        var steam_achievement: Dictionary = Steam.getAchievement(achievement)
        if !steam_achievement['ret']:
            continue
        if steam_achievement['achieved']:
            ACHIEVEMENTS[achievement] = true
        
func unlock_steam_achievement(value: String) -> void:
    # If the achievement is already unlocked, or steam failed to init, return.
    if ACHIEVEMENTS[value] == true || using_steam == false:
        return
    
    ACHIEVEMENTS[value] = true
    var _response = Steam.setAchievement(value)
    _response = Steam.storeStats()