Skip to content

Commit 8f668da

Browse files
committed
Release ZomboidMod v2.3.0
2 parents dbd0603 + 9e7d3f2 commit 8f668da

File tree

8 files changed

+198
-17
lines changed

8 files changed

+198
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# User data
22
local.properties
3+
zdoc.version
34

45
# Temporary
56
.gitignored
7+
serialize.lua
68

79
# Libraries
810
/lib/

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ZomboidMod serves as an umbrella for these tools, connecting everything you need
2222
- Decompiles and packages game classes to expose game engine code.
2323
- Uses [ZomboidDoc](https://github.com/yooksi/pz-zdoc/) to compile a readable and always up-to-date modding Lua library.
2424
- Compact workspace that can be used straight out of the box.
25+
- Fully automated project changelog generation.
26+
- Create mod distributions with a click of a button.
2527
- Easy installation steps for enabling advanced features.
2628
- Comes pre-configured for use with Git.
2729
- Fully integrates with IntelliJ IDEA.
@@ -128,6 +130,45 @@ You can rerun the task at any time if you accidentally delete the configuration
128130

129131
## How to use
130132

133+
### Search scopes
134+
135+
IDEA [scopes](https://www.jetbrains.com/help/idea/settings-scopes.html) are sets of files you can search in various contexts. ZomboidMod generates custom search scopes to help you find code usages or references helpful in modding the game:
136+
137+
- `mod-lua` - All Lua files in `media` directory.
138+
- `mod-media` - All files in `media` directory.
139+
- `pz-java` - Project Zomboid Java classes.
140+
- `pz-lua` - Project Zomboid Lua classes.
141+
142+
Learn more about [searching everywhere](https://www.jetbrains.com/help/idea/searching-everywhere.html) in IntelliJ IDEA.
143+
144+
### Changelog
145+
146+
> If you are not familiar with what a changelog is I recommend reading [keep a changelog](https://keepachangelog.com/en/1.0.0/).
147+
148+
ZomboidMod uses [github-changelog-generator](https://github.com/github-changelog-generator/github-changelog-generator) to generate standardized changelogs. Your should generate a changelog after each release, when all issues on project Github repository have been closed with a merge commit.
149+
150+
Before generating a changelog you need to do the following:
151+
152+
- Make sure you have designated repository `url` in `mod.info` file.
153+
154+
- Generate a [Github token](https://github.com/github-changelog-generator/github-changelog-generator#github-token) and store it in `local.properties`:
155+
156+
```properties
157+
cg.token=<your-40-digit-token>
158+
```
159+
160+
That simply run `generateChangelog` task to generate project changelog.
161+
162+
### Distribution
163+
164+
Before others can download your mod you need to assemble and upload the mod distribution.
165+
166+
Assembling distributions is a process of packaging everything your mod needs to run in production environment in compressed archives. Anything not needed in production environment (such as gradle files) needs to be excluded from distributions.
167+
168+
ZomboidMod handles this for you. Just run `assembleModDist` and a distribution archive matching the current project version will be created in `build/distributions` directory.
169+
170+
## List of tasks
171+
131172
### Setup tasks
132173

133174
- `createLaunchRunConfigs` - Create game launch run configurations.
@@ -156,6 +197,7 @@ You can rerun the task at any time if you accidentally delete the configuration
156197

157198
- `annotateZomboidLua` - Annotate vanilla Lua with EmmyLua.
158199
- `compileZomboidLua` - Compile Lua library from modding API.
200+
- `updateZomboidLua` - Run ZomboidDoc to update compiled Lua library.
159201
- `decompileZomboid` - Decompile Project Zomboid classes.
160202
- `zomboidClasses` - Assembles Project Zomboid classes.
161203
- `zomboidJar` - Assembles a jar archive containing game classes.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id 'distribution'
77
}
88
repositories {
9-
jcenter()
9+
mavenCentral()
1010
}
1111

1212
java {

dist/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# User data
22
local.properties
3+
zdoc.version
4+
5+
# Temporary
6+
serialize.lua
37

48
# Libraries
59
/lib/

dist/distribution.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import java.nio.file.Files
22
import java.nio.file.Paths
33

4-
// set repository owner and name
5-
project.ext.set('repo.owner', 'cocolabs')
6-
project.ext.set('repo.name', 'pz-zmod')
7-
84
// changelog.gradle
95
apply from: 'https://git.io/JqJiC'
106

mod.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ void validateModInfo() {
3636
else if (key == 'url')
3737
{
3838
try {
39-
new URL(property)
39+
if (new URL(property).host != 'github.com') {
40+
throw new InvalidUserDataException("Mod URL \'${property}\' is not a valid Github repo URL")
41+
}
4042
}
4143
catch (MalformedURLException e) {
4244
throw new InvalidUserDataException("Mod URL \'${property}\' is not a valid URL", e)
@@ -109,7 +111,7 @@ tasks.register('initModInfo') {
109111
ant.input(message: 'Enter mod description: \n', addproperty: 'mod.description')
110112
modInfoProperties.setProperty('description', ant.properties.get('mod.description') as String)
111113

112-
ant.input(message: 'Enter mod repo/workshop URL: \n', addproperty: 'mod.url')
114+
ant.input(message: 'Enter github repository URL: \n', addproperty: 'mod.url')
113115
modInfoProperties.setProperty('url', ant.properties.get('mod.url') as String)
114116

115117
// starting mod version is 0.1.0 (sem-ver)
@@ -134,6 +136,18 @@ task loadModInfo {
134136
logger.info("Loading property ${it.key}:${it.value}")
135137
project.ext.set("mod.${(it.key as String)}", it.value as String)
136138
})
139+
def sUrl = modInfoProperties.getProperty('url')
140+
if (sUrl && !sUrl.isBlank())
141+
{
142+
def url = new URL(sUrl)
143+
def urlPath = url.path.startsWith('/') ? url.path.substring(1) : url.path
144+
def pathElements = urlPath.split('/')
145+
if (pathElements.length != 2) {
146+
throw new InvalidUserDataException("Unexpected mod url format '${urlPath}'")
147+
}
148+
project.ext.set('repo.owner', pathElements[0])
149+
project.ext.set('repo.name', pathElements[1])
150+
}
137151
}
138152
else logger.warn('WARN: Unable to find mod.info file')
139153
}

mod.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ poster=poster.png
33
description=Compact mod development environment.
44
id=pz-zmod
55
url=https://github.com/cocolabs/pz-zmod
6-
modversion=2.2.0
6+
modversion=2.3.0
77
pzversion=41.50-IWBUMS

zdoc.gradle

Lines changed: 132 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ repositories {
77
// try to find dependencies locally first
88
mavenLocal()
99
}
10-
// Github Packages repository credentials
11-
project.ext.cocoLabsRepo = 'pz-zdoc'
12-
apply from: 'https://git.io/JtydE'
1310

1411
configurations {
1512
zomboidDoc.extendsFrom zomboidRuntimeOnly
1613
}
1714
dependencies {
18-
// https://github.com/orgs/cocolabs/packages?repo_name=pz-zdoc
19-
zomboidDoc 'io.cocolabs:pz-zdoc:3.+'
15+
// https://search.maven.org/artifact/io.github.cocolabs/pz-zdoc
16+
zomboidDoc 'io.github.cocolabs:pz-zdoc:3.+'
2017

2118
// ZomboidDoc compiled Lua library
2219
if (project.ext.has('mod.pzversion')) {
@@ -65,21 +62,118 @@ tasks.register('zomboidVersion', JavaExec.class) {
6562
it.finalizedBy(tasks.getByName('saveModInfo'))
6663
}
6764

68-
tasks.register('annotateZomboidLua', JavaExec.class) {
65+
/**
66+
* <p>Returns {@code File} instance of {@code zdoc.version} file.</p>
67+
* If the file does not exist it will be created.
68+
*/
69+
File getZDocVersionFile() {
70+
71+
def file = file('zdoc.version')
72+
if (!file.exists() && !file.createNewFile()) {
73+
throw new IOException("Unable to create zdoc.version file")
74+
}
75+
return file
76+
}
77+
78+
/**
79+
* Compare the given versions and return a comparator resulting value.
80+
*
81+
* @param versionA semantic version to compare against.
82+
* @param versionB semantic version to compare with.
83+
* @return {@code -1} if {@code versionA} is lower then {@code versionB}, {@code 0} if
84+
* versions are equal and {@code 1} if {@code versionA} is higher then {@code versionB}
85+
*/
86+
static int compareSemanticVersions(Integer[] versionA, Integer[] versionB) {
87+
88+
if (versionA.length != 3 || versionB.length != 3) {
89+
throw new GradleException("Not valid semantic versions [${versionA}, ${versionB}]")
90+
}
91+
for (int i = 0; i < 3; i++)
92+
{
93+
// first version is higher then second
94+
if (versionA[i] > versionB[i]) {
95+
return 1
96+
}
97+
// second version is higher then first
98+
else if (versionA[i] < versionB[i]) {
99+
return -1
100+
}
101+
}
102+
// semantic versions are equal
103+
return 0
104+
}
105+
106+
/**
107+
* Returns a series of integers representing {@code ZomboidDoc} dependency version.
108+
*/
109+
@SuppressWarnings('UnnecessaryQualifiedReference')
110+
Integer[] getZDocDependencyVersion() {
111+
112+
def pattern = java.util.regex.Pattern.compile('[\\w\\-]+(\\d+)\\.(\\d+)\\.(\\d+)')
113+
def dependency = configurations.zomboidDoc.files.stream()
114+
.filter({it.name.startsWith('pz-zdoc')}).findFirst()
115+
if (!dependency.present) {
116+
throw new RuntimeException('Unable to find ZomboidDoc dependency in configuration')
117+
}
118+
def filename = dependency.get().name
119+
java.util.regex.Matcher matcher = pattern.matcher(filename)
120+
if (matcher.find())
121+
{
122+
def result = new Integer[3]
123+
for (int i = 0; i < 3; i++) {
124+
result[i] = Integer.valueOf(matcher.group(i + 1))
125+
}
126+
return result
127+
}
128+
else throw new RuntimeException("Malformed zdoc dependency name ${filename}")
129+
}
130+
131+
/**
132+
* Returns a series of integers representing last {@code ZomboidDoc} dependency version.
133+
*
134+
* @param versionFile {@code file} to read the version information from.
135+
* @param currentVersion series of integers representing current {@code ZomboidDoc} version.
136+
* @return last {@code ZomboidDoc} dependency version or {@code null} if no version found.
137+
*/
138+
Integer[] getZDocLastVersion(versionFile, currentVersion) {
139+
140+
def content = versionFile.readLines()
141+
if (!content.empty)
142+
{
143+
String[] elements = content.get(0).split('\\.')
144+
if (elements.length == 3)
145+
{
146+
Integer[] result = new Integer[elements.length]
147+
for (int i = 0; i < elements.length; i++) {
148+
result[i] = Integer.valueOf(elements[i])
149+
}
150+
return result
151+
}
152+
else logger.warn("WARN: Malformed semantic version found '${elements}'")
153+
}
154+
versionFile.text = currentVersion.join('.')
155+
return null
156+
}
157+
158+
def annotateZomboidLua = tasks.register('annotateZomboidLua', JavaExec.class) {
69159

70160
it.description 'Annotate vanilla Lua with EmmyLua.'
71-
it.setGroup 'zomboid'
161+
it.group 'zomboid'
72162

73163
it.main = 'io.cocolabs.pz.zdoc.Main'
74164
it.classpath = configurations.zomboidDoc
75165
it.args('annotate', '-i', "${project.ext.gameDir}/media/lua", '-o', "$zDocLuaDir/media/lua")
76166
it.dependsOn(tasks.getByName('zomboidClasses'))
167+
it.doLast {
168+
def versionFile = getZDocVersionFile()
169+
versionFile.text = getZDocDependencyVersion().join('.')
170+
}
77171
}
78172

79-
tasks.register('compileZomboidLua', JavaExec.class) {
173+
def compileZomboidLua = tasks.register('compileZomboidLua', JavaExec.class) {
80174

81175
it.description 'Compile Lua library from modding API.'
82-
it.setGroup 'zomboid'
176+
it.group 'zomboid'
83177

84178
//noinspection GroovyAssignabilityCheck,GroovyAccessibility
85179
it.javaLauncher = javaToolchains.launcherFor {
@@ -89,4 +183,33 @@ tasks.register('compileZomboidLua', JavaExec.class) {
89183
it.classpath = configurations.zomboidDoc
90184
it.args('compile', '-i', "$gameDir", '-o', "$zDocLuaDir/media/lua/shared/Library")
91185
it.dependsOn(tasks.getByName('zomboidClasses'))
186+
it.shouldRunAfter(annotateZomboidLua)
187+
it.doLast {
188+
def versionFile = getZDocVersionFile()
189+
versionFile.text = getZDocDependencyVersion().join('.')
190+
}
92191
}
192+
193+
def updateZomboidLua = tasks.register('updateZomboidLua') {
194+
195+
it.description 'Run ZomboidDoc to update compiled Lua library.'
196+
it.group 'zomboid'
197+
198+
def versionFile = getZDocVersionFile()
199+
def currentVersion = getZDocDependencyVersion()
200+
def lastVersion = getZDocLastVersion(versionFile, currentVersion)
201+
def compareResult = lastVersion != null ? compareSemanticVersions(lastVersion, currentVersion) : -1
202+
it.onlyIf {
203+
compareResult == -1
204+
}
205+
// current version is higher then last version
206+
if (compareResult == -1) {
207+
it.dependsOn(annotateZomboidLua, compileZomboidLua)
208+
}
209+
it.doLast {
210+
// update zdoc.version data
211+
versionFile.text = currentVersion.join('.')
212+
}
213+
}
214+
classes.dependsOn(updateZomboidLua)
215+

0 commit comments

Comments
 (0)