Skip to content

Commit

Permalink
トリックオアトリート
Browse files Browse the repository at this point in the history
  • Loading branch information
vaaaaanquish committed Jun 21, 2024
1 parent 735a0f8 commit 6ee00f6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
3 changes: 2 additions & 1 deletion torisetsu/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ local.properties
kotlin-js-store/yarn.lock

# generated from base.html
index.html
src/jsMain/resources/*.html
!src/jsMain/resources/base.html
6 changes: 2 additions & 4 deletions torisetsu/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ repositories {
// aoitori
copy {
from("src/jsMain/resources/base.html")
into("src/jsMain/resources/aoitori/")
into("src/jsMain/resources/")
expand(mapOf(
"scriptPath" to "..",
"ogpImageName" to "aoitori.png"
))
rename("base", "index")
rename("base", "aoitori")
}
// main
copy {
from("src/jsMain/resources/base.html")
into("src/jsMain/resources/")
expand(mapOf(
"scriptPath" to "..",
"ogpImageName" to "banner.png"
))
rename("base", "index")
Expand Down
34 changes: 16 additions & 18 deletions torisetsu/src/jsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@ import core.ComposeQuiz
import core.ComposeResult
import core.Quiz
import core.Result
import kotlinx.browser.window

@Composable
fun App() {
var resultId by remember { mutableStateOf(0) }
var currentPage by remember { mutableStateOf(Page.TOP) }
val quiz: Quiz by remember { mutableStateOf(ComposeQuiz()) }
val result: Result by remember { mutableStateOf(ComposeResult()) }


when (currentPage) {
Page.TOP -> TopPage(
onClickStart = { currentPage = Page.QUIZ }
)

Page.QUIZ -> QuizPage(
quiz = quiz,
onClickFinish = { nextId: Int ->
resultId = nextId
currentPage = Page.RESULT
if (window.location.pathname in listOf("/", "")) {
when (currentPage) {
Page.TOP -> {
TopPage(
onClickStart = { currentPage = Page.QUIZ }
)
}
)

Page.RESULT -> ResultPage(
diagnosis = result.getDiagnosis(resultId),
Page.QUIZ -> {
QuizPage(quiz = quiz)
}
}
} else {
ResultPage(
diagnosis = result.getDiagnosis(window.location.pathname),
onClickBack = {
quiz.reset()
resultId = 0
currentPage = Page.TOP
window.location.pathname = "/"
}
)
}

}
3 changes: 1 addition & 2 deletions torisetsu/src/jsMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import style.GlobalStyle

enum class Page {
TOP,
QUIZ,
RESULT
QUIZ
}

fun main() {
Expand Down
5 changes: 2 additions & 3 deletions torisetsu/src/jsMain/kotlin/components/pages/QuizPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import org.jetbrains.compose.web.dom.Text

@Composable
fun QuizPage(
quiz: Quiz,
onClickFinish: (nextId: Int) -> Unit,
quiz: Quiz
) {
PageLayout {
Div(
Expand Down Expand Up @@ -64,7 +63,7 @@ fun QuizPage(
Button(
attrs = {
onClick {
quiz.onClickNext(opt, onClickFinish)
quiz.onClickNext(opt)
}
},
) {
Expand Down
6 changes: 3 additions & 3 deletions torisetsu/src/jsMain/kotlin/components/pages/ResultPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.dom.*

@Composable
fun ResultPage(diagnosis: Diagnosis, onClickBack: () -> Unit) {
fun ResultPage(diagnosis: Diagnosis?, onClickBack: () -> Unit) {
PageLayout {
Div(
attrs = {
Expand Down Expand Up @@ -50,7 +50,7 @@ fun ResultPage(diagnosis: Diagnosis, onClickBack: () -> Unit) {
}
}
Img(
src = diagnosis.srcImg,
src = diagnosis!!.srcImg,
attrs = {
style {
width(100.percent)
Expand Down Expand Up @@ -120,7 +120,7 @@ fun ResultPage(diagnosis: Diagnosis, onClickBack: () -> Unit) {
}
}
) {
Text(diagnosis.postText)
Text(diagnosis!!.postText)
}
A(
href = "https://example.com",
Expand Down
11 changes: 9 additions & 2 deletions torisetsu/src/jsMain/kotlin/core/ComposeQuiz.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.MutableState
import data.AnswerOption
import data.Question
import kotlinx.browser.window

class ComposeQuiz : Quiz {
// TODO: Load file
Expand Down Expand Up @@ -45,12 +46,18 @@ class ComposeQuiz : Quiz {
),
),
)
private val results: List<String> = listOf(
"/aoitori.html",
"/aoitori.html",
"/aoitori.html",
"/aoitori.html"
)
override val currentQuizId: MutableState<Int> = mutableStateOf(0)
override val currentQuizNumber: MutableState<Int> = mutableStateOf(1)

override fun onClickNext(answerOption: AnswerOption, onClickFinish: (nextId: Int) -> Unit) {
override fun onClickNext(answerOption: AnswerOption) {
if (answerOption.isFinish) {
onClickFinish(answerOption.nextId)
window.location.pathname = results[answerOption.nextId]
}
currentQuizNumber.value += 1
currentQuizId.value = answerOption.nextId
Expand Down
18 changes: 11 additions & 7 deletions torisetsu/src/jsMain/kotlin/core/ComposeResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@ import data.Diagnosis

class ComposeResult() : Result {
// TODO: Load file
private val diagnosisList: List<Diagnosis> = listOf(
Diagnosis(
private val diagnosisMap: Map<String, Diagnosis> = mapOf(
"aoitori" to
Diagnosis(
typeText = "診断結果0です",
srcImg = "./images/penguin.png",
preText = "どんなインシデントでも冷静",
mainText = "タイプ\n\n狙った獲物が、現れるまで、数時間も動きを止めることができるトリで、その動じない姿はまさに頼れるシニアなエンジニア。関東では、上野動物園、千葉市動物公園で見ることができます。",
postText = "動じないエンジニア大募集!",
),
Diagnosis(
"aoitori2" to
Diagnosis(
typeText = "診断結果1です",
srcImg = "./images/penguin.png",
preText = "どんなインシデントでも冷静",
mainText = "タイプ\n\n狙った獲物が、現れるまで、数時間も動きを止めることができるトリで、その動じない姿はまさに頼れるシニアなエンジニア。関東では、上野動物園、千葉市動物公園で見ることができます。",
postText = "動じないエンジニア大募集!",
),
Diagnosis(
"aoitori3" to
Diagnosis(
typeText = "診断結果2です",
srcImg = "./images/penguin.png",
preText = "どんなインシデントでも冷静",
mainText = "タイプ\n\n狙った獲物が、現れるまで、数時間も動きを止めることができるトリで、その動じない姿はまさに頼れるシニアなエンジニア。関東では、上野動物園、千葉市動物公園で見ることができます。",
postText = "動じないエンジニア大募集!",
),
Diagnosis(
"aoitori4" to
Diagnosis(
typeText = "診断結果3です",
srcImg = "./images/penguin.png",
preText = "どんなインシデントでも冷静",
Expand All @@ -35,7 +39,7 @@ class ComposeResult() : Result {
),
)

override fun getDiagnosis(resultId: Int): Diagnosis {
return diagnosisList[resultId]
override fun getDiagnosis(resultPathName: String): Diagnosis? {
return diagnosisMap.get(resultPathName.replace("/", "").replace(".html", ""))
}
}
2 changes: 1 addition & 1 deletion torisetsu/src/jsMain/kotlin/core/Quiz.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import data.AnswerOption
interface Quiz {
val currentQuizId: MutableState<Int>
val currentQuizNumber: MutableState<Int>
fun onClickNext(answerOption: AnswerOption, onClickFinish: (nextId: Int) -> Unit)
fun onClickNext(answerOption: AnswerOption)
fun getAnswerOptions(): List<AnswerOption>
fun getQuestionText(): String
fun reset()
Expand Down
2 changes: 1 addition & 1 deletion torisetsu/src/jsMain/kotlin/core/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package core
import data.Diagnosis

interface Result {
fun getDiagnosis(resultId: Int): Diagnosis
fun getDiagnosis(resultPathName: String): Diagnosis?
}
2 changes: 1 addition & 1 deletion torisetsu/src/jsMain/resources/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<body>
<div id="root">
</div>
<script src="${scriptPath}/torisetsu.js"></script>
<script src="torisetsu.js"></script>
</body>
</html>

0 comments on commit 6ee00f6

Please sign in to comment.