Skip to content

Commit d5dc8f3

Browse files
authored
Merge pull request #420 from kremnev8/master
Add API for mods
2 parents a11ae8a + d0c61d7 commit d5dc8f3

File tree

281 files changed

+1842
-840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+1842
-840
lines changed

.github/scripts/thunderstore_bundle.js

Lines changed: 111 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@ import {
1111
statSync,
1212
} from "fs";
1313
import { join } from "path";
14-
import fgrpkg from "@terascope/fetch-github-release";
15-
const downloadRelease = fgrpkg;
16-
import json2toml from "json2toml";
1714
import child_process from "child_process";
1815
import { zip } from "zip-a-folder";
19-
import fsepkg from "fs-extra";
20-
const move = fsepkg.move;
16+
import fsepkg, { copy } from "fs-extra";
2117
const remove = fsepkg.remove;
2218
import * as core from "@actions/core";
2319

2420
// Setting it so that it's consistent with installs from thunderstore
2521
const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod";
22+
const NEBULA_API_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerModApi";
2623
const DIST_FOLDER = "dist";
2724
const DIST_RELEASE_FOLDER = join(DIST_FOLDER, "release");
28-
const DIST_NEBULA_FOLDER = join(DIST_RELEASE_FOLDER, "nebula");
29-
const DIST_TSTORE_CLI_FOLDER = join(DIST_RELEASE_FOLDER, "tstore-cli");
30-
const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tstore-cli.exe");
31-
const DIST_TSTORE_CLI_CONFIG_PATH = join(
32-
DIST_TSTORE_CLI_FOLDER,
33-
"publish.toml"
25+
const DIST_NEBULA_FOLDER = join(
26+
DIST_RELEASE_FOLDER,
27+
NEBULA_RELEASE_FOLDER_NAME
28+
);
29+
const DIST_NEBULA_API_FOLDER = join(
30+
DIST_RELEASE_FOLDER,
31+
NEBULA_API_RELEASE_FOLDER_NAME
3432
);
33+
const DIST_TSTORE_CLI_FOLDER = join("Libs", "tcli");
34+
const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tcli.exe");
3535
const PLUGIN_INFO_PATH = "NebulaPatcher\\PluginInfo.cs";
36+
const API_PLUGIN_INFO_PATH = "NebulaAPI\\NebulaModAPI.cs";
3637
const pluginInfo = getPluginInfo();
38+
const apiPluginInfo = getApiPluginInfo();
3739
const TSTORE_ARCHIVE_PATH = join(
3840
DIST_RELEASE_FOLDER,
3941
"nebula-thunderstore.zip"
4042
);
43+
const TSTORE_API_ARCHIVE_PATH = join(
44+
DIST_RELEASE_FOLDER,
45+
"nebula-api-thunderstore.zip"
46+
);
4147
const GH_ARCHIVE_PATH = join(
4248
DIST_RELEASE_FOLDER,
4349
"Nebula_" + pluginInfo.version + ".zip"
@@ -48,29 +54,40 @@ const CHANGELOG_PATH = "CHANGELOG.md";
4854

4955
async function main() {
5056
if (!existsSync(DIST_NEBULA_FOLDER)) {
51-
throw DIST_NEBULA_FOLDER + " does not exist";
57+
let err = DIST_NEBULA_FOLDER + " does not exist";
58+
core.setFailed(err);
59+
throw err;
5260
}
5361

54-
if (!existsSync(DIST_TSTORE_CLI_FOLDER)) {
55-
mkdirSync(DIST_TSTORE_CLI_FOLDER, { recursive: true });
62+
if (!existsSync(DIST_NEBULA_API_FOLDER)) {
63+
let err = DIST_NEBUDIST_NEBULA_API_FOLDERLA_FOLDER + " does not exist";
64+
core.setFailed(err);
65+
throw err;
5666
}
5767

5868
try {
5969
generateReleaseBody();
6070
} catch (err) {
6171
core.setFailed(err);
72+
throw err;
6273
}
6374

6475
generateManifest();
76+
generateApiManifest();
6577
copyIcon();
78+
copyApiIcon();
6679
copyReadme();
80+
copyApiReadme();
6781
appendChangelog();
82+
appendApiChangelog();
6883
copyLicenses();
84+
copyApiLicense();
6985

7086
await createTStoreArchive();
87+
await createTStoreApiArchive();
7188
await createGHArchive();
7289

73-
await doTStoreRelease();
90+
uploadToTStore();
7491
}
7592

7693
function getPluginInfo() {
@@ -83,13 +100,29 @@ function getPluginInfo() {
83100
};
84101
}
85102

103+
function getApiPluginInfo() {
104+
const pluginInfoRaw = readFileSync(API_PLUGIN_INFO_PATH).toString("utf-8");
105+
const versionInfoRaw = readFileSync(
106+
join("NebulaAPI", "version.json")
107+
).toString("utf-8");
108+
return {
109+
name: pluginInfoRaw.match(/API_NAME = "(.*)";/)[1],
110+
id: pluginInfoRaw.match(/API_GUID = "(.*)";/)[1],
111+
version: JSON.parse(versionInfoRaw).version,
112+
};
113+
}
114+
86115
function generateManifest() {
87116
const manifest = {
88117
name: pluginInfo.name,
89118
description:
90119
"With this mod you will be able to play with your friends in the same game!",
91120
version_number: pluginInfo.version,
92-
dependencies: ["xiaoye97-BepInEx-5.4.11", "PhantomGamers-IlLine-1.0.0"],
121+
dependencies: [
122+
"xiaoye97-BepInEx-5.4.11",
123+
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
124+
"PhantomGamers-IlLine-1.0.0",
125+
],
93126
website_url: "https://github.com/hubastard/nebula",
94127
};
95128
writeFileSync(
@@ -98,26 +131,64 @@ function generateManifest() {
98131
);
99132
}
100133

134+
function generateApiManifest() {
135+
const manifest = {
136+
name: apiPluginInfo.name,
137+
description: "API for other mods to work with the Nebula Multiplayer Mod",
138+
version_number: apiPluginInfo.version,
139+
website_url: "https://github.com/hubastard/nebula",
140+
};
141+
writeFileSync(
142+
join(DIST_NEBULA_API_FOLDER, "manifest.json"),
143+
JSON.stringify(manifest, null, 2)
144+
);
145+
}
146+
101147
function copyIcon() {
102148
copyFileSync(MOD_ICON_PATH, join(DIST_NEBULA_FOLDER, "icon.png"));
103149
}
104150

151+
function copyApiIcon() {
152+
copyFileSync(
153+
join("NebulaAPI", "icon.png"),
154+
join(DIST_NEBULA_API_FOLDER, "icon.png")
155+
);
156+
}
157+
105158
function copyReadme() {
106159
copyFileSync(README_PATH, join(DIST_NEBULA_FOLDER, README_PATH));
107160
}
108161

162+
function copyApiReadme() {
163+
copyFileSync(
164+
join("NebulaAPI", README_PATH),
165+
join(DIST_NEBULA_API_FOLDER, README_PATH)
166+
);
167+
}
168+
109169
function appendChangelog() {
110170
appendFileSync(
111171
join(DIST_NEBULA_FOLDER, README_PATH),
112172
"\n" + readFileSync(CHANGELOG_PATH)
113173
);
114174
}
115175

176+
function appendApiChangelog() {
177+
appendFileSync(
178+
join(DIST_NEBULA_API_FOLDER, README_PATH),
179+
"\n" + readFileSync(join("NebulaAPI", CHANGELOG_PATH))
180+
);
181+
}
182+
116183
function copyLicenses() {
117184
copyFileSync("LICENSE", join(DIST_NEBULA_FOLDER, "nebula.LICENSE"));
118185
copyFolderContent("Licenses", DIST_NEBULA_FOLDER);
119186
}
120187

188+
function copyApiLicense() {
189+
copyFileSync("LICENSE", join(DIST_NEBULA_API_FOLDER, "nebula.LICENSE"));
190+
}
191+
121192
function copyFolderContent(src, dst, excludedExts) {
122193
readdirSync(src).forEach((file) => {
123194
const srcPath = join(src, file);
@@ -138,54 +209,6 @@ function copyFolderContent(src, dst, excludedExts) {
138209
});
139210
}
140211

141-
async function doTStoreRelease() {
142-
const user = "Windows10CE";
143-
const repo = "tstore-cli";
144-
const outputdir = DIST_TSTORE_CLI_FOLDER;
145-
const leaveZipped = false;
146-
const disableLogging = false;
147-
148-
// Define a function to filter releases.
149-
function filterRelease(release) {
150-
// Filter out prereleases.
151-
return release.prerelease === false;
152-
}
153-
154-
// Define a function to filter assets.
155-
function filterAsset(asset) {
156-
// Select assets that contain the string 'windows'.
157-
return asset.name.includes("tstore-cli.exe");
158-
}
159-
160-
try {
161-
await downloadRelease(
162-
user,
163-
repo,
164-
outputdir,
165-
filterRelease,
166-
filterAsset,
167-
leaveZipped,
168-
disableLogging
169-
);
170-
console.log("Successfully downloaded tstore-cli.exe");
171-
await new Promise((r) => setTimeout(r, 2000));
172-
generateTStoreConfig();
173-
uploadToTStore();
174-
} catch (err) {
175-
console.error(err.message);
176-
}
177-
}
178-
179-
function generateTStoreConfig() {
180-
const config = {
181-
author: "nebula",
182-
communities: ["dyson-sphere-program"],
183-
nsfw: false,
184-
zip: TSTORE_ARCHIVE_PATH,
185-
};
186-
writeFileSync(DIST_TSTORE_CLI_CONFIG_PATH, json2toml(config));
187-
}
188-
189212
function generateReleaseBody() {
190213
const changelog = readFileSync(CHANGELOG_PATH, "utf-8");
191214
const versionRegExp = new RegExp(
@@ -215,37 +238,46 @@ function generateReleaseBody() {
215238
join(DIST_RELEASE_FOLDER, "BODY.md"),
216239
"# Alpha Version " + currentVersion + "\n\n### Changes\n" + body
217240
);
218-
219-
console.log(body);
220241
}
221242

222243
async function createTStoreArchive() {
223244
await zip(DIST_NEBULA_FOLDER, TSTORE_ARCHIVE_PATH);
224245
}
225246

247+
async function createTStoreApiArchive() {
248+
await zip(DIST_NEBULA_API_FOLDER, TSTORE_API_ARCHIVE_PATH);
249+
}
250+
226251
async function createGHArchive() {
227252
// Ensure contents are within subfolder in zip
228-
await move(
253+
await copy(
229254
DIST_NEBULA_FOLDER,
230255
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME)
231256
);
232-
await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH);
233-
await move(
234-
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME),
235-
DIST_NEBULA_FOLDER
257+
await copy(
258+
DIST_NEBULA_API_FOLDER,
259+
join(DIST_FOLDER, "tmp", NEBULA_API_RELEASE_FOLDER_NAME)
236260
);
261+
await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH);
237262
await remove(join(DIST_FOLDER, "tmp"));
238263
}
239264

240265
function uploadToTStore() {
241-
child_process.execSync(
242-
DIST_TSTORE_CLI_EXE_PATH +
243-
" publish --config " +
244-
DIST_TSTORE_CLI_CONFIG_PATH,
245-
function (err) {
246-
console.error(err);
247-
}
248-
);
266+
try {
267+
child_process.execSync(
268+
`"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth`
269+
);
270+
} catch (error) {
271+
console.error(`Thunderstore upload failed for ${TSTORE_ARCHIVE_PATH}`);
272+
}
273+
274+
try {
275+
child_process.execSync(
276+
`"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_API_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth`
277+
);
278+
} catch (error) {
279+
console.error(`Thunderstore upload failed for ${TSTORE_API_ARCHIVE_PATH}`);
280+
}
249281
}
250282

251283
main();

.github/workflows/build-winx64.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
- name: Clear output directory in DSP files
3131
# We use SilentlyContinue here because it errors out if the folder does not exist otherwise
32-
run: rm -R -ErrorAction SilentlyContinue "dist\release\nebula"
32+
run: rm -R -ErrorAction SilentlyContinue "dist"
3333

3434
- name: Add remote build identifier
3535
run: New-Item -Name .remoteBuild -ItemType File -force
@@ -50,4 +50,4 @@ jobs:
5050
with:
5151
# Artifact name
5252
name: build-artifacts-${{ matrix.configuration }}
53-
path: dist\release\nebula
53+
path: dist\release

.github/workflows/publish-release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ jobs:
4646

4747
- name: Clear output directory in DSP files
4848
# We use SilentlyContinue here because it errors out if the folder does not exist otherwise
49-
run : rm -R -ErrorAction SilentlyContinue "${{ env.NEBULA_FOLDER }}"
49+
run : rm -R -ErrorAction SilentlyContinue "dist"
5050

5151
- name: Add remote build identifier
52-
run: copy /b /Y NUL .remoteBuild
52+
run: New-Item -Name .remoteBuild -ItemType File -force
5353

5454
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
5555
- name: Setup MSBuild.exe
@@ -91,7 +91,13 @@ jobs:
9191
- uses: actions/upload-artifact@v2.2.4
9292
with:
9393
name: nebula-thunderstore
94-
path: ${{ env.DIST_RELEASE_FOLDER }}nebula
94+
path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerMod
95+
96+
# Upload the API thunderstore artifact (in case automatic upload fails)
97+
- uses: actions/upload-artifact@v2.2.4
98+
with:
99+
name: nebula-api-thunderstore
100+
path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerModApi
95101

96102
# Create release
97103
- uses: hubastard/release-action@v1

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Changelog
22

3+
0.5.0:
4+
5+
- Added API that enables other mods to sync over multiplayer! (Big thanks to @kremnev8!)
6+
- Fixed a bug that caused sorters to break when a client built a belt under preexisting sorters.
7+
- Fixed a bug that resulted in the client getting an error after disconnecting from a game that the host left.
8+
- Refactored session architecture (big changes to codebase but should be seamless to users)
9+
310
0.4.0:
411

512
- Nebula now supports DSP version 0.8.20.7962+
@@ -20,4 +27,4 @@
2027

2128
0.2.0:
2229

23-
- initial release on thunderstore
30+
- initial release on thunderstore

0 commit comments

Comments
 (0)