Public Access
This commit is contained in:
1 parent
28c2ca0db3
commit
e28079566b
21 files changed
+398
-78
No files matched your search
+37
-35
@@ -38,6 +38,35 @@ sourceSets.main.resources {
|
||||
exclude("src/generated/**/.cache") // datagen cache files
|
||||
}
|
||||
|
||||
// Generate the client-safe creative-page index from bundled symbol definitions.
|
||||
// New built-in symbols then appear in the Pages tab without another Java list.
|
||||
abstract class GenerateCreativeSymbolIndex extends DefaultTask {
|
||||
@InputDirectory abstract DirectoryProperty getSymbolsDir()
|
||||
@OutputDirectory abstract DirectoryProperty getIndexDir()
|
||||
|
||||
@TaskAction void generate() {
|
||||
File root = symbolsDir.get().asFile
|
||||
def definitions = new LinkedHashMap<String, Object>()
|
||||
java.nio.file.Files.walk(root.toPath()).withCloseable { paths ->
|
||||
paths.filter { java.nio.file.Files.isRegularFile(it) && it.toString().endsWith('.json') }
|
||||
.sorted().forEach { source ->
|
||||
String path = root.toPath().relativize(source).toString()
|
||||
.replace('\\', '/').replaceAll(/\.json$/, '')
|
||||
definitions["rivencraft:${path}"] = new groovy.json.JsonSlurper().parse(source.toFile())
|
||||
}
|
||||
}
|
||||
File index = new File(indexDir.get().asFile, 'assets/rivencraft/creative_symbol_pages.json')
|
||||
index.parentFile.mkdirs()
|
||||
index.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(definitions)) + '\n'
|
||||
}
|
||||
}
|
||||
|
||||
def generateCreativeSymbolIndex = tasks.register('generateCreativeSymbolIndex', GenerateCreativeSymbolIndex) {
|
||||
symbolsDir.set(layout.projectDirectory.dir('src/main/resources/data/rivencraft/rivencraft/symbols'))
|
||||
indexDir.set(layout.buildDirectory.dir('generated/resources/creativeSymbols'))
|
||||
}
|
||||
sourceSets.main.resources.srcDir generateCreativeSymbolIndex
|
||||
|
||||
// Archived suites use separate namespaces but share the same empty structure.
|
||||
tasks.named('processResources', ProcessResources).configure {
|
||||
archivedGameTestSuites.each { suite ->
|
||||
@@ -148,67 +177,38 @@ neoForge {
|
||||
}
|
||||
}
|
||||
|
||||
// Every default run gets a fresh world. Failed worlds stay available until a
|
||||
// successful run; caller-supplied directories are never managed here.
|
||||
// Vanilla's GameTestServer uses a fixed world seed of 0. Every default run
|
||||
// regenerates its world; custom run directories are never managed here.
|
||||
boolean customGameTestRunDir = providers.gradleProperty('gameTestRunDir').isPresent()
|
||||
File dedicatedGameTestBuildDir = layout.buildDirectory.get().asFile
|
||||
File dedicatedGameTestDir = layout.buildDirectory.dir('gametest-run').get().asFile
|
||||
File dedicatedGameTestWorld = new File(dedicatedGameTestDir, 'world')
|
||||
File gameTestSuccessMarker = new File(dedicatedGameTestDir, '.last-gametest-succeeded')
|
||||
def prepareGameTestWorld = tasks.register('prepareGameTestWorld') {
|
||||
onlyIf { !customGameTestRunDir }
|
||||
doLast {
|
||||
java.nio.file.Files.deleteIfExists(gameTestSuccessMarker.toPath())
|
||||
File preserved = GameTestWorlds.preserve(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
if (preserved != null) logger.lifecycle('Preserved GameTest world for inspection at {}', preserved)
|
||||
GameTestWorlds.clean(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
}
|
||||
}
|
||||
def finishGameTestWorld = tasks.register('finishGameTestWorld') {
|
||||
onlyIf { !customGameTestRunDir }
|
||||
doLast {
|
||||
if (gameTestSuccessMarker.exists()) {
|
||||
GameTestWorlds.clean(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
java.nio.file.Files.delete(gameTestSuccessMarker.toPath())
|
||||
} else {
|
||||
File preserved = GameTestWorlds.preserve(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
if (preserved != null) logger.lifecycle('Preserved GameTest world for inspection at {}', preserved)
|
||||
}
|
||||
GameTestWorlds.clean(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
}
|
||||
}
|
||||
tasks.named('runGameTestServer').configure {
|
||||
dependsOn(prepareGameTestWorld)
|
||||
finalizedBy(finishGameTestWorld)
|
||||
doLast {
|
||||
if (!customGameTestRunDir) {
|
||||
GameTestWorlds.check(dedicatedGameTestBuildDir, dedicatedGameTestDir)
|
||||
java.nio.file.Files.createFile(gameTestSuccessMarker.toPath())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GameTestWorlds {
|
||||
static void check(File buildDir, File runDir) {
|
||||
[buildDir, runDir, new File(runDir, 'world'), new File(runDir, 'failed-worlds')].each { path ->
|
||||
[buildDir, runDir, new File(runDir, 'world'), new File(runDir, 'failed-worlds'),
|
||||
new File(runDir, 'failed-seed.txt'), new File(runDir, '.last-gametest-succeeded')].each { path ->
|
||||
if (java.nio.file.Files.isSymbolicLink(path.toPath())) {
|
||||
throw new GradleException("Refusing to manage a symlinked GameTest path: ${path}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static File preserve(File buildDir, File runDir) {
|
||||
File world = new File(runDir, 'world')
|
||||
if (!world.exists()) return null
|
||||
check(buildDir, runDir)
|
||||
if (!world.isDirectory()) throw new GradleException("Expected a GameTest world directory: ${world}")
|
||||
File failures = new File(runDir, 'failed-worlds')
|
||||
java.nio.file.Files.createDirectories(failures.toPath())
|
||||
String snapshot = java.time.format.DateTimeFormatter.ofPattern('yyyyMMdd-HHmmss-SSS')
|
||||
.format(java.time.LocalDateTime.now()) + '-' + java.util.UUID.randomUUID()
|
||||
File destination = new File(failures, snapshot)
|
||||
java.nio.file.Files.move(world.toPath(), destination.toPath())
|
||||
return destination
|
||||
}
|
||||
|
||||
static void clean(File buildDir, File runDir) {
|
||||
check(buildDir, runDir)
|
||||
[new File(runDir, 'world'), new File(runDir, 'failed-worlds')].each { root ->
|
||||
@@ -220,6 +220,8 @@ class GameTestWorlds {
|
||||
}
|
||||
}
|
||||
}
|
||||
java.nio.file.Files.deleteIfExists(new File(runDir, 'failed-seed.txt').toPath())
|
||||
java.nio.file.Files.deleteIfExists(new File(runDir, '.last-gametest-succeeded').toPath())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user