Skip to content

Commit

Permalink
release: 1.0.5 (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: Pengoose <[email protected]>
  • Loading branch information
devxb and pengooseDev authored Dec 28, 2024
1 parent 051de19 commit 5d9cadd
Show file tree
Hide file tree
Showing 64 changed files with 1,280 additions and 1,103 deletions.
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div align="center">

**English** | [한국어](README.md) | [简体中文](README-zhcn.md)
**English** | [한국어](README.md) | [简体中文](README-zhcn.md) | [日本語](README-ja.md)

<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdevxb%2Fgitanimals&count_bg=%23000000&title_bg=%23000000&icon=&icon_color=%23000000&title=hits&edge_flat=true"/></a>
</div>
Expand Down
213 changes: 213 additions & 0 deletions README-ja.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README-zhcn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div align="center">

[English](README-en.md) | [한국어](README.md) | **简体中文**
[English](README-en.md) | [한국어](README.md) | **简体中文** | [日本語](README-ja.md)

<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdevxb%2Fgitanimals&count_bg=%23000000&title_bg=%23000000&icon=&icon_color=%23000000&title=hits&edge_flat=true"/></a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div align="center">

[English](README-en.md) | **한국어** | [简体中文](README-zhcn.md)
[English](README-en.md) | **한국어** | [简体中文](README-zhcn.md) | [日本語](README-ja.md)

<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fdevxb%2Fgitanimals&count_bg=%23000000&title_bg=%23000000&icon=&icon_color=%23000000&title=hits&edge_flat=true"/></a>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.guild.core
package org.gitanimals.core

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.render.domain
package org.gitanimals.core

enum class FieldType {

Expand Down Expand Up @@ -316,7 +316,7 @@ enum class FieldType {
override fun drawBorder(): String {
return "<rect x=\"0.5\" y=\"0.5\" width=\"599\" height=\"299\" rx=\"4.5\" stroke=\"#D9D9D9\"/>"
}
},
},
SNOW_GRASS_FIELD {
override fun loadComponent(name: String, commit: Long): String {
return snowGrassFieldSvg.replace(NAME_FIX, name.toSvg(0.0, 3.0))
Expand All @@ -341,6 +341,21 @@ enum class FieldType {
return "<rect x=\"0.5\" y=\"0.5\" width=\"599\" height=\"299\" rx=\"4.5\" stroke=\"#00894D\"/>"
}
},
LOGO_SHOWING {
override fun loadComponent(name: String, commit: Long): String {
return dummyGuildFieldSvg.replace(NAME_FIX, name.toSvg(0.0, 3.0))
.replace(COMMIT_FIX, commit.toSvg("commit", 260.0, 4.0))
}

override fun fillBackground(): String =
"""
<rect x="0.5" y="0.5" width="599" height="299" rx="4.5" fill="#1E1E1E"/>
$logoShowingFieldSvg
"""

override fun drawBorder(): String =
"<rect x=\"0.5\" y=\"0.5\" width=\"599\" height=\"299\" rx=\"4.5\" stroke=\"#D9D9D9\" fill=\"none\"/>"
}
;

abstract fun loadComponent(name: String, commit: Long): String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.guild.core
package org.gitanimals.core

import com.github.f4b6a3.tsid.TsidFactory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.render.domain
package org.gitanimals.core

enum class Mode {
FARM,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.render.domain
package org.gitanimals.core

import org.springframework.core.io.ClassPathResource
import java.nio.charset.Charset
Expand Down Expand Up @@ -38,6 +38,12 @@ val grassChristmasTreeBackgroundSvg: String =
ClassPathResource("persona/field/grass-christmastree-background.svg")
.getContentAsString(Charset.defaultCharset())

val dummyGuildFieldSvg: String = ClassPathResource("persona/field/white-field.svg")
.getContentAsString(Charset.defaultCharset())

val logoShowingFieldSvg: String = ClassPathResource("persona/field/logo-showing.svg")
.getContentAsString(Charset.defaultCharset())

val gooseSvg: String = ClassPathResource("persona/animal/goose.svg")
.getContentAsString(Charset.defaultCharset())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.guild.core
package org.gitanimals.core

import java.time.Clock
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.render.controller.interceptor
package org.gitanimals.core.interceptor

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gitanimals.render.controller.interceptor
package org.gitanimals.core.interceptor

import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
Expand Down
70 changes: 70 additions & 0 deletions src/main/kotlin/org/gitanimals/guild/app/DrawGuildFacade.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.gitanimals.guild.app

import org.gitanimals.core.Mode
import org.gitanimals.guild.domain.Guild
import org.gitanimals.guild.domain.GuildService
import org.gitanimals.guild.domain.GuildService.Companion.loadMembers
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service

@Service
class DrawGuildFacade(
private val renderApi: RenderApi,
private val guildService: GuildService,
@Value("\${internal.secret}") private val internalSecret: String,
) {

fun drawGuild(id: Long): String {
val guild = guildService.getGuildById(id, loadMembers)
val renderUsers = getRenderUsers(guild)

val svgBuilder = StringBuilder().openGuild()
.append(guild.getGuildFarmType().fillBackground())

val personaSvgs = renderUsers.map { user ->
val persona = user.personas.firstOrNull()
?: throw IllegalArgumentException("Cannot draw guild cause user does not have any persona. user: \"$user\"")

persona.type.load(
name = user.name,
contributionCount = user.totalContributions.toLong(),
animationId = persona.id.toLong(),
level = persona.level.toLong(),
mode = Mode.NAME_WITH_LEVEL,
)
}

personaSvgs.forEach { svgBuilder.append(it) }

return svgBuilder.append(
guild.getGuildFarmType().loadComponent(guild.getTitle(), guild.getTotalContributions())
).append(guild.getGuildFarmType().drawBorder())
.closeGuild()
}

private fun getRenderUsers(guild: Guild): List<RenderApi.UserResponse> {
val userIdAndPersonaIdRequests = guild.getMembers().map {
RenderApi.UserIdAndPersonaIdRequest(
personaId = it.personaId,
userId = it.userId,
)
} + RenderApi.UserIdAndPersonaIdRequest(
personaId = guild.getLeaderPersonaId(),
userId = guild.getLeaderUserId(),
)

return renderApi.getAllPersonasByUserIdsAndPersonaIds(
internalSecret = internalSecret,
userIdAndPersonaIdRequests = userIdAndPersonaIdRequests,
)
}


private fun StringBuilder.openGuild(): StringBuilder =
this.append("<svg width=\"600\" height=\"300\" viewBox=\"0 0 600 300\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">")

private fun StringBuilder.closeGuild(): String = this
.append("</svg>")
.toString()

}
25 changes: 0 additions & 25 deletions src/main/kotlin/org/gitanimals/guild/app/DrawGuildProxy.kt

This file was deleted.

22 changes: 20 additions & 2 deletions src/main/kotlin/org/gitanimals/guild/app/RenderApi.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package org.gitanimals.guild.app

import org.gitanimals.core.PersonaType
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.service.annotation.GetExchange

fun interface RenderApi {
interface RenderApi {

@GetExchange("/users/{username}")
fun getUserByName(@PathVariable("username") username: String): UserResponse

@GetExchange("/internals/personas/all")
fun getAllPersonasByUserIdsAndPersonaIds(
@RequestHeader(INTERNAL_SECRET_KEY) internalSecret: String,
@RequestBody userIdAndPersonaIdRequests: List<UserIdAndPersonaIdRequest>,
): List<UserResponse>

data class UserResponse(
val id: String,
val name: String,
Expand All @@ -18,7 +27,16 @@ fun interface RenderApi {
data class PersonaResponse(
val id: String,
val level: String,
val type: String,
val type: PersonaType,
)
}

data class UserIdAndPersonaIdRequest(
val userId: Long,
val personaId: Long,
)

private companion object {
private const val INTERNAL_SECRET_KEY = "Internal-Secret"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.gitanimals.guild.app.event

import org.gitanimals.guild.core.clock
import org.gitanimals.core.clock
import java.time.Instant

data class InboxInputEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.gitanimals.guild.app.request

import org.gitanimals.guild.domain.GuildFarmType
import org.gitanimals.core.FieldType

data class CreateGuildRequest(
val title: String,
val body: String,
val guildIcon: String,
val autoJoin: Boolean,
val farmType: GuildFarmType,
val farmType: FieldType,
val personaId: String,
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.gitanimals.guild.controller

import org.gitanimals.core.FieldType
import org.gitanimals.guild.app.*
import org.gitanimals.guild.app.request.CreateGuildRequest
import org.gitanimals.guild.controller.request.JoinGuildRequest
import org.gitanimals.guild.controller.response.*
import org.gitanimals.guild.domain.GuildFarmType
import org.gitanimals.guild.domain.GuildIcons
import org.gitanimals.guild.domain.GuildService
import org.gitanimals.guild.domain.SearchFilter
import org.gitanimals.guild.domain.extension.GuildFieldTypeExtension.isGuildField
import org.gitanimals.guild.domain.request.ChangeGuildRequest
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
Expand All @@ -25,7 +26,7 @@ class GuildController(
private val searchGuildFacade: SearchGuildFacade,
private val changeMainPersonaFacade: ChangeMainPersonaFacade,
private val leaveGuildFacade: LeaveGuildFacade,
private val drawGuildProxy: DrawGuildProxy,
private val drawGuildFacade: DrawGuildFacade,
) {

@ResponseStatus(HttpStatus.OK)
Expand Down Expand Up @@ -121,7 +122,7 @@ class GuildController(
@GetMapping("/guilds/backgrounds")
@ResponseStatus(HttpStatus.OK)
fun findAllGuildBackgrounds(): GuildBackgroundResponse {
return GuildBackgroundResponse(GuildFarmType.entries)
return GuildBackgroundResponse(FieldType.entries.filter { it.isGuildField() })
}

@PostMapping("/guilds/{guildId}/personas")
Expand All @@ -144,5 +145,5 @@ class GuildController(
@GetMapping("/guilds/{guildId}/draw")
fun draw(
@PathVariable("guildId") guildId: Long,
) = drawGuildProxy.drawGuild(guildId)
) = drawGuildFacade.drawGuild(guildId)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.gitanimals.guild.controller.response

import org.gitanimals.guild.domain.GuildFarmType
import org.gitanimals.core.FieldType

data class GuildBackgroundResponse(
val backgrounds: List<GuildFarmType>
val backgrounds: List<FieldType>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gitanimals.guild.controller.response

import com.fasterxml.jackson.annotation.JsonFormat
import org.gitanimals.core.PersonaType
import org.gitanimals.guild.domain.Guild
import java.time.Instant

Expand All @@ -26,7 +27,7 @@ data class GuildResponse(
val name: String,
val contributions: String,
val personaId: String,
val personaType: String,
val personaType: PersonaType,
)

data class Member(
Expand All @@ -35,7 +36,7 @@ data class GuildResponse(
val name: String,
val contributions: String,
val personaId: String,
val personaType: String,
val personaType: PersonaType,
)

data class WaitMember(
Expand All @@ -44,7 +45,7 @@ data class GuildResponse(
val name: String,
val contributions: String,
val personaId: String,
val personaType: String,
val personaType: PersonaType,
)

companion object {
Expand Down
Loading

0 comments on commit 5d9cadd

Please sign in to comment.