mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Desktop Unciv now sends status to Discord!
Basically stole the Discord RPC implementation outta Mindustry
This commit is contained in:
parent
a4dac0f67a
commit
62fd7d8588
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 872 KiB After Width: | Height: | Size: 874 KiB |
@ -2,7 +2,6 @@ buildscript {
|
|||||||
|
|
||||||
ext.kotlinVersion = '1.3.50'
|
ext.kotlinVersion = '1.3.50'
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Chinese mirrors for quicker loading for chinese devs
|
// Chinese mirrors for quicker loading for chinese devs
|
||||||
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
|
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
|
||||||
@ -14,6 +13,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
jcenter()
|
jcenter()
|
||||||
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
||||||
@ -49,6 +49,7 @@ allprojects {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
|
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
|
||||||
|
maven{ url 'https://jitpack.io' } // for java-discord-rpc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,9 +64,10 @@ project(":desktop") {
|
|||||||
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
|
implementation "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
|
||||||
|
|
||||||
implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion" // This is for the TexturePacker class
|
implementation "com.badlogicgames.gdx:gdx-tools:$gdxVersion" // This is for the TexturePacker class
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" // This iss so the JAR works with Kotlin
|
||||||
}
|
|
||||||
|
|
||||||
|
implementation 'com.github.MinnDevelopment:java-discord-rpc:v2.0.1'
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class UnCivGame(val version: String) : Game() {
|
|||||||
|
|
||||||
var music : Music? =null
|
var music : Music? =null
|
||||||
val musicLocation = "music/thatched-villagers.mp3"
|
val musicLocation = "music/thatched-villagers.mp3"
|
||||||
|
var isInitialized=false
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
Current = this
|
Current = this
|
||||||
@ -58,6 +59,7 @@ class UnCivGame(val version: String) : Game() {
|
|||||||
else setScreen(LanguagePickerScreen())
|
else setScreen(LanguagePickerScreen())
|
||||||
|
|
||||||
thread { startMusic() }
|
thread { startMusic() }
|
||||||
|
isInitialized=true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startMusic(){
|
fun startMusic(){
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package com.unciv.app.desktop;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Files;
|
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
|
|
||||||
import com.unciv.UnCivGame;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
class DesktopLauncher {
|
|
||||||
public static void main (String[] arg) {
|
|
||||||
|
|
||||||
if (new File("../Images").exists()) { // So we don't run this from within a fat JAR
|
|
||||||
TexturePacker.Settings settings = new TexturePacker.Settings();
|
|
||||||
// Apparently some chipsets, like NVIDIA Tegra 3 graphics chipset (used in Asus TF700T tablet),
|
|
||||||
// don't support non-power-of-two texture sizes - kudos @yuroller!
|
|
||||||
// https://github.com/yairm210/UnCiv/issues/1340
|
|
||||||
settings.maxWidth = 2048;
|
|
||||||
settings.maxHeight = 2048;
|
|
||||||
settings.combineSubdirectories = true;
|
|
||||||
settings.pot = true;
|
|
||||||
settings.fast = true;
|
|
||||||
|
|
||||||
// This is so they don't look all pixelated
|
|
||||||
settings.filterMag = Texture.TextureFilter.MipMapLinearLinear;
|
|
||||||
settings.filterMin = Texture.TextureFilter.MipMapLinearLinear;
|
|
||||||
TexturePacker.process(settings, "../Images", ".", "game");
|
|
||||||
}
|
|
||||||
|
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
|
||||||
config.addIcon("ExtraImages/Icon.png", Files.FileType.Internal);
|
|
||||||
config.title="Unciv";
|
|
||||||
new LwjglApplication(new UnCivGame("Desktop"), config);
|
|
||||||
}
|
|
||||||
}
|
|
72
desktop/src/com/unciv/app/desktop/DesktopLauncher.kt
Normal file
72
desktop/src/com/unciv/app/desktop/DesktopLauncher.kt
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package com.unciv.app.desktop
|
||||||
|
|
||||||
|
import club.minnced.discord.rpc.DiscordEventHandlers
|
||||||
|
import club.minnced.discord.rpc.DiscordRPC
|
||||||
|
import club.minnced.discord.rpc.DiscordRichPresence
|
||||||
|
import com.badlogic.gdx.Files
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||||
|
import com.badlogic.gdx.graphics.Texture
|
||||||
|
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||||
|
import com.unciv.UnCivGame
|
||||||
|
import com.unciv.models.gamebasics.tr
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
internal object DesktopLauncher {
|
||||||
|
@JvmStatic
|
||||||
|
fun main(arg: Array<String>) {
|
||||||
|
|
||||||
|
if (File("../Images").exists()) { // So we don't run this from within a fat JAR
|
||||||
|
val settings = TexturePacker.Settings()
|
||||||
|
// Apparently some chipsets, like NVIDIA Tegra 3 graphics chipset (used in Asus TF700T tablet),
|
||||||
|
// don't support non-power-of-two texture sizes - kudos @yuroller!
|
||||||
|
// https://github.com/yairm210/UnCiv/issues/1340
|
||||||
|
settings.maxWidth = 2048
|
||||||
|
settings.maxHeight = 2048
|
||||||
|
settings.combineSubdirectories = true
|
||||||
|
settings.pot = true
|
||||||
|
settings.fast = true
|
||||||
|
|
||||||
|
// This is so they don't look all pixelated
|
||||||
|
settings.filterMag = Texture.TextureFilter.MipMapLinearLinear
|
||||||
|
settings.filterMin = Texture.TextureFilter.MipMapLinearLinear
|
||||||
|
TexturePacker.process(settings, "../Images", ".", "game")
|
||||||
|
}
|
||||||
|
|
||||||
|
val config = LwjglApplicationConfiguration()
|
||||||
|
config.addIcon("ExtraImages/Icon.png", Files.FileType.Internal)
|
||||||
|
config.title = "Unciv"
|
||||||
|
|
||||||
|
|
||||||
|
val game = UnCivGame("Desktop")
|
||||||
|
|
||||||
|
try {
|
||||||
|
val handlers = DiscordEventHandlers()
|
||||||
|
DiscordRPC.INSTANCE.Discord_Initialize("647066573147996161", handlers, true, null)
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(Thread { DiscordRPC.INSTANCE.Discord_Shutdown() })
|
||||||
|
|
||||||
|
thread {
|
||||||
|
while(true){
|
||||||
|
updateRpc(game)
|
||||||
|
Thread.sleep(1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
print("Could not initialize Discord")
|
||||||
|
}
|
||||||
|
|
||||||
|
LwjglApplication(game, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateRpc(game: UnCivGame) {
|
||||||
|
if(!game.isInitialized) return
|
||||||
|
val presence = DiscordRichPresence()
|
||||||
|
val currentPlayerCiv = game.gameInfo.getCurrentPlayerCivilization()
|
||||||
|
presence.details=currentPlayerCiv.getTranslatedNation().getLeaderDisplayName().tr()
|
||||||
|
presence.largeImageKey = "logo" // The actual image is uploaded to the discord app / applications webpage
|
||||||
|
presence.largeImageText ="Turn".tr()+" " + currentPlayerCiv.gameInfo.turns
|
||||||
|
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user