Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.graphics.RectF
import kotlin.random.Random

fun Random.nextFloat(from: Float, until: Float): Float =
(until - from) * nextFloat()
(until - from) * nextFloat() + from

fun Random.nextPositionIn(area: RectF): PointF =
PointF(nextFloat(area.left, area.right), nextFloat(area.top, area.bottom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ package com.buzbuz.smartautoclicker.core.common.tutorial.domain.model.data.subje
enum class QuickClickGameTargetType {
IMAGE_BLUE,
IMAGE_RED,
IMAGE_GREEN,
IMAGE_YELLOW,
NUMBER,
TEXT_DAY,
TEXT_GOODBYE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.buzbuz.smartautoclicker.core.common.tutorial.domain.model.monitoring

enum class MonitoredViewType {
ACTION_TYPE_DIALOG_CLICK_ACTION,
ACTION_TYPE_DIALOG_COUNTER_ACTION,
ACTION_TYPE_DIALOG_TOGGLE_EVENT_ACTION,
ACTIONS_BRIEF_FIRST_ITEM,
ACTIONS_BRIEF_MENU_BUTTON_CREATE_ACTION,
ACTIONS_BRIEF_MENU_BUTTON_SAVE,
Expand All @@ -29,15 +31,25 @@ enum class MonitoredViewType {
CONDITIONS_BRIEF_FIRST_ITEM,
CONDITIONS_BRIEF_MENU_BUTTON_CREATE,
CONDITIONS_BRIEF_MENU_BUTTON_SAVE,
COUNTER_ACTION_DIALOG_BUTTON_SAVE,
COUNTER_ACTION_DIALOG_FIELD_SELECT_COUNTER,
COUNTER_REACHED_DIALOG_BUTTON_SAVE,
COUNTER_REACHED_DIALOG_FIELD_COUNTER_SELECTION,
COUNTER_SELECTION_DIALOG_BUTTON_CREATE,
EVENT_DIALOG_BUTTON_SAVE,
EVENT_DIALOG_FIELD_ACTIONS,
EVENT_DIALOG_FIELD_CONDITIONS,
EVENT_DIALOG_FIELD_INITIAL_STATE,
EVENT_DIALOG_FIELD_OPERATOR_ITEM_AND,
EVENT_DIALOG_FIELD_OPERATOR_ITEM_OR,
MAIN_MENU_BUTTON_CONFIG,
MAIN_MENU_BUTTON_PLAY,
SCENARIO_DIALOG_BUTTON_CREATE_EVENT,
SCENARIO_DIALOG_BUTTON_SAVE,
SCENARIO_DIALOG_ITEM_FIRST_EVENT,
SCENARIO_DIALOG_ITEM_SECOND_EVENT,
SCENARIO_DIALOG_ITEM_THIRD_EVENT,
SCENARIO_DIALOG_ITEM_FOURTH_EVENT,
SCENARIO_DIALOG_TRIGGER_EVENT_TAB,

SCREEN_CONDITION_CAPTURE_MENU_BUTTON_CAPTURE,
Expand All @@ -56,6 +68,7 @@ enum class MonitoredViewType {
TEXT_CONDITION_DIALOG_FIELD_TEXT_TO_DETECT,

TIMER_REACHED_CONDITION_BUTTON_SAVE,
TOGGLE_EVENT_DIALOG_SELECT_TOGGLES,
TIMER_REACHED_CONDITION_FIELD_AFTER,
TIMER_REACHED_CONDITION_FIELD_RESTART,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class TutorialStepStartConditionMonitor @Inject constructor(
fun monitorCondition(
condition: TutorialStepStartCondition,
subjectController: TutorialSubjectController,
onConditionReached: () -> Unit
onConditionReached: () -> Unit,
) = when (condition) {

is TutorialStepStartCondition.MonitoredViewClicked -> {
Expand All @@ -56,7 +56,15 @@ internal class TutorialStepStartConditionMonitor @Inject constructor(

is TutorialStepStartCondition.MonitoredOverlayDisplayed -> {
stepConditionMonitoringJob = coroutineScopeIo.launch {
// If we already are on the overlay wanted, we want to user to go away and then go back
val currentTop = overlayManager.getBackStackTop()
var awaitingCurrentLeave = currentTop?.tutorialMonitoringTag() == condition.type.name

overlayManager.backStackTopFlow.collect { newTop ->
if (awaitingCurrentLeave && condition.type.name == newTop?.tutorialMonitoringTag())
return@collect

awaitingCurrentLeave = false
if (condition.type.name != newTop?.tutorialMonitoringTag()) return@collect

onConditionReached()
Expand All @@ -74,23 +82,25 @@ internal class TutorialStepStartConditionMonitor @Inject constructor(

TutorialStepStartCondition.GameLost ->
(subjectController as? QuickClickGameEngine)?.monitorNextCompletion { isWon ->
if (isWon) return@monitorNextCompletion
if (isWon) return@monitorNextCompletion false
onConditionReached()
true
}

TutorialStepStartCondition.GameWon ->
(subjectController as? QuickClickGameEngine)?.monitorNextCompletion { isWon ->
if (!isWon) return@monitorNextCompletion
if (!isWon) return@monitorNextCompletion false
onConditionReached()
true
}

TutorialStepStartCondition.Immediate ->
onConditionReached()

is TutorialStepStartCondition.MonitoredNumberInput ->
monitoredViewsManager.monitorNumber(condition.type, condition.expectedNumber) {
onConditionReached()
}
is TutorialStepStartCondition.MonitoredNumberInput ->
monitoredViewsManager.monitorNumber(condition.type, condition.expectedNumber) {
onConditionReached()
}
}

fun stopMonitoring(condition: TutorialStepStartCondition, subjectController: TutorialSubjectController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class QuickClickGameEngine (
private val coroutineScopeIo: CoroutineScope = CoroutineScope(SupervisorJob() + ioDispatcher)

private var gameJob: Job? = null
private var onGameCompleted: ((isWon: Boolean) -> Unit)? = null
private var onGameCompleted: ((isWon: Boolean) -> Boolean)? = null


private val _state: MutableStateFlow<TutorialSubjectState.QuickClickGame> = MutableStateFlow(defaultState())
Expand Down Expand Up @@ -94,15 +94,17 @@ internal class QuickClickGameEngine (
targets = emptyMap()
)
}
onGameCompleted?.invoke(isWon)
onGameCompleted = null

val consumed = onGameCompleted?.invoke(isWon) ?: true
if (consumed) onGameCompleted = null
gameJob = null
}
}

override fun stop() {
Log.d(TAG, "Stop game")

onGameCompleted = null
gameJob?.cancel()
gameJob = null

Expand All @@ -119,7 +121,7 @@ internal class QuickClickGameEngine (
}
}

fun monitorNextCompletion(listener: ((isWon: Boolean) -> Unit)?) {
fun monitorNextCompletion(listener: ((isWon: Boolean) -> Boolean)?) {
onGameCompleted = listener
}

Expand Down
Loading
Loading