Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed Aug 6, 2023
1 parent c508870 commit 2a38f06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 14 additions & 7 deletions client/src/commonMain/kotlin/ui/MainMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import sceneContainer
import ui.custom.customUiButton
import ui.custom.customUiScrollable
import util.ColorPalette
import websocket.createRoom
import websocket.getViewedRooms
import websocket.joinRoom
import websocket.*
import kotlin.math.PI

class MainMenuState {
Expand Down Expand Up @@ -82,9 +80,19 @@ suspend fun MainMenuState.mainMenu() {
uiHorizontalStack(height = top.height*0.75f, padding = padding*2) {
val bottomButtonSize = Size(top.heightD * PI, .0)
customUiButton(size = bottomButtonSize).bottomButton("방 생성").onClick {
lateinit var loading: Container
loading = sceneContainer.uiContainer {
serverList.visible = false
loadingMenu("방 생성 중...") {
serverList.visible = true
loading.removeFromParent()
}
}
val room = createRoom()
serverList.removeFromParent()
joinRoom(room.uuid)
websocketClient()
serverList.removeFromParent()
loading.removeFromParent()
WaitingRoomState().waitingRoom(room.uuid)
}
customUiButton(size = bottomButtonSize).bottomButton("새로고침").onClick {
Expand Down Expand Up @@ -178,17 +186,16 @@ fun MainMenuState.room(room: ViewedRoom) {
}.centerXOn(sceneContainer)
}

fun Container.loadingMenu(text: String, buttonText: String, onClick: () -> Unit): UIText {
fun Container.loadingMenu(text: String, buttonText: String? = null, onClick: () -> Unit): UIText {
val text = uiText(text) {
styles(styler)
centerOnStage()
alignY(containerRoot, 0.4, true)
}
lateinit var cancelText: View
val button =
customUiButton(size = Size(sceneContainer.width * 0.471f, sceneContainer.width / 25)) {
styles(styler)
cancelText = bottomButton(buttonText).centerOn(this)
if (buttonText !== null) bottomButton(buttonText).centerOn(this)
centerXOnStage()
alignY(containerRoot, 0.6, true)
onClick {
Expand Down
6 changes: 5 additions & 1 deletion client/src/commonMain/kotlin/websocket/websocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import sceneContainer
import util.launchNow

var _websocketClient: WebSocketClient? = null
private var websocketSemaphore = false
suspend fun websocketClient(): WebSocketClient {
if (_websocketClient === null) {
_websocketClient = newWebsocketClient()
if (websocketSemaphore) throw AssertionError("blocked by semaphore")
websocketSemaphore = true
try { _websocketClient = newWebsocketClient() }
finally { websocketSemaphore = false }
}
return _websocketClient!!
}
Expand Down

0 comments on commit 2a38f06

Please sign in to comment.