refactor: Joke time is now a parameter
This commit is contained in:
parent
9de366915b
commit
8cc3db52de
1 changed files with 9 additions and 9 deletions
|
@ -15,23 +15,23 @@ namespace Messaging {
|
||||||
[SerializeField, Min(0)] private float sendJokeDelay = 2f;
|
[SerializeField, Min(0)] private float sendJokeDelay = 2f;
|
||||||
[SerializeField, Min(0)] private float initialSendJokeDelay = 4f;
|
[SerializeField, Min(0)] private float initialSendJokeDelay = 4f;
|
||||||
|
|
||||||
private List<TextAsset> jokesBag;
|
private List<TextAsset> _jokesBag;
|
||||||
|
|
||||||
private MessageData.MessageData _currentJoke;
|
private MessageData.MessageData _currentJoke;
|
||||||
private int _currentJokeIndex;
|
private int _currentJokeIndex;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
_messages = messageStructureGenerator.GenerateMessages();
|
_messages = messageStructureGenerator.GenerateMessages();
|
||||||
jokesBag = new List<TextAsset>(jokes);
|
_jokesBag = new List<TextAsset>(jokes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
SendRandomJoke();
|
SendRandomJoke(initialSendJokeDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void SendRandomJoke() {
|
private async void SendRandomJoke(float delay) {
|
||||||
_currentJoke = GetRandomJoke();
|
_currentJoke = GetRandomJoke();
|
||||||
await Task.Delay((int)(initialSendJokeDelay * 1000));
|
await Task.Delay((int)(delay * 1000));
|
||||||
CreateMessage(_currentJoke.QuestionMessage.Key, false);
|
CreateMessage(_currentJoke.QuestionMessage.Key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ namespace Messaging {
|
||||||
if (message == _currentJoke.AnswerMessage.Key) {
|
if (message == _currentJoke.AnswerMessage.Key) {
|
||||||
ModifyRealMessageText(_currentJoke.QuestionMessage.Value, _currentJokeIndex, false);
|
ModifyRealMessageText(_currentJoke.QuestionMessage.Value, _currentJokeIndex, false);
|
||||||
ModifyRealMessageText(_currentJoke.AnswerMessage.Value, _messages.Length - 1, true);
|
ModifyRealMessageText(_currentJoke.AnswerMessage.Value, _messages.Length - 1, true);
|
||||||
SendRandomJoke();
|
SendRandomJoke(sendJokeDelay);
|
||||||
} else {
|
} else {
|
||||||
//TODO: Add lives support
|
//TODO: Add lives support
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,9 @@ namespace Messaging {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessageData.MessageData GetRandomJoke() {
|
private MessageData.MessageData GetRandomJoke() {
|
||||||
TextAsset joke = jokesBag[Random.Range(0, jokesBag.Count)];
|
TextAsset joke = _jokesBag[Random.Range(0, _jokesBag.Count)];
|
||||||
if (jokesBag.Count == 0)
|
if (_jokesBag.Count == 0)
|
||||||
jokesBag = new List<TextAsset>(jokes);
|
_jokesBag = new List<TextAsset>(jokes);
|
||||||
|
|
||||||
return new MessageData.MessageData(joke.text);
|
return new MessageData.MessageData(joke.text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue