Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed Aug 18, 2023
1 parent 7e70a82 commit 5f449a3
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 60 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ configureAutoVersions()
allprojects { repositories {
mavenLocal(); mavenCentral(); google(); gradlePluginPortal()
maven("https://maven.pkg.github.com/cy6ergn0m/kotlinx-uuid")
} }
} }
51 changes: 40 additions & 11 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ korge {
icon = File(projectDir, "src/commonMain/resources/images/logo.png"
.replace("/", File.separator))
exeBaseName = "Skeep"
name = "Skeep"
androidManifestChunks.addAll(setOf(
"""<uses-permission android:name="android.permission.INTERNET" />""",
"""<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />"""
))
}

kotlin {
jvm()
sourceSets {
val commonMain by getting {
kotlin.addSrcDir(File(project(":shared").projectDir, "src/commonMain/kotlin"))
dependencies {
api(project(":shared"))
api("de.cketti.unicode:kotlin-codepoints-deluxe:0.6.1")
api(project(":deps"))
api(libs.kotlinx.uuid)
api(libs.kotlinx.serialization)
api(libs.koin)
api(libs.ktor.client.auth)
api(libs.ktor.client.content.negotation)
api(libs.ktor.serialization.kotlinx.protobuf)
}
}
val jsMain by getting {
Expand All @@ -44,6 +56,12 @@ kotlin {
api(libs.logback)
}
}
val androidMain by getting {
dependencies {
api(libs.ktor.client.cio)
api(libs.logback)
}
}
runCatching {
val mingwX64Main by getting {
dependencies {
Expand All @@ -65,21 +83,32 @@ kotlin {
}
}
}
linuxArm64().apply {
configurations.filter { it.name.contains("linuxArm64") }.forEach {
it.exclude(libs.kotlinx.uuid.asProvider())
it.exclude(libs.kotlinx.serialization)
it.exclude(libs.koin)
it.exclude(libs.ktor.client.auth)
it.exclude(libs.ktor.client.content.negotation)
it.exclude(libs.ktor.serialization.kotlinx.json)
configurations.filter { listOf(
"linuxArm64", "linuxArm64Main", "linuxX64", "linuxX64Main"
).contains(it.name) }.forEach {
it.exclude(libs.kotlinx.uuid.asProvider())
it.exclude(libs.kotlinx.serialization)
it.exclude(libs.koin)
it.exclude(libs.ktor.client.auth)
it.exclude(libs.ktor.client.content.negotation)
it.exclude(libs.ktor.serialization.kotlinx.json)

}
}
}


fun Configuration.exclude(provider: Provider<MinimalExternalModuleDependency>) {
val module = provider.get().module
exclude(group = module.group, module = module.name)
}
}

fun SourceDirectorySet.addSrcDir(file: File) {
setSrcDirs(srcDirs.apply { add(file) })
}

@Suppress("UnstableApiUsage")
tasks.withType<ProcessResources> {
filesMatching("client.properties") {
expand(rootProject.properties)
}
}
34 changes: 34 additions & 0 deletions client/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
>

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />
<application

android:allowBackup="true"
android:label="Skeep"
android:icon="@mipmap/icon"
android:roundIcon="@android:drawable/sym_def_app_icon"
android:theme="@style/AppThemeOverride"
android:supportsRtl="true"
>
<profileable android:shell="true" />
<activity android:name=".MainActivity"
android:banner="@drawable/app_banner"
android:icon="@drawable/app_icon"
android:label="Skeep"
android:logo="@drawable/app_icon"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:screenOrientation="sensor"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
34 changes: 34 additions & 0 deletions client/src/androidMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import io.ktor.client.engine.cio.*
import korlibs.io.file.std.resourcesVfs
import korlibs.io.lang.readProperties
import network.ClientEngineFactory
import network.URLProvider
import org.koin.core.context.startKoin
import org.koin.core.qualifier.named
import org.koin.dsl.bind
import org.koin.dsl.module
import org.koin.mp.KoinPlatform

class Main

suspend fun runMain() {
main()
}
suspend fun main() {
val clientProps = resourcesVfs["client.properties"].readProperties()
val url = clientProps["server"]!!
val version = clientProps["version"]!!
startKoin {}
KoinPlatform.getKoin().loadModules(listOf(module {
single(named("version")) { version }
factory {
object : URLProvider {
override val url: String get() = url
}
} bind URLProvider::class
factory {
object : ClientEngineFactory { override fun getEngine() = CIO }
} bind ClientEngineFactory::class
}))
startMain()
}
2 changes: 1 addition & 1 deletion client/src/commonMain/kotlin/MainScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import util.transform
val styler: ViewStyles.() -> Unit = {
textFont = getKoin().get<Font>()
textAlignment = TextAlignment.MIDDLE_CENTER
textSize = 45f
textSize = 100f
textColor = ColorPalette.text
}

Expand Down
24 changes: 12 additions & 12 deletions client/src/commonMain/kotlin/ui/newLoginMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import korlibs.korge.ui.*
import korlibs.korge.view.Container
import korlibs.korge.view.align.*
import korlibs.korge.view.positionX
import korlibs.korge.view.solidRect
import korlibs.korge.view.zIndex
import korlibs.math.geom.RectCorners
import korlibs.math.geom.Size
Expand All @@ -30,9 +31,9 @@ import util.transform

class LoginMenuState {
val loginMenuPadding = 40f
val blockSize get() = Size(480, 75)
val loginMenuSize get() = Size(550, 500)
val loginButtonSize = Size(blockSize.width / 2 - loginMenuPadding / 2, blockSize.height)
val blockSize get() = Size(500, 140)
val loginMenuSize get() = Size(500, 500)
val loginButtonSize = Size(blockSize.width*0.65f, blockSize.height)
lateinit var input: UITextInput
lateinit var warningText: UIText
lateinit var loginMenu: Container
Expand All @@ -42,18 +43,17 @@ class LoginMenuState {

fun loginMenuView(loginMenuState: LoginMenuState = LoginMenuState()): Unit = screen.run { loginMenuState.run {
uiContainer(loginMenuSize) loginMenu@{

styles.textSize = 80f
loginMenu = this
styles(styler)
uiVerticalStack(adjustSize = false, padding = loginMenuPadding) {
uiSpacing(size = Size(0f, loginMenuPadding))
uiText("스키프").transform { centerXOn(this@loginMenu) }
uiSpacing(size = Size(0f, loginMenuPadding/2))
uiContainer(blockSize) nickNameInput@{
transform { centerXOn(this@loginMenu) }
styles.textSize = styles.textSize * 0.95f
styles.textAlignment = TextAlignment.MIDDLE_LEFT
input = customUiTextInput("닉네임", size = size) {
text = " "
}.zIndex(2).transform {
size = this@nickNameInput.size
controller.caretContainer.alignY(this, 0.75, false)
Expand All @@ -73,7 +73,7 @@ fun loginMenuView(loginMenuState: LoginMenuState = LoginMenuState()): Unit = scr
shadowColor = Colors.TRANSPARENT
bgColor = ColorPalette.base
borderColor = ColorPalette.base
borderSize = loginMenuPadding / 6
borderSize = height/12
radius = RectCorners(borderSize*2)
this@customUiButton.mouse {
onMove { borderColor = ColorPalette.hover }
Expand All @@ -84,9 +84,9 @@ fun loginMenuView(loginMenuState: LoginMenuState = LoginMenuState()): Unit = scr
transform { centerXOn(this@loginMenu) }
}
uiSpacing(size = Size(0f, loginMenuPadding))
warningText =uiText("") {
warningText = uiText("") {
styles(styler)
styles.textSize = styles.textSize * 0.75f
styles.textSize = styles.textSize * 0.5f
styles.textColor = ColorPalette.out
transform { centerXOn(this@loginMenu) }
}
Expand Down Expand Up @@ -127,15 +127,15 @@ suspend fun LoginMenuState.join() {
username = input.text.trim()
joinOnce = true
initializeClient()
val login = login()
val login: LoginResultType = login()
if (login == LoginResultType.ALREADY_JOINED) {
warningText.text = "입력하신 닉네임은 이미 사용중입니다"
joinOnce = false
return
} else if (login == LoginResultType.SERVER_IS_NOT_AVAILABLE
|| runCatching { websocketClient() }
.also { it.exceptionOrNull()?.printStackTrace() }.isFailure) {
warningText.text = "죄송합니다, 지금은 인증 서버를 사용할 수 없습니다.\n나중에 다시 시도해 주세요."
.also { it.exceptionOrNull()?.apply { println(stackTraceToString()) } }.isFailure) {
warningText.text = "지금은 서버를 사용할 수 없습니다.\n나중에 다시 시도해 주세요."
warningText.centerXOn(loginMenu)
joinOnce = false
return
Expand Down
62 changes: 37 additions & 25 deletions client/src/commonMain/kotlin/ui/waitingRoom.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import kotlin.math.max

class WaitingRoomState {
val padding = 25f
lateinit var profileSize: Size
val stackPadding = padding / 2
val profileSize get() = Size(sidebarContainerSize.width, sidebarContainerSize.height/6f - padding)
lateinit var profiles: UIVerticalStack
lateinit var chats: Container
lateinit var space: Container
Expand All @@ -52,6 +53,8 @@ class WaitingRoomState {
val titleSize get() = Size(screen.width - sidebarSize.width, belowElementHeight * 1.5f)
val textInputSize get() = inputBarSize.minus(Size(padding / 2, 0f))
val sidebarContainerSize get() = Size(sidebarSize.width - padding, sidebarSize.height - padding)
val sidebarRectSize get() = Size(sidebarContainerSize.width, (profileSize.height + padding / 2f) * 6f - stackPadding)
val chatSize get() = Size(inputBarSize.width, screen.height - titleSize.height - inputBarSize.height - padding * 3)
}

suspend fun WaitingRoomState.waitingRoom(room: UUID) {
Expand Down Expand Up @@ -85,23 +88,25 @@ suspend fun WaitingRoomState.waitingRoom(room: UUID) {
}.transform { size(titleSize).position(padding, padding) }

uiContainer(sidebarContainerSize) {
profileSize = Size(size.width, size.height/6f - padding)

val stackPadding = padding / 2
profiles = uiVerticalStack(adjustSize = true, padding = stackPadding)
solidRect(size = Size(size.width, (profileSize.height+padding/2f)*6f- stackPadding) , color = ColorPalette.base).zIndex(-1)
solidRect(size = sidebarRectSize, color = ColorPalette.base).zIndex(-1)
.transform { size(sidebarRectSize) }
transform {
size(sidebarContainerSize)
positionX(screen.width - sidebarSize.width)
positionY(padding)
}
}
customUiButton(size = leaveButton) {
val back = solidRect(size, color = ColorPalette.out).centerOn(this)
customUiButton(size = leaveButton) leaveButton@{
val back = solidRect(size, color = ColorPalette.out).transform { centerOn(this@leaveButton) }
var isDone = false
customUiText("나가기").centerOn(this)
positionX(padding)
positionY(screen.height - padding - size.height)
customUiText("나가기").transform { centerOn(this@leaveButton) }
transform {
size(leaveButton)
positionX(padding)
positionY(screen.height - padding - size.height)
}
onMouseDragCloseable {
onUp up@{
if (isDone) return@up
Expand All @@ -113,21 +118,26 @@ suspend fun WaitingRoomState.waitingRoom(room: UUID) {
}
}

val chatSize = Size(inputBarSize.width, screen.height - titleSize.height - inputBarSize.height - padding * 3)
customUiScrollable(cache = true, disableMouseDrag = true, size = chatSize) {
scroll = it
it.positionX(padding + leaveButton.width + padding)
it.positionY(padding + titleSize.height + padding)
it.transform {
it.size(chatSize)
it.positionX(padding + leaveButton.width + padding)
it.positionY(padding + titleSize.height + padding)
}
it.backgroundColor = Colors.TRANSPARENT
it.horizontal.view.visible = false
it.vertical.view.visible = false
it.scrollBarAlpha = 0f
scroll.timeScrollBar = 0.seconds
scroll.horizontal.view.visible = false
scroll.scrollTopRatio = 1f
uiVerticalStack(width = size.width, padding = padding, adjustSize = false) {
uiVerticalStack(width = chatSize.width, padding = padding, adjustSize = false) {
transform {
width = chatSize.width
}
chats = this
space = uiSpacing(Size(size.width, chatSize.height))
space = uiSpacing(chatSize).transform { size(chatSize) }
styles(styler)
styles {
textAlignment = TextAlignment.MIDDLE_LEFT
Expand All @@ -138,7 +148,7 @@ suspend fun WaitingRoomState.waitingRoom(room: UUID) {
val username = packet.username
if (profiles.children.any { it.getExtra("profile") == username }) return@onEvent
chat("${username}이(가) 서버에 참여했습니다")
profile(username, profiles, profileSize)
profileView(username, profiles)
}
onEvent(PacketEvent) {
val packet = it.packet
Expand All @@ -158,15 +168,15 @@ suspend fun WaitingRoomState.waitingRoom(room: UUID) {
}
}
listPlayer().forEach {
profile(it.username, profiles, profileSize)
profileView(it.username, profiles)
}
}

fun WaitingRoomState.profile(name: String, container: Container, profileSize: Size) {
container.uiContainer(Size(profileSize.width, profileSize.height)) {
fun WaitingRoomState.profileView(name: String, container: Container) {
container.uiContainer(profileSize) profile@{
transform { size(profileSize) }
// solidRect(size, color = Colors.WHITE)
setExtra("profile", name)
val profileImageSize = Size(profileSize.height, profileSize.height)
val imageBitmap = getKoin().get<Bitmap>(named("profile")).toBMP32().apply {
updateColors {
if (it != Colors.TRANSPARENT) {
Expand All @@ -176,18 +186,20 @@ fun WaitingRoomState.profile(name: String, container: Container, profileSize: Si
}
}.slice()
uiImage(size = Size(imageBitmap.width, imageBitmap.height), bitmap = imageBitmap) {
scaleXY = profileImageSize.width / size.width
transform { scaleXY = profileSize.width / size.width }
}//}.centerYOn(this)
uiText(name) { styles.textAlignment = TextAlignment.MIDDLE_LEFT }
.alignX(this, 0.85, false)
.alignY(this, 0.15, true)

uiText(name) { styles.textAlignment = TextAlignment.MIDDLE_LEFT }.transform {
alignX(this@profile, 0.85, false)
alignY(this@profile, 0.15, true)
}
}
}

fun WaitingRoomState.chat(chat: String) {
val chat = chats.uiText(chat)
space.height = max(0f, space.height - chat.height)
space.transform {
height = max(0f, space.height - chat.height)
}
scroll.scrollTopRatio = 1f
}

Expand Down
Loading

0 comments on commit 5f449a3

Please sign in to comment.