Skip to content

Commit

Permalink
Use the HTML bundle, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 27, 2023
1 parent 7902007 commit 810cc33
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 126 deletions.
143 changes: 73 additions & 70 deletions make.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {readFile} from 'fs/promises';
import {readFile, rm} from 'node:fs/promises';

import {Manager} from '@shockpkg/core';
import {
Expand All @@ -8,6 +8,7 @@ import {
ValueBoolean
} from '@shockpkg/plist-dom';
import {
BundleHtml,
BundleSaWindows,
BundleSaMac,
BundleSaLinux,
Expand All @@ -28,11 +29,10 @@ import {
import {docs} from './util/doc.mjs';
import {isMac, codesign} from './util/mac.mjs';
import {makeZip, makeTgz, makeExe, makeDmg} from './util/dist.mjs';
import {copyFile, outputFile, remove} from './util/fs.mjs';
import {templateStrings} from './util/string.mjs';
import {SourceZip, SourceDir, readSources} from './util/source.mjs';

async function * resources() {
async function * resources(browser = false) {
for await (const [file, read] of readSources([
new SourceDir('mod/1.0.2'),
new SourceZip('original/1.0.2/voyanuirpg.zip', 'voyanuirpg/')
Expand All @@ -41,9 +41,17 @@ async function * resources() {
yield [file, await read()];
}
}
const src = browser ? 'src/browser' : 'src/projector';
const files = ['voyanuionlinegame.swf'];
if (browser) {
files.push('main.js', 'main.css');
}
for (const f of files) {
yield [f, await readFile(`${src}/${f}`)];
}
}

function movie(delay) {
function projected(delay) {
const swfv = 8;
const [w, h] = [742, 556];
const fps = 20;
Expand All @@ -52,69 +60,52 @@ function movie(delay) {
return loader(swfv, w, h, fps, bg, url, delay ? Math.round(fps / 2) : 0);
}

async function bundler(b) {
for await (const [file, data] of resources()) {
await b.createResourceFile(file, data);
}
await b.copyResourceFile(
'voyanuionlinegame.swf',
'src/projector/voyanuionlinegame.swf'
);
}

async function browser(dest) {
for await (const [file, data] of resources()) {
await outputFile(`${dest}/${file}`, data);
}
await Promise.all([
'voyanuionlinegame.swf',
'main.js',
'main.css'
].map(f => copyFile(`src/browser/${f}`, `${dest}/${f}`)));
const defaultPrefix = 'voyanuionlinegame.';
await outputFile(`${dest}/index.html`, templateStrings(
await readFile('src/browser/index.html', 'utf8'),
{
LS_PREFIX: process.env.VNOG_LS_PREFIX || defaultPrefix,
API_PREFIX: process.env.VNOG_API_PREFIX || defaultPrefix,
API_URL: process.env.VNOG_API_URL || '',
API_NAME: process.env.VNOG_API_NAME || '',
API_LINK: process.env.VNOG_API_LINK || ''
}
));
}

const task = {'': _ => Object.keys(task).map(t => t && console.error(t)) && 1};

task['clean'] = async () => {
await remove('build', 'dist');
await rm('dist', {force: true, recursive: true});
await rm('build', {force: true, recursive: true});
};

task['build:pages'] = async () => {
const build = 'build/pages';
await remove(build);
await browser(build);
await docs('docs', build);
};

task['build:browser'] = async () => {
const build = 'build/browser';
await remove(build);
await browser(`${build}/data`);
await outputFile(
`${build}/${appFile}.html`,
'<meta http-equiv="refresh" content="0;url=data/index.html">\n'
);
await docs('docs', build);
};

task['dist:browser:zip'] = async () => {
await makeZip(`dist/${distName}-Browser.zip`, 'build/browser');
};
for (const [type, flat] of Object.entries({
'pages': true,
'browser': false
})) {
const build = `build/${type}`;
task[`build:${type}`] = async () => {
await rm(build, {force: true, recursive: true});
const file = flat ? 'index.html' : `${appFile}.html`;
const b = new BundleHtml(`${build}/${file}`, flat);
b.projector.lang = 'en-US';
b.projector.title = appName;
const defaultPrefix = 'voyanuionlinegame.';
b.projector.html = async () => templateStrings(
await readFile('src/browser/index.html', 'utf8'),
{
LS_PREFIX: process.env.VNOG_LS_PREFIX || defaultPrefix,
API_PREFIX: process.env.VNOG_API_PREFIX || defaultPrefix,
API_URL: process.env.VNOG_API_URL || '',
API_NAME: process.env.VNOG_API_NAME || '',
API_LINK: process.env.VNOG_API_LINK || ''
}
);
await b.write(async b => {
for await (const [file, data] of resources(true)) {
await b.createResourceFile(file, data);
}
});
await docs('docs', build);
};
}

task['dist:browser:tgz'] = async () => {
await makeTgz(`dist/${distName}-Browser.tgz`, 'build/browser');
};
for (const [type, make] of Object.entries({
'zip': makeZip,
'tgz': makeTgz
})) {
task[`dist:browser:${type}`] = async () => {
await make(`dist/${distName}-Browser.${type}`, 'build/browser');
};
}

for (const [type, pkg] of Object.entries({
'i386': 'flash-player-35.0.0.204-windows-i386-sa-2022-08-13',
Expand All @@ -123,11 +114,11 @@ for (const [type, pkg] of Object.entries({
})) {
const build = `build/windows-${type}`;
task[`build:windows-${type}`] = async () => {
await remove(build);
await rm(build, {force: true, recursive: true});
const file = `${appFile}.exe`;
const b = new BundleSaWindows(`${build}/${file}`);
b.projector.player = await new Manager().file(pkg);
b.projector.movieData = movie(false);
b.projector.movieData = projected(false);
b.projector.versionStrings = {
FileVersion: version,
ProductVersion: versionShort,
Expand All @@ -144,7 +135,11 @@ for (const [type, pkg] of Object.entries({
b.projector.patchWindowTitle = appName;
b.projector.patchOutOfDateDisable = true;
b.projector.removeCodeSignature = true;
await b.write(bundler);
await b.write(async b => {
for await (const [file, data] of resources()) {
await b.createResourceFile(file, data);
}
});
await docs('docs', build);
};
task[`dist:windows-${type}:zip`] = async () => {
Expand Down Expand Up @@ -179,11 +174,11 @@ for (const [type, pkg] of Object.entries({
})) {
const build = `build/mac-${type}`;
task[`build:mac-${type}`] = async () => {
await remove(build);
await rm(build, {force: true, recursive: true});
const pkgInfo = 'APPL????';
const b = new BundleSaMac(`${build}/${appFile}.app`);
b.projector.player = await new Manager().file(pkg);
b.projector.movieData = movie(false);
b.projector.movieData = projected(false);
b.projector.binaryName = appFile;
b.projector.pkgInfoData = pkgInfo;
b.projector.infoPlistData = (new Plist(new ValueDict(new Map([
Expand Down Expand Up @@ -215,7 +210,11 @@ for (const [type, pkg] of Object.entries({
b.projector.patchWindowTitle = appName;
b.projector.removeInfoPlistStrings = true;
b.projector.removeCodeSignature = true;
await b.write(bundler);
await b.write(async b => {
for await (const [file, data] of resources()) {
await b.createResourceFile(file, data);
}
});
if (isMac) {
await codesign(b.projector.path);
await codesign(b.path);
Expand Down Expand Up @@ -250,14 +249,18 @@ for (const [type, pkg] of Object.entries({
})) {
const build = `build/linux-${type}`;
task[`build:linux-${type}`] = async () => {
await remove(build);
await rm(build, {force: true, recursive: true});
const b = new BundleSaLinux(`${build}/${appFile}`);
b.projector.player = await new Manager().file(pkg);
b.projector.movieData = movie(true);
b.projector.movieData = projected(true);
b.projector.patchProjectorOffset = /x86_64/.test(type);
b.projector.patchProjectorPath = true;
b.projector.patchWindowTitle = appName;
await b.write(bundler);
await b.write(async b => {
for await (const [file, data] of resources()) {
await b.createResourceFile(file, data);
}
});
await docs('docs', build);
};
task[`dist:linux-${type}:tgz`] = async () => {
Expand Down
8 changes: 3 additions & 5 deletions src/browser/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Voya Nui Online Game</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<title>Voya Nui Online Game</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
Expand Down Expand Up @@ -51,8 +51,7 @@ <h2 class="saving-option-title">Account Save:</h2>
<script type="text/html" class="swfcode">
<div class="game">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"
classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000"
width="742"
height="556"
id="player"
Expand All @@ -65,7 +64,6 @@ <h2 class="saving-option-title">Account Save:</h2>
<param name="flashvars" value="%FLASHVARS%">
<embed
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
width="742"
height="556"
name="player"
Expand Down
7 changes: 2 additions & 5 deletions util/dist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import {createRequire} from 'node:module';
import {createWriteStream} from 'node:fs';
import {readdir, mkdir, rm} from 'node:fs/promises';
import {basename, dirname} from 'node:path';
import {promisify} from 'node:util';
import {pipeline} from 'node:stream';
import {pipeline} from 'node:stream/promises';
import {spawn} from 'node:child_process';

import archiver from 'archiver';
import tar from 'tar';

const pipe = promisify(pipeline);

export async function makeZip(target, source) {
await rm(target, {force: true});
await mkdir(dirname(target), {recursive: true});
Expand All @@ -22,7 +19,7 @@ export async function makeZip(target, source) {
archive.on('warning', err => {
archive.emit('error', err);
});
const done = pipe(archive, createWriteStream(target));
const done = pipeline(archive, createWriteStream(target));
archive.directory(source, false);
await Promise.all([archive.finalize(), done]);
}
Expand Down
46 changes: 0 additions & 46 deletions util/fs.mjs

This file was deleted.

0 comments on commit 810cc33

Please sign in to comment.