Skip to content
Open
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ dependencies {
implementation(projects.feature.setting)
implementation(projects.feature.carddelete)
implementation(projects.feature.webview)
implementation(projects.feature.game)

implementation(libs.compose.material.icons.core)
implementation(libs.androidx.activity.compose)
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/kotlin/com/gamss/android/app/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation3.runtime.EntryProviderScope
import androidx.navigation3.runtime.NavKey
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.scene.Scene
Expand All @@ -54,6 +55,10 @@ import com.gamss.android.feature.chat.ChatRoomScreen
import com.gamss.android.feature.chat.ChattingListScreen
import com.gamss.android.feature.chat.navigation.ChatKey
import com.gamss.android.feature.chat.navigation.ChatRoomKey
import com.gamss.android.feature.game.GameListScreen
import com.gamss.android.feature.game.clicker.ClickerGameScreen
import com.gamss.android.feature.game.navigation.ClickerGameKey
import com.gamss.android.feature.game.navigation.GameKey
import com.gamss.android.feature.home.HomeScreen
import com.gamss.android.feature.home.navigation.HomeKey
import com.gamss.android.feature.setting.accountinfo.AccountInfoScreen
Expand Down Expand Up @@ -112,7 +117,7 @@ fun MainScreen(
.padding(innerPadding)
.statusBarsPadding(),
entries = navigationState.toEntries(entryProvider = entries),
// 최상위 탭(홈/보관함/대화) 전환 기본값. 탭은 위계 없는 형제 화면이라
// 최상위 탭(홈/보관함/대화/오락) 전환 기본값. 탭은 위계 없는 형제 화면이라
// 방향성 있는 슬라이드 대신 fade-through를 쓴다. 상세 화면은 아래 entry의
// metadata(detailTransition)가 이 기본값을 덮어쓴다.
transitionSpec = tabFadeThroughSpec,
Expand Down Expand Up @@ -192,6 +197,7 @@ private fun mainEntryProvider(navigator: Navigator) = entryProvider {
entry<WebViewKey>(metadata = detailSlideTransition) { key ->
WebViewScreen(page = key.page, onBackClick = navigator::goBack)
}
gameEntries(navigator)
entry<ChatKey> {
ChattingListScreen(
onChatClick = { navigator.navigate(ChatRoomKey(it)) },
Expand All @@ -211,8 +217,20 @@ private fun mainEntryProvider(navigator: Navigator) = entryProvider {
}
}

private fun EntryProviderScope<NavKey>.gameEntries(navigator: Navigator) {
entry<GameKey> {
GameListScreen(
onNavigateToSetting = { navigator.navigate(SettingKey) },
onClickerGameClick = { navigator.navigate(ClickerGameKey) },
)
}
entry<ClickerGameKey>(metadata = detailSlideTransition) {
ClickerGameScreen(onBackClick = navigator::goBack)
}
}

/**
* 최상위 탭(홈/보관함/대화) 간 전환에 쓰는 기본 트랜지션.
* 최상위 탭(홈/보관함/대화/오락) 간 전환에 쓰는 기본 트랜지션.
* 탭은 위계 없는 형제 화면이라 방향성 있는 슬라이드 대신 fade-through를 쓴다.
*/
private val tabFadeThroughSpec: AnimatedContentTransitionScope<Scene<NavKey>>.() -> ContentTransform = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.gamss.android.feature.archive.navigation.ArchiveKey
import com.gamss.android.feature.carddelete.navigation.CardDeleteKey
import com.gamss.android.feature.chat.navigation.ChatKey
import com.gamss.android.feature.chat.navigation.ChatRoomKey
import com.gamss.android.feature.game.navigation.ClickerGameKey
import com.gamss.android.feature.game.navigation.GameKey
import com.gamss.android.feature.home.navigation.HomeKey
import com.gamss.android.feature.login.navigation.LoginKey
import com.gamss.android.feature.onboarding.navigation.OnboardingKey
Expand All @@ -32,6 +34,8 @@ private val screenNames: Map<NavKey, String> = mapOf(
ArchiveKey to "archive",
SettingKey to "setting",
AccountInfoKey to "account_info",
GameKey to "game_list",
ClickerGameKey to "clicker_game",
)

/** 새 화면 key 를 추가하면 여기에도 이름을 붙여야 집계된다. MainKey 는 탭을 담는 틀이라 세지 않는다. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.gamss.android.core.designsystem.component.GamssBottomBarItem
import com.gamss.android.core.designsystem.component.GamssIcons
import com.gamss.android.feature.archive.navigation.ArchiveKey
import com.gamss.android.feature.chat.navigation.ChatKey
import com.gamss.android.feature.game.navigation.GameKey
import com.gamss.android.feature.home.navigation.HomeKey

data class TopLevelDestination(
Expand All @@ -22,6 +23,7 @@ fun topLevelDestinations(): List<TopLevelDestination> = listOf(
TopLevelDestination(key = ArchiveKey, iconRes = GamssIcons.TabArchive, labelRes = R.string.tab_archive),
TopLevelDestination(key = HomeKey, iconRes = GamssIcons.TabHome, labelRes = R.string.tab_home),
TopLevelDestination(key = ChatKey, iconRes = GamssIcons.TabChat, labelRes = R.string.tab_chat),
TopLevelDestination(key = GameKey, iconRes = GamssIcons.TabGame, labelRes = R.string.tab_game),
)

fun List<TopLevelDestination>.keys(): Set<NavKey> = map { it.key }.toSet()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="tab_archive">보관함</string>
<string name="tab_home">홈</string>
<string name="tab_chat">대화</string>
<string name="tab_game">오락</string>

<string name="back_press_exit_confirm">뒤로가기를 한 번 더 누르면 종료돼요</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.gamss.android.feature.archive.navigation.ArchiveKey
import com.gamss.android.feature.carddelete.navigation.CardDeleteKey
import com.gamss.android.feature.chat.navigation.ChatKey
import com.gamss.android.feature.chat.navigation.ChatRoomKey
import com.gamss.android.feature.game.navigation.ClickerGameKey
import com.gamss.android.feature.game.navigation.GameKey
import com.gamss.android.feature.home.navigation.HomeKey
import com.gamss.android.feature.login.navigation.LoginKey
import com.gamss.android.feature.onboarding.navigation.OnboardingKey
Expand Down Expand Up @@ -41,6 +43,8 @@ class ScreenViewTest {
AccountInfoKey,
NicknameChangeKey("감쓰"),
WebViewKey(GamssWebPage.ServiceTerms),
GameKey,
ClickerGameKey,
)
keys.forEach { assertNotNull("$it", it.toScreenView()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package com.gamss.android.app.navigation

import com.gamss.android.feature.archive.navigation.ArchiveKey
import com.gamss.android.feature.chat.navigation.ChatKey
import com.gamss.android.feature.game.navigation.GameKey
import com.gamss.android.feature.home.navigation.HomeKey
import org.junit.Assert.assertEquals
import org.junit.Test

class TopLevelDestinationTest {

@Test
fun 탭은_보관함_홈_대화_세_종이다() {
assertEquals(listOf(ArchiveKey, HomeKey, ChatKey), topLevelDestinations().map { it.key })
fun 탭은_보관함_홈_대화_오락_네_종이다() {
assertEquals(listOf(ArchiveKey, HomeKey, ChatKey, GameKey), topLevelDestinations().map { it.key })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.compose.ui.unit.dp
import com.gamss.android.core.designsystem.theme.GamssTheme

private val BottomBarHeight = 66.dp
private val ItemRowWidth = 255.dp
private val ItemRowWidth = 312.dp
private val ItemRowHeight = 44.dp
private val ItemIconSize = 26.dp
private val ItemLabelGap = 4.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ object GamssIcons {
@DrawableRes
val TabChat: Int = R.drawable.ic_tab_chat

@DrawableRes
val TabGame: Int = R.drawable.ic_tab_game

@DrawableRes
val RightChevron: Int = R.drawable.ic_right_chevron

Expand Down
25 changes: 25 additions & 0 deletions core/designsystem/src/main/res/drawable/ic_tab_game.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:translateX="1.465"
android:translateY="0.769">
<path
android:pathData="M20.2592,15.4561C20.1833,16.1847 19.8481,16.7762 19.2535,17.2307C18.6588,17.6852 18.0564,18.1387 17.4462,18.5912C16.836,19.0437 16.1899,19.4427 15.5078,19.7883C14.8257,20.1338 14.1085,20.367 13.3562,20.4878C12.6039,20.6085 11.865,20.7678 11.1396,20.9654C10.4142,21.1631 9.68015,21.3461 8.93754,21.5142C8.19493,21.6824 7.44345,21.7431 6.68309,21.6964C5.92274,21.6498 5.17671,21.5304 4.44502,21.3383C3.71333,21.1462 2.96832,20.9695 2.20999,20.8082C1.45166,20.6469 0.987884,20.1831 0.818656,19.4167C0.649427,18.6503 0.792902,17.9492 1.24908,17.3134C1.70526,16.6775 2.27228,16.1873 2.95015,15.8428C3.62801,15.4982 4.30092,15.1563 4.96888,14.8169C5.63685,14.4776 6.32391,14.1704 7.03008,13.8953C7.73625,13.6203 8.45329,13.3797 9.18118,13.1736C9.90907,12.9675 10.6573,12.8714 11.4259,12.8853C12.1945,12.8992 12.9517,12.8175 13.6977,12.6402C14.4437,12.4629 15.1939,12.4234 15.9482,12.5219C16.7025,12.6204 17.4471,12.7693 18.1819,12.9687C18.9168,13.168 19.4323,13.4716 19.7285,13.8795C20.0248,14.2874 20.2062,14.47 20.2729,14.4273C20.3396,14.3846 20.335,14.7276 20.2592,15.4561Z"
android:strokeWidth="1.5"
android:strokeColor="#C2C7D1"
android:strokeLineCap="round"/>
<path
android:pathData="M10.5621,16.6102V16.5102C10.4852,15.0668 10.4956,13.9677 10.5934,13.2127C10.6912,12.4577 10.695,11.7027 10.6048,10.9477C10.5146,10.1927 10.4507,9.61435 10.4133,9.21268C10.3759,8.81102 10.3913,8.61018 10.4596,8.61018L10.5621,8.71018V8.61018"
android:strokeWidth="1.5"
android:strokeColor="#C2C7D1"
android:strokeLineCap="round"/>
<path
android:pathData="M14.2989,5.71421C14.1234,6.45023 13.7271,7.02716 13.1101,7.44502C12.4932,7.86288 11.8272,8.17148 11.1123,8.37083C10.3974,8.57018 9.67863,8.53192 8.956,8.25606C8.23337,7.9802 7.6873,7.50672 7.31777,6.83563C6.94824,6.16454 6.75488,5.45804 6.73771,4.71613C6.72053,3.97423 6.87952,3.26092 7.21465,2.57623C7.54979,1.89153 8.06737,1.38723 8.7674,1.0633C9.46743,0.739381 10.1769,0.666647 10.8957,0.845102C11.6145,1.02356 12.3118,1.28564 12.9877,1.63134C13.6635,1.97704 14.1074,2.52276 14.3192,3.2685C14.5311,4.01424 14.6245,4.42429 14.5996,4.49865C14.5746,4.573 14.4744,4.97819 14.2989,5.71421Z"
android:strokeWidth="1.5"
android:strokeColor="#C2C7D1"
android:strokeLineCap="round"/>
</group>
</vector>
357 changes: 357 additions & 0 deletions docs/clicker-game.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions feature/game/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
alias(libs.plugins.gamss.android.feature)
}

android {
namespace = "com.gamss.android.feature.game"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.gamss.android.feature.game

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.gamss.android.core.designsystem.component.GamssIconButton
import com.gamss.android.core.designsystem.component.GamssIcons
import com.gamss.android.core.designsystem.component.GamssLogo
import com.gamss.android.core.designsystem.component.GamssTopBar
import com.gamss.android.core.designsystem.theme.GamssTheme

@Composable
fun GameListScreen(
onNavigateToSetting: () -> Unit,
onClickerGameClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier.fillMaxSize()) {
GamssTopBar(
contentPadding = PaddingValues(start = TopBarStartPadding, end = TopBarEndPadding),
leading = { GamssLogo(contentDescription = stringResource(R.string.game_logo_description)) },
trailing = {
GamssIconButton(
iconRes = GamssIcons.Setting,
contentDescription = stringResource(R.string.game_setting_description),
onClick = onNavigateToSetting,
)
},
)
GameCard(
onClick = onClickerGameClick,
modifier = Modifier.padding(start = CardStartPadding, top = CardTopPadding),
)
}
}

@Composable
private fun GameCard(
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier
.width(CardWidth)
.clickable(role = Role.Button, onClick = onClick),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(CardLabelGap),
) {
Image(
painter = painterResource(R.drawable.game_clicker_thumbnail),
contentDescription = null,
modifier = Modifier.size(width = CardWidth, height = ThumbnailHeight),
)
Text(
text = stringResource(R.string.game_clicker_title),
style = GamssTheme.typography.body3Medium,
color = GamssTheme.colors.gray950,
textAlign = TextAlign.Center,
)
}
}

private val TopBarStartPadding = 20.dp
private val TopBarEndPadding = 8.dp
private val CardStartPadding = 24.dp

// 시안의 상단바(64dp)보다 GamssTopBar(62dp)가 2dp 낮아 그만큼 더한다.
private val CardTopPadding = 33.dp

private val CardWidth = 157.dp
private val ThumbnailHeight = 143.67.dp
private val CardLabelGap = 12.dp

@Preview(showBackground = true, widthDp = 402, heightDp = 874)
@Composable
@Suppress("UnusedPrivateMember")
private fun GameListScreenPreview() {
GamssTheme(darkTheme = false) {
GameListScreen(onNavigateToSetting = {}, onClickerGameClick = {})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.gamss.android.feature.game.clicker

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameMillis
import kotlin.math.roundToInt

// 화면이 가려지면 프레임이 멈춘다. 돌아왔을 때 그 공백을 한 프레임으로 몰아 받으면 시간이
// 한꺼번에 흘러가 버리므로, 한 프레임에 반영하는 시간을 제한해 가려진 동안은 멈춘 것으로 친다.
private const val MAX_FRAME_DELTA_MS = 100L
private const val PERCENT = 100f

/** [gauge] 는 매 프레임 바뀌므로 그리기 단계에서만 읽는다. */
@Stable
internal class ClickerGameController(initial: ClickerGameState = ClickerGameState()) {
var state by mutableStateOf(initial)
private set

val isPlaying by derivedStateOf { state.phase == ClickerGamePhase.Playing }
val record by derivedStateOf { state.record }

// 접근성 값이 매 프레임 바뀌지 않도록 1% 단위로 끊는다.
val gaugeProgress by derivedStateOf { (state.gauge * PERCENT).roundToInt() / PERCENT }

val gauge: Float get() = state.gauge

fun tap(): Boolean {
val next = state.tap()
if (next === state) return false
state = next
return true
}

fun replay() {
state = ClickerGameState()
}

suspend fun runClock(): Nothing {
var lastFrameMs = withFrameMillis { it }
while (true) {
val frameMs = withFrameMillis { it }
state = state.advance((frameMs - lastFrameMs).coerceAtMost(MAX_FRAME_DELTA_MS))
lastFrameMs = frameMs
}
}

companion object {
val Saver = listSaver<ClickerGameController, Any>(
save = { with(it.state) { listOf(phase.name, gauge, elapsedMs) } },
restore = {
ClickerGameController(
ClickerGameState(
phase = ClickerGamePhase.valueOf(it[0] as String),
gauge = it[1] as Float,
elapsedMs = it[2] as Long,
),
)
},
)
}
}

@Composable
internal fun rememberClickerGameController(): ClickerGameController =
rememberSaveable(saver = ClickerGameController.Saver) { ClickerGameController() }
Loading
Loading