Skip to content

Commit

Permalink
Merge pull request #420 from kremnev8/master
Browse files Browse the repository at this point in the history
Add API for mods
  • Loading branch information
hubastard authored Sep 1, 2021
2 parents a11ae8a + d0c61d7 commit d5dc8f3
Show file tree
Hide file tree
Showing 281 changed files with 1,842 additions and 840 deletions.
190 changes: 111 additions & 79 deletions .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,39 @@ import {
statSync,
} from "fs";
import { join } from "path";
import fgrpkg from "@terascope/fetch-github-release";
const downloadRelease = fgrpkg;
import json2toml from "json2toml";
import child_process from "child_process";
import { zip } from "zip-a-folder";
import fsepkg from "fs-extra";
const move = fsepkg.move;
import fsepkg, { copy } from "fs-extra";
const remove = fsepkg.remove;
import * as core from "@actions/core";

// Setting it so that it's consistent with installs from thunderstore
const NEBULA_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerMod";
const NEBULA_API_RELEASE_FOLDER_NAME = "nebula-NebulaMultiplayerModApi";
const DIST_FOLDER = "dist";
const DIST_RELEASE_FOLDER = join(DIST_FOLDER, "release");
const DIST_NEBULA_FOLDER = join(DIST_RELEASE_FOLDER, "nebula");
const DIST_TSTORE_CLI_FOLDER = join(DIST_RELEASE_FOLDER, "tstore-cli");
const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tstore-cli.exe");
const DIST_TSTORE_CLI_CONFIG_PATH = join(
DIST_TSTORE_CLI_FOLDER,
"publish.toml"
const DIST_NEBULA_FOLDER = join(
DIST_RELEASE_FOLDER,
NEBULA_RELEASE_FOLDER_NAME
);
const DIST_NEBULA_API_FOLDER = join(
DIST_RELEASE_FOLDER,
NEBULA_API_RELEASE_FOLDER_NAME
);
const DIST_TSTORE_CLI_FOLDER = join("Libs", "tcli");
const DIST_TSTORE_CLI_EXE_PATH = join(DIST_TSTORE_CLI_FOLDER, "tcli.exe");
const PLUGIN_INFO_PATH = "NebulaPatcher\\PluginInfo.cs";
const API_PLUGIN_INFO_PATH = "NebulaAPI\\NebulaModAPI.cs";
const pluginInfo = getPluginInfo();
const apiPluginInfo = getApiPluginInfo();
const TSTORE_ARCHIVE_PATH = join(
DIST_RELEASE_FOLDER,
"nebula-thunderstore.zip"
);
const TSTORE_API_ARCHIVE_PATH = join(
DIST_RELEASE_FOLDER,
"nebula-api-thunderstore.zip"
);
const GH_ARCHIVE_PATH = join(
DIST_RELEASE_FOLDER,
"Nebula_" + pluginInfo.version + ".zip"
Expand All @@ -48,29 +54,40 @@ const CHANGELOG_PATH = "CHANGELOG.md";

async function main() {
if (!existsSync(DIST_NEBULA_FOLDER)) {
throw DIST_NEBULA_FOLDER + " does not exist";
let err = DIST_NEBULA_FOLDER + " does not exist";
core.setFailed(err);
throw err;
}

if (!existsSync(DIST_TSTORE_CLI_FOLDER)) {
mkdirSync(DIST_TSTORE_CLI_FOLDER, { recursive: true });
if (!existsSync(DIST_NEBULA_API_FOLDER)) {
let err = DIST_NEBUDIST_NEBULA_API_FOLDERLA_FOLDER + " does not exist";
core.setFailed(err);
throw err;
}

try {
generateReleaseBody();
} catch (err) {
core.setFailed(err);
throw err;
}

generateManifest();
generateApiManifest();
copyIcon();
copyApiIcon();
copyReadme();
copyApiReadme();
appendChangelog();
appendApiChangelog();
copyLicenses();
copyApiLicense();

await createTStoreArchive();
await createTStoreApiArchive();
await createGHArchive();

await doTStoreRelease();
uploadToTStore();
}

function getPluginInfo() {
Expand All @@ -83,13 +100,29 @@ function getPluginInfo() {
};
}

function getApiPluginInfo() {
const pluginInfoRaw = readFileSync(API_PLUGIN_INFO_PATH).toString("utf-8");
const versionInfoRaw = readFileSync(
join("NebulaAPI", "version.json")
).toString("utf-8");
return {
name: pluginInfoRaw.match(/API_NAME = "(.*)";/)[1],
id: pluginInfoRaw.match(/API_GUID = "(.*)";/)[1],
version: JSON.parse(versionInfoRaw).version,
};
}

function generateManifest() {
const manifest = {
name: pluginInfo.name,
description:
"With this mod you will be able to play with your friends in the same game!",
version_number: pluginInfo.version,
dependencies: ["xiaoye97-BepInEx-5.4.11", "PhantomGamers-IlLine-1.0.0"],
dependencies: [
"xiaoye97-BepInEx-5.4.11",
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
"PhantomGamers-IlLine-1.0.0",
],
website_url: "https://github.com/hubastard/nebula",
};
writeFileSync(
Expand All @@ -98,26 +131,64 @@ function generateManifest() {
);
}

function generateApiManifest() {
const manifest = {
name: apiPluginInfo.name,
description: "API for other mods to work with the Nebula Multiplayer Mod",
version_number: apiPluginInfo.version,
website_url: "https://github.com/hubastard/nebula",
};
writeFileSync(
join(DIST_NEBULA_API_FOLDER, "manifest.json"),
JSON.stringify(manifest, null, 2)
);
}

function copyIcon() {
copyFileSync(MOD_ICON_PATH, join(DIST_NEBULA_FOLDER, "icon.png"));
}

function copyApiIcon() {
copyFileSync(
join("NebulaAPI", "icon.png"),
join(DIST_NEBULA_API_FOLDER, "icon.png")
);
}

function copyReadme() {
copyFileSync(README_PATH, join(DIST_NEBULA_FOLDER, README_PATH));
}

function copyApiReadme() {
copyFileSync(
join("NebulaAPI", README_PATH),
join(DIST_NEBULA_API_FOLDER, README_PATH)
);
}

function appendChangelog() {
appendFileSync(
join(DIST_NEBULA_FOLDER, README_PATH),
"\n" + readFileSync(CHANGELOG_PATH)
);
}

function appendApiChangelog() {
appendFileSync(
join(DIST_NEBULA_API_FOLDER, README_PATH),
"\n" + readFileSync(join("NebulaAPI", CHANGELOG_PATH))
);
}

function copyLicenses() {
copyFileSync("LICENSE", join(DIST_NEBULA_FOLDER, "nebula.LICENSE"));
copyFolderContent("Licenses", DIST_NEBULA_FOLDER);
}

function copyApiLicense() {
copyFileSync("LICENSE", join(DIST_NEBULA_API_FOLDER, "nebula.LICENSE"));
}

function copyFolderContent(src, dst, excludedExts) {
readdirSync(src).forEach((file) => {
const srcPath = join(src, file);
Expand All @@ -138,54 +209,6 @@ function copyFolderContent(src, dst, excludedExts) {
});
}

async function doTStoreRelease() {
const user = "Windows10CE";
const repo = "tstore-cli";
const outputdir = DIST_TSTORE_CLI_FOLDER;
const leaveZipped = false;
const disableLogging = false;

// Define a function to filter releases.
function filterRelease(release) {
// Filter out prereleases.
return release.prerelease === false;
}

// Define a function to filter assets.
function filterAsset(asset) {
// Select assets that contain the string 'windows'.
return asset.name.includes("tstore-cli.exe");
}

try {
await downloadRelease(
user,
repo,
outputdir,
filterRelease,
filterAsset,
leaveZipped,
disableLogging
);
console.log("Successfully downloaded tstore-cli.exe");
await new Promise((r) => setTimeout(r, 2000));
generateTStoreConfig();
uploadToTStore();
} catch (err) {
console.error(err.message);
}
}

function generateTStoreConfig() {
const config = {
author: "nebula",
communities: ["dyson-sphere-program"],
nsfw: false,
zip: TSTORE_ARCHIVE_PATH,
};
writeFileSync(DIST_TSTORE_CLI_CONFIG_PATH, json2toml(config));
}

function generateReleaseBody() {
const changelog = readFileSync(CHANGELOG_PATH, "utf-8");
const versionRegExp = new RegExp(
Expand Down Expand Up @@ -215,37 +238,46 @@ function generateReleaseBody() {
join(DIST_RELEASE_FOLDER, "BODY.md"),
"# Alpha Version " + currentVersion + "\n\n### Changes\n" + body
);

console.log(body);
}

async function createTStoreArchive() {
await zip(DIST_NEBULA_FOLDER, TSTORE_ARCHIVE_PATH);
}

async function createTStoreApiArchive() {
await zip(DIST_NEBULA_API_FOLDER, TSTORE_API_ARCHIVE_PATH);
}

async function createGHArchive() {
// Ensure contents are within subfolder in zip
await move(
await copy(
DIST_NEBULA_FOLDER,
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME)
);
await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH);
await move(
join(DIST_FOLDER, "tmp", NEBULA_RELEASE_FOLDER_NAME),
DIST_NEBULA_FOLDER
await copy(
DIST_NEBULA_API_FOLDER,
join(DIST_FOLDER, "tmp", NEBULA_API_RELEASE_FOLDER_NAME)
);
await zip(join(DIST_FOLDER, "tmp"), GH_ARCHIVE_PATH);
await remove(join(DIST_FOLDER, "tmp"));
}

function uploadToTStore() {
child_process.execSync(
DIST_TSTORE_CLI_EXE_PATH +
" publish --config " +
DIST_TSTORE_CLI_CONFIG_PATH,
function (err) {
console.error(err);
}
);
try {
child_process.execSync(
`"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth`
);
} catch (error) {
console.error(`Thunderstore upload failed for ${TSTORE_ARCHIVE_PATH}`);
}

try {
child_process.execSync(
`"${DIST_TSTORE_CLI_EXE_PATH}" publish --file "${TSTORE_API_ARCHIVE_PATH}" --token "${process.env.TSTORE_TOKEN}" --use-session-auth`
);
} catch (error) {
console.error(`Thunderstore upload failed for ${TSTORE_API_ARCHIVE_PATH}`);
}
}

main();
4 changes: 2 additions & 2 deletions .github/workflows/build-winx64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

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

- name: Add remote build identifier
run: New-Item -Name .remoteBuild -ItemType File -force
Expand All @@ -50,4 +50,4 @@ jobs:
with:
# Artifact name
name: build-artifacts-${{ matrix.configuration }}
path: dist\release\nebula
path: dist\release
12 changes: 9 additions & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:

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

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

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
Expand Down Expand Up @@ -91,7 +91,13 @@ jobs:
- uses: actions/[email protected]
with:
name: nebula-thunderstore
path: ${{ env.DIST_RELEASE_FOLDER }}nebula
path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerMod

# Upload the API thunderstore artifact (in case automatic upload fails)
- uses: actions/[email protected]
with:
name: nebula-api-thunderstore
path: ${{ env.DIST_RELEASE_FOLDER }}nebula-NebulaMultiplayerModApi

# Create release
- uses: hubastard/release-action@v1
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

0.5.0:

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

0.4.0:

- Nebula now supports DSP version 0.8.20.7962+
Expand All @@ -20,4 +27,4 @@

0.2.0:

- initial release on thunderstore
- initial release on thunderstore
Loading

0 comments on commit d5dc8f3

Please sign in to comment.