A Godot Engine app to help streamers organize Majority Judgment polls in their streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

137 lines
3.5 KiB

extends Node
# Goal
# ====
#
# Set up Majority Judgment polls using a variety of providers,
# such a the Twitch Chat, SMS (Android only)…
#
# Unused (see Config.gd) #
var config:ConfigResource
var config_path := "user://settings.tres"
##########################
# Add your provider here, as well as in the SettingsForm scene.
var registered_providers = [
'MajorityJudgmentDemoProvider',
'MajorityJudgmentTwitchChatProvider',
'MajorityJudgmentAndroidSmsProvider',
]
const ONGOING_POLL_FILEPATH = "user://ongoing_poll.tres"
var ongoing_poll:MajorityJudgmentPoll
func _ready():
load_config()
# load_ongoing_poll()
func go_to_main_menu():
var _done = get_tree().change_scene("res://gui/MainMenu.tscn")
func go_to_settings():
var _done = get_tree().change_scene("res://gui/forms/SettingsForm.tscn")
func go_to_twitch_settings():
var _done = get_tree().change_scene("res://gui/forms/twitch_config/TwitchAuthConfig.tscn")
func load_config():
if File.new().file_exists(self.config_path):
self.config = load(self.config_path)
if null == self.config:
self.config = ConfigResource.new()
func save_config():
var saved = ResourceSaver.save(self.config_path, self.config)
if OK != saved:
printerr("Failed to save configuration.")
func start_poll(poll):
prints("Starting poll", poll)
# Prepare timer for automatic closing of the poll?
# Move to poll results scene
assert(null == self.ongoing_poll, "Cannot start another poll while one is ongoing.")
self.ongoing_poll = poll
var _done = get_tree().change_scene("res://addons/majority_judgment/nodes/MajorityJudgmentLinearResultsControl.tscn")
yield(get_tree(), "idle_frame")
get_tree().current_scene.align_with_bottom = Config.get_parameter("align_with_bottom", false)
get_tree().current_scene.set_poll(poll) # last
func close_ongoing_poll():
assert(self.ongoing_poll, "No ongoing poll to close.")
var saved = ResourceSaver.save(
"user://poll_%d.tres" % [self.ongoing_poll.opened_at],
self.ongoing_poll,
ResourceSaver.FLAG_OMIT_EDITOR_PROPERTIES
)
if OK != saved:
printerr("Failed to save closing poll to disk: ERROR " + saved)
self.ongoing_poll = null
func save_ongoing_poll():
assert(self.ongoing_poll, "No ongoing poll to save.")
var saved = ResourceSaver.save(ONGOING_POLL_FILEPATH, self.ongoing_poll)
if OK != saved:
printerr("Failed to save ongoing poll to disk: ERROR " + saved)
func has_ongoing_poll():
if null != self.ongoing_poll:
return true
var file = File.new()
return file.file_exists(ONGOING_POLL_FILEPATH)
func load_ongoing_poll():
# assert(null == ongoing_poll, "There already is an ongoing poll.")
var file := File.new()
if file.file_exists(ONGOING_POLL_FILEPATH):
print("Loading ongoing poll…")
# var _ongoing_poll = ResourceLoader.load(ONGOING_POLL_FILEPATH, "MajorityJudgmentPoll")
var _ongoing_poll = ResourceLoader.load(ONGOING_POLL_FILEPATH)
print("Ongoing poll loaded!")
start_poll(_ongoing_poll)
else:
print("No ongoing poll to load.")
func get_providers() -> Array:
var providers = Array()
for registered_provider in registered_providers:
var enabled = Config.get_parameter(
"provider_%s_enabled" % registered_provider,
false # default
)
if enabled:
var provider = load(
"res://addons/majority_judgment/providers/%s.gd"
%
registered_provider
).new()
providers.append(provider)
return providers
func can_have_sms_provider() -> bool:
return Engine.has_singleton("AndroidSmsReceiver")
func get_now() -> int:
return OS.get_unix_time()
func timer(duration:int) -> SceneTreeTimer:
return get_tree().create_timer(duration)