]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Text/auto_skip.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Text / auto_skip.gd
1 class_name DialogicAutoSkip
2 extends RefCounted
3 ## This class holds the settings for the Auto-Skip feature.
4 ## Changing the variables will alter the behaviour of Auto-Skip.
5 ##
6 ## Auto-Skip must be implemented per event.
7
8 ## Emitted whenever the Auto-Skip state changes, from `true` to `false` or
9 ## vice-versa.
10 signal toggled(is_enabled: bool)
11
12 ## Whether Auto-Skip is enabled or not.
13 ## If Auto-Skip is referred to be [i]disabled[/i], it refers to setting this
14 ## this variable to `false`.
15 ## This variable will automatically emit [signal autoskip_changed] when changed.
16 var enabled := false : set = _set_enabled
17
18 ## If `true`, Auto-Skip will be disabled when the user presses a recognised
19 ## input action.
20 var disable_on_user_input := true
21
22 ## If `true`, Auto-Skip will be disabled when the timeline advances to a
23 ## unread Text event or an event requesting user input.
24 var disable_on_unread_text := false
25
26 ## If `true`, Auto-Skip will be enabled when the timeline advances to a
27 ## previously visited Text event.
28 ## Useful if the player always wants to skip already-visited Text events.
29 var enable_on_visited := false
30
31 ## If `true`, Auto-Skip will skip Voice events instead of playing them.
32 var skip_voice := true
33
34 ## The amount of seconds each event may take.
35 ## This is not enforced, each event must implement this behaviour.
36 var time_per_event: float = 0.1
37
38
39 ## Setting up Auto-Skip.
40 func _init() -> void:
41         time_per_event = ProjectSettings.get_setting('dialogic/text/autoskip_time_per_event', time_per_event)
42
43         if DialogicUtil.autoload().has_subsystem("History") and not DialogicUtil.autoload().History.visited_event.is_connected(_handle_seen_event):
44                 DialogicUtil.autoload().History.visited_event.connect(_handle_seen_event)
45                 DialogicUtil.autoload().History.unvisited_event.connect(_handle_unseen_event)
46
47
48 ## Called when Auto-Skip is enabled or disabled.
49 ## Emits [signal autoskip_changed] if the state changed.
50 func _set_enabled(is_enabled: bool) -> void:
51         var previous_enabled := enabled
52         enabled = is_enabled
53
54         if enabled != previous_enabled:
55                 toggled.emit(enabled)
56
57
58 func _handle_seen_event() -> void:
59         # If Auto-Skip is disabled but reacts to seen events, we
60         # enable Auto-Skip.
61         if not enabled and enable_on_visited:
62                 enabled = true
63
64
65 func _handle_unseen_event() -> void:
66         if not enabled:
67                 return
68
69         if disable_on_unread_text:
70                 enabled = false