|
|
@ -1,6 +1,14 @@ |
|
|
|
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" |
|
|
@ -13,9 +21,13 @@ var registered_providers = [ |
|
|
|
'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(): |
|
|
@ -45,15 +57,56 @@ func save_config(): |
|
|
|
|
|
|
|
func start_poll(poll): |
|
|
|
prints("Starting poll", poll) |
|
|
|
# Start listening to chat commands |
|
|
|
# Prepare timer for automatic closing of the 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") |
|
|
|
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: |
|
|
@ -75,12 +128,6 @@ func can_have_sms_provider() -> bool: |
|
|
|
return Engine.has_singleton("AndroidSmsReceiver") |
|
|
|
|
|
|
|
|
|
|
|
#func get_android_sms_reader(): |
|
|
|
# if can_have_sms_provider(): |
|
|
|
# return Engine.get_singleton("AndroidSmsReader") |
|
|
|
# return null |
|
|
|
|
|
|
|
|
|
|
|
func get_now() -> int: |
|
|
|
return OS.get_unix_time() |
|
|
|
|
|
|
|