Files
shattered-pixel-dungeon-web…/html/build.gradle
2025-06-03 20:10:46 +03:00

155 lines
4.6 KiB
Groovy

apply plugin: 'java-library'
dependencies {
implementation "com.badlogicgames.gdx:gdx:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion"
implementation "com.github.xpenatan.gdx-teavm:backend-teavm:$gdxTeaVMVersion"
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
implementation "com.github.xpenatan.gdx-teavm:gdx-freetype-teavm:$gdxTeaVMVersion"
implementation project(':core')
implementation "org.teavm:teavm-jso:$teaVMVersion"
implementation "org.teavm:teavm-core:$teaVMVersion"
}
repositories {
google()
mavenCentral()
maven { url 'https://teavm.org/maven/repository' }
}
tasks.register('compileClient', JavaExec) {
classpath(sourceSets.main.runtimeClasspath)
mainClass.set('com.shatteredpixel.shatteredpixeldungeon.html.Compile')
jvmArgs('-Xms8g', '-Xmx14g', '-Xss16m', '-XX:MaxMetaspaceSize=12g', '-Dfile.encoding=UTF-8')
outputs.dir '../release/webapp'
doFirst {
println "Running compileClient..."
}
doLast {
println "compileClient completed!"
}
}
task modifyHtml {
doLast {
def htmlFile = file("../release/webapp/index.html")
def destinationDir = file("../release/webapp/assets")
def sourceFavicon = file("../desktop/src/main/assets/icons/windows.ico")
def sourceGif = file("../html/src/main/assets/logo.gif")
def destinationStartupLogo = file("../release/webapp/startup-logo.png")
// copy windows.ico
if (sourceFavicon.exists()) {
def destinationFile = new File(destinationDir, "windows.ico")
sourceFavicon.withInputStream { input ->
destinationFile.withOutputStream { output ->
output << input
}
}
println "Copied windows.ico to assets folder."
} else {
println "windows.ico does not exist. Skipping copy step."
}
if (sourceGif.exists()) {
destinationStartupLogo.parentFile.mkdirs()
sourceGif.withInputStream { input ->
destinationStartupLogo.withOutputStream { output ->
output << input
}
}
println "Replaced startup-logo.png with a gif."
} else {
println "Gif does not exist. Skipping replacement step."
}
if (htmlFile.exists()) {
def faviconLink = '<link rel="icon" href="assets/windows.ico" type="image/x-icon">'
def content = htmlFile.text
// add a link for the favicon
if (content.contains("</head>")) {
content = content.replace("</head>", faviconLink + "\n</head>")
println "Favicon link added to index.html."
}
// Change page title
if (content.contains("<title>")) {
content = content.replaceFirst("<title>.*?</title>", "<title>Shattered Pixel Dungeon</title>")
println "Title updated to 'Shattered Pixel Dungeon'."
} else {
println "No <title> tag found in index.html. Skipping title update."
}
if (content.contains("<style>") && content.contains("</style>")) {
content = content.replaceAll(
"(?s)<style>.*?</style>",
"""<style>
body {
display: flex;
justify-content: center;
align-items: center;
background: #000;
height: 100vh;
margin: 0;
padding: 0;
overflow: hidden;
}
#progress {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
#progress-img {
display: flex;
width: 850px;
height: auto;
margin-bottom: -20px;
}
#progress-box {
background: rgba(255,255,255,0.1);
border: 2px solid #fff;
display: flex;
margin-top: -20px;
justify-content: center;
align-items: center;
position: relative;
height: 30px;
width: 600px;
}
#progress-bar {
display: block;
background: #44FF82;
height: 20px;
width: 0%;
}
</style>"""
)
println "Successfully replaced the <style> block in index.html."
} else {
println "No <style> block found in index.html. Skipping style replacement."
}
htmlFile.text = content
} else {
println "index.html does not exist. Skipping favicon injection."
}
}
}
tasks.named('modifyHtml') {
mustRunAfter('compileClient')
}
tasks.named('build') {
dependsOn 'compileClient'
finalizedBy 'modifyHtml'
}