-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
234 lines (195 loc) · 7.14 KB
/
build.gradle
File metadata and controls
234 lines (195 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import java.text.SimpleDateFormat
plugins {
id 'java'
//id 'application'
id 'java-library'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}
group = "${group}"
version = "${version}"
//mainClassName = "${mainClass}"
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
// LWJGL
implementation platform("org.lwjgl:lwjgl-bom:${lwjglVersion}")
// JOML - 3D math
implementation "org.joml:joml:${jomlVersion}"
// org.json https://mvnrepository.com/artifact/org.json/json
implementation group: 'org.json', name: 'json', version: '20240303'
// LWJGL
implementation "org.lwjgl:lwjgl"
implementation "org.lwjgl:lwjgl-glfw" // Windows management
implementation "org.lwjgl:lwjgl-opengl" // OpenGL 3D
implementation "org.lwjgl:lwjgl-stb" // Images/assets loader
implementation "org.lwjgl:lwjgl-openal" // OpenAL for audio
implementation "io.github.spair:imgui-java-binding:${imguiJavaVersion}" // ImGui for GUI
implementation "io.github.spair:imgui-java-lwjgl3:${imguiJavaVersion}" // ImGui for GUI
// LWJGL Windows
runtimeOnly "org.lwjgl:lwjgl::${lwjglNatives}"
runtimeOnly "org.lwjgl:lwjgl-glfw::${lwjglNatives}"
runtimeOnly "org.lwjgl:lwjgl-opengl::${lwjglNatives}"
runtimeOnly "org.lwjgl:lwjgl-stb::${lwjglNatives}"
runtimeOnly "org.lwjgl:lwjgl-openal::${lwjglNatives}"
runtimeOnly "io.github.spair:imgui-java-${imguiNatives}:${imguiJavaVersion}"
// Netty
implementation 'io.netty:netty-all:4.1.113.Final'
// Discord
implementation 'com.github.JnCrMx:discord-game-sdk4j:5cdac341e3'
// Processors
annotationProcessor project(':processors')
implementation project(path: ':processors')
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
//withSourcesJar()
//withJavadocJar()
}
jar {
manifest {
attributes(
'Main-Class': "${mainClass}",
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
from('resources') {
into 'resources'
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Excluding the test game
//exclude 'com/restonic4/test/**'
archiveBaseName.set("CitadelEngine${project.hasProperty('serverBuild') ? '-Server' : ''}")
}
tasks.register('buildServerJar', Exec) {
commandLine 'cmd', '/c', 'gradlew.bat clean build -PserverBuild'
}
tasks.register('buildJar', Exec) {
commandLine 'cmd', '/c', 'gradlew.bat clean build'
}
tasks.register('packageApp', Exec) {
def jarName = jar.archiveFileName.get()
def appVersion = project.version
def outputDir = "$buildDir/app"
def iconPath = "$projectDir/resources/assets/textures/icons/icon.ico"
doFirst {
file(outputDir).mkdirs()
}
def args = [
'jpackage',
'--input', 'build/libs/',
'--main-jar', jarName,
'--main-class', "${mainClass}",
'--name', "${appName}",
'--type', 'exe',
'--win-dir-chooser',
'--win-shortcut',
'--win-menu',
'--app-version', appVersion,
'--icon', iconPath,
'--dest', outputDir
]
if (consoleEnabled == "true") {
args += ['--win-console']
}
commandLine 'cmd', '/c', args.join(' ')
}
tasks.register('buildAndPackage') {
dependsOn 'buildJar'
dependsOn 'packageApp'
}
tasks.register('buildBothJars', Exec) {
commandLine 'cmd', '/c', 'gradlew.bat clean build'
commandLine 'cmd', '/c', 'gradlew.bat build -PserverBuild'
}
// Define a map to hold configurations for each mode
def modeConfig = [
'last24Hours': [dateShift: [Calendar.DATE, -1], secondsPerDay: 20],
'lastWeek': [dateShift: [Calendar.WEEK_OF_YEAR, -1], secondsPerDay: 8],
'lastMonth': [dateShift: [Calendar.MONTH, -1], secondsPerDay: 4],
'lastYear': [dateShift: [Calendar.YEAR, -1], secondsPerDay: 1],
'all': [dateShift: null, secondsPerDay: 1],
'allSlow': [dateShift: null, secondsPerDay: 4]
]
// Utility function to get formatted date string
static def getFormattedDateString(Date date) {
def dateFormat = new SimpleDateFormat("\"yyyy-MM-dd HH:mm:ss Z\"")
dateFormat.setTimeZone(TimeZone.getDefault())
return dateFormat.format(date)
}
// Function to get date based on mode
static def getStartDate(mode, modeConfig) {
def config = modeConfig[mode]
if (config == null) {
throw new GradleException("Invalid time mode: $mode")
}
if (config.dateShift == null) {
return null
}
Calendar calendar = Calendar.getInstance()
calendar.add(config.dateShift[0], config.dateShift[1])
return getFormattedDateString(calendar.getTime())
}
// Function to get seconds per day based on mode
static def getSecondsPerDay(mode, modeConfig) {
def config = modeConfig[mode]
if (config == null) {
throw new GradleException("Invalid time mode: $mode")
}
return config.secondsPerDay
}
tasks.register('gource', Exec) {
// Set the desired mode
def mode = "${gourceMode}"
def startDate = getStartDate(mode, modeConfig)
def secondsPerDay = getSecondsPerDay(mode, modeConfig)
// Build the list of arguments
def args = [
'gource',
'-f', '-1920x1080',
'--seconds-per-day', "${secondsPerDay}",
'--title', "${appName}",
'--hide', 'mouse,progress',
'--highlight-colour', 'FFD700',
'--highlight-user', 'restonic4',
'--highlight-user', 'Dinax',
'--caption-file', 'gource/captions.txt',
'--font-scale', '2'
]
// Add the start date argument if it's not null
if (startDate != null) {
args += ['--start-date', startDate]
}
// Configure the command line
commandLine 'cmd', '/c', args.join(' ')
}
// Auto update common constants between gradle and java
task updateGradleUtil {
def filePath = "src/main/java/com/restonic4/citadel/util/GradleUtil.java"
def versionRegex = /public static final String VERSION = ".*";/
def nameRegex = /public static final String APP_NAME = ".*";/
def consoleRegex = /public static final Boolean CONSOLE_ENABLED = .*/
def serverBuildRegex = /public static final Boolean SERVER_BUILD = .*/
doLast {
def file = file(filePath)
if (!file.exists()) {
throw new GradleException("File not found: $filePath")
}
if (project.hasProperty('serverBuild')) {
consoleEnabled = true
}
def content = file.text
content = content.replaceAll(versionRegex, "public static final String VERSION = \"${project.version}\";")
content = content.replaceAll(nameRegex, "public static final String APP_NAME = \"${appName}\";")
content = content.replaceAll(consoleRegex, "public static final Boolean CONSOLE_ENABLED = ${consoleEnabled};")
content = content.replaceAll(serverBuildRegex, "public static final Boolean SERVER_BUILD = ${project.hasProperty('serverBuild')};")
file.text = content
println "Updated GradleUtil.java"
}
}
compileJava.dependsOn(updateGradleUtil)