Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
indent_style = space
indent_size = 4
continuation_indent_size = 4
max_line_length = off
ktlint_code_style = ktlint_official
56 changes: 35 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
alias(libs.plugins.intellijPlatform)
alias(libs.plugins.changelog)
alias(libs.plugins.kover)
alias(libs.plugins.ktlint)
}

group = properties("pluginGroup").get()
Expand All @@ -34,12 +35,12 @@ dependencies {
bundledPlugins(
properties("platformBundledPlugins").map {
it.split(",").map(String::trim).filter(String::isNotEmpty)
}
},
)
plugins(
properties("platformPlugins").map {
it.split(",").map(String::trim).filter(String::isNotEmpty)
}
},
)
}
}
Expand Down Expand Up @@ -67,29 +68,31 @@ intellijPlatform {
name = properties("pluginName")
version = properties("pluginVersion")

description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
description =
providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
}

val changelog = project.changelog
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
changeNotes =
properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
}

ideaVersion {
sinceBuild = properties("pluginSinceBuild")
Expand All @@ -101,8 +104,14 @@ intellijPlatform {
token = providers.environmentVariable("PUBLISH_TOKEN")
channels.set(
properties("pluginVersion").map {
listOf(it.split("-").getOrElse(1) { "default" }.split(".").first())
}
listOf(
it
.split("-")
.getOrElse(1) { "default" }
.split(".")
.first(),
)
},
)
}

Expand All @@ -128,6 +137,11 @@ kover {
}
}

ktlint {
version.set(libs.versions.ktlint)
outputToConsole.set(true)
}

tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ changelog = "2.5.0"
intellijPlatform = "2.16.0"
kotlin = "2.3.21"
kover = "0.9.8"
ktlint = "1.8.0"
ktlintGradle = "14.2.0"

[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
Expand All @@ -14,3 +16,4 @@ changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
intellijPlatform = { id = "org.jetbrains.intellij.platform", version.ref = "intellijPlatform" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle" }
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import org.jetbrains.annotations.PropertyKey
private const val BUNDLE = "messages.CodeXPBundle"

object CodeXPBundle : DynamicBundle(BUNDLE) {

@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)
fun message(
@PropertyKey(resourceBundle = BUNDLE) key: String,
vararg params: Any,
) = getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
fun messagePointer(
@PropertyKey(resourceBundle = BUNDLE) key: String,
vararg params: Any,
) = getLazyMessage(key, *params)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class CodeXPStartupActivity : StartupActivity {
ApplicationManager.getApplication().getService(CodeXPService::class.java)
CodeXPUIManager.createDialogArea()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.github.ilovegamecoding.intellijcodexp.enums
/**
* Event enum for the plugin events.
*/
enum class Event(val xpValue: Long) {
enum class Event(
val xpValue: Long,
) {
NONE(0),
TYPING(2),
CUT(1),
Expand All @@ -16,5 +18,5 @@ enum class Event(val xpValue: Long) {
BUILD(5),
RUN(10),
DEBUG(20),
ACTION(5);
}
ACTION(5),
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.github.ilovegamecoding.intellijcodexp.enums
/**
* Position enum for the gained XP label.
*/
enum class PositionToDisplayGainedXP(val x: Int, val y: Int) {
enum class PositionToDisplayGainedXP(
val x: Int,
val y: Int,
) {
TOP(0, -1),
TOP_LEFT(-1, -1),
LEFT(-1, 0),
BOTTOM_LEFT(-1, 1),
BOTTOM(0, 1),
BOTTOM_RIGHT(1, 1),
RIGHT(1, 0),
TOP_RIGHT(1, -1)
}
TOP_RIGHT(1, -1),
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ interface CodeXPEventListener {
* @param event The event that occurred.
* @param dataContext The data context of the event.
*/
fun eventOccurred(event: Event, dataContext: DataContext? = null)
}
fun eventOccurred(
event: Event,
dataContext: DataContext? = null,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ interface CodeXPListener {
*
* @param challenge Updated challenge.
*/
fun challengeUpdated(event: Event, challenge: CodeXPChallenge, newChallenge: CodeXPChallenge? = null)
fun challengeUpdated(
event: Event,
challenge: CodeXPChallenge,
newChallenge: CodeXPChallenge? = null,
)

/**
* Function that is called when challenge completed.
*
* @param challenge Completed challenge.
*/
fun challengeCompleted(event: Event, challenge: CodeXPChallenge)
}
fun challengeCompleted(
event: Event,
challenge: CodeXPChallenge,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ import com.intellij.openapi.application.ApplicationManager
* This class listens to events from the IDE and fires them to the message bus.
*/
internal class IdeEventListener : AnActionListener {
override fun afterEditorTyping(c: Char, dataContext: DataContext) {
override fun afterEditorTyping(
c: Char,
dataContext: DataContext,
) {
super.afterEditorTyping(c, dataContext)

fireEvent(Event.TYPING, dataContext)
}

override fun afterActionPerformed(action: AnAction, event: AnActionEvent, result: AnActionResult) {
override fun afterActionPerformed(
action: AnAction,
event: AnActionEvent,
result: AnActionResult,
) {
super.afterActionPerformed(action, event, result)

when (action.templateText) {
Expand All @@ -45,8 +52,14 @@ internal class IdeEventListener : AnActionListener {
* @param event The event to fire.
* @param dataContext The data context of the event.
*/
private fun fireEvent(event: Event, dataContext: DataContext? = null) {
ApplicationManager.getApplication().messageBus.syncPublisher(CodeXPEventListener.CODEXP_EVENT)
private fun fireEvent(
event: Event,
dataContext: DataContext? = null,
) {
ApplicationManager
.getApplication()
.messageBus
.syncPublisher(CodeXPEventListener.CODEXP_EVENT)
.eventOccurred(event, dataContext)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ object CodeXPNotificationManager {
private val notificationGroup: NotificationGroup =
NotificationGroupManager.getInstance().getNotificationGroup("CodeXP")

private fun notify(title: String, content: String) {
private fun notify(
title: String,
content: String,
) {
notificationGroup.createNotification(title, content, NotificationType.INFORMATION).notify(null)
}

fun notifyChallengeComplete(codeXPChallenge: CodeXPChallenge) {
notify("${codeXPChallenge.name} completed!", "Reward: ${codeXPChallenge.rewardXP} XP")
}

fun notifyLevelUp(nickname: String, level: Int, xpToNextLevel: Long) {
fun notifyLevelUp(
nickname: String,
level: Int,
xpToNextLevel: Long,
) {
notify(
"Level up!",
"Congratulations $nickname! You are now level $level. You need $xpToNextLevel XP to reach the next level."
"Congratulations $nickname! You are now level $level. You need $xpToNextLevel XP to reach the next level.",
)
}
}
}
Loading