Skip to content

Commit

Permalink
un-es6
Browse files Browse the repository at this point in the history
  • Loading branch information
zeddidragon committed Feb 25, 2023
1 parent 4add3cb commit 289a577
Show file tree
Hide file tree
Showing 29 changed files with 86 additions and 92 deletions.
7 changes: 1 addition & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaVersion": 6,
},
"rules": {
"indent": ["error", 2],
Expand Down
2 changes: 1 addition & 1 deletion converters/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,4 @@ function compile(obj) {
compile.compile = compile
compile.compiler = opts => obj => compile(obj, opts)

export default compile
module.exports = compile
4 changes: 2 additions & 2 deletions converters/decompiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decompileBuffer } from './infer.js'
const { decompileBuffer } = require('./infer.js')

function padCeil(value, divisor = 0x10) {
return Math.ceil(value / divisor) * divisor
Expand Down Expand Up @@ -257,4 +257,4 @@ Contact the developers of this tool and tell them which file this happened in!
return decompile
}

export default decompiler
module.exports = decompiler
18 changes: 9 additions & 9 deletions converters/infer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import decompileSgo from './sgo/to-json.js'
import decompileRmp from './rmp/to-json.js'
import compileSgo from './sgo/from-json.js'
import compileRmp from './rmp/from-json.js'
const decompileSgo = require('./sgo/to-json.js')
const decompileRmp = require('./rmp/to-json.js')
const compileSgo = require('./sgo/from-json.js')
const compileRmp = require('./rmp/from-json.js')

const recognized = {
'SGO\0': 'sgo',
Expand All @@ -14,7 +14,7 @@ const recognized = {
'\0MVB': 'bvm',
}

export function identifyBuffer(buffer) {
function identifyBuffer(buffer) {
const leader = buffer.slice(0, 4).toString().toUpperCase()
const match = recognized[leader]
if(match) return match
Expand All @@ -26,7 +26,7 @@ const supported = [
'rmp',
]

export function decompileBuffer(buffer, size) {
function decompileBuffer(buffer, size) {
const type = identifyBuffer(buffer)
if(size) buffer = buffer.slice(0, size)
if(supported.includes(type)) {
Expand All @@ -38,7 +38,7 @@ export function decompileBuffer(buffer, size) {
return buffer.toString('base64')
}

export function identifyData(obj) {
function identifyData(obj) {
if(typeof obj === 'string') return
if(/^sgo$/i.test(obj.format)) return 'sgo'
if(obj.variables) return 'sgo'
Expand All @@ -49,7 +49,7 @@ export function identifyData(obj) {
if(obj.spawns) return 'rmp'
}

export function compileData(obj) {
function compileData(obj) {
const type = identifyData(obj)
if(supported.includes(type)) {
return ({
Expand All @@ -60,7 +60,7 @@ export function compileData(obj) {
return Buffer.from(obj, 'base64')
}

export default {
module.exports = {
identifyBuffer,
decompileBuffer,
identifyData,
Expand Down
6 changes: 3 additions & 3 deletions converters/rmp/from-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import compiler from '../compiler.js'
import sgo from '../sgo/from-json.js'
const compiler = require('../compiler.js')
const sgo = require('../sgo/from-json.js')

function compileRmp(obj) {
const { compile, types } = compiler(obj)
Expand Down Expand Up @@ -158,4 +158,4 @@ function compileRmp(obj) {
compileRmp.compile = compileRmp
compileRmp.compiler = opts => obj => compileRmp(obj, opts)

export default compileRmp
module.exports = compileRmp
6 changes: 3 additions & 3 deletions converters/rmp/to-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import decompiler from '../decompiler.js'
import sgo from '../sgo/to-json.js'
const decompiler = require('../decompiler.js')
const sgo = require('../sgo/to-json.js')

function decompile(buffer, config) {
const { decompile, types } = decompiler('RMP', buffer, config)
Expand Down Expand Up @@ -142,4 +142,4 @@ function decompile(buffer, config) {
return decompile(RmpHeader)
}

export default decompile
module.exports = decompile
8 changes: 4 additions & 4 deletions converters/sgo/from-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import compiler from '../compiler.js'
import { compileData } from '../infer.js'
const compiler = require('../compiler.js')
const infer = require('../infer.js')

function compileSgo(obj) {
const { compile, types } = compiler(obj)
Expand All @@ -18,7 +18,7 @@ function compileSgo(obj) {
} = types

function ExtraSize(cursor, value, offset, tmp) {
const buffer = compileData(value.data || value)
const buffer = infer.compileData(value.data || value)
tmp.buffer = buffer
if(/sgo/i.test(value.format || value.type)) {
const variables = value.data ? value.data.variables : value.variables
Expand Down Expand Up @@ -103,4 +103,4 @@ function compileSgo(obj) {
compileSgo.compile = compileSgo
compileSgo.compiler = () => obj => compileSgo(obj)

export default compileSgo
module.exports = compileSgo
2 changes: 1 addition & 1 deletion converters/sgo/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,4 @@ const values = {
}
}

export default {names, values}
module.exports = {names, values}
4 changes: 2 additions & 2 deletions converters/sgo/to-json.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import decompiler from '../decompiler.js'
const decompiler = require('../decompiler.js')

function decompileSgo(buffer, config) {
const { decompile, types } = decompiler('SGO', buffer, config)
Expand Down Expand Up @@ -120,4 +120,4 @@ function decompileSgo(buffer, config) {
decompileSgo.decompile = decompileSgo
decompileSgo.decompiler = opts => buffer => decompileSgo(buffer, opts)

export default decompileSgo
module.exports = decompileSgo
2 changes: 1 addition & 1 deletion devdocs/command2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// where 0 is 2C, 1 is 2D, 2 is 2E

export default [
module.exports = [
{
representations: [0x0],
group: 0,
Expand Down
2 changes: 1 addition & 1 deletion devdocs/config-sgo-comments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
ModeList: [
[
'GameMode_Scenario', // Title translation key
Expand Down
4 changes: 2 additions & 2 deletions devtools/all-weapons.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
const fs = require('fs')

function allWeapons() {
return Array.from(eachWeapon())
Expand All @@ -21,4 +21,4 @@ function eachWeapon() {

allWeapons.each = eachWeapon

export default allWeapons
module.exports = allWeapons
8 changes: 4 additions & 4 deletions devtools/rename-param.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import allWeapons from 'all-weapons'
import getNode from '../helpers/get-node'
import meta from '../converters/sgo/meta'
const fs = require('fs')
const allWeapons = require('all-weapons')
const getNode = require('../helpers/get-node')
const meta = require('../converters/sgo/meta')

const sentryMeta = meta.names.ammoClasses.SentryGunBullet01

Expand Down
2 changes: 1 addition & 1 deletion devtools/star-simulator-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ function render(weapons, maxes) {
`)
}

export default render
module.exports = render
6 changes: 3 additions & 3 deletions devtools/star-simulator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import allWeapons from './all-weapons'
import getNode from '../helpers/get-node'
import render from './star-simulator-render'
const allWeapons = require('./all-weapons')
const getNode = require('../helpers/get-node')
const render = require('./star-simulator-render')

const maxDmg = {}
const processed = []
Expand Down
2 changes: 1 addition & 1 deletion helpers/blurbs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
smokeGrenade: '\n\n' +
'Press and hold the attack button to wind up your throw, then release to ' +
'let the smoke grenade fly. ' +
Expand Down
10 changes: 5 additions & 5 deletions helpers/bullets.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import syncFs from 'fs'
import getNode from './get-node.js'
const syncFs = require('fs')
const getNode = require('./get-node.js')
const fs = syncFs.promises

let game

export function assignGame(g) {
function assignGame(g) {
game = g
}

Expand Down Expand Up @@ -366,7 +365,8 @@ function SupportUnitBullet01(wpn) {
][wpn.custom[0].value]
}

export default {
module.exports = {
assignGame,
'': BlankBullet,
undefined: BlankBullet,
BombBullet01,
Expand Down
10 changes: 5 additions & 5 deletions helpers/calcdata.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import syncFs from 'fs'
import process from 'process'
import getNode from './get-node.js'
import bullets, { assignGame } from './bullets.js'
const syncFs = require('fs')
const process = require('process')
const getNode = require('./get-node.js')
const bullets = require('./bullets.js')
const fs = syncFs.promises

assignGame(41)
bullets.assignGame(41)

function loadJson(path) {
return fs.readFile(`data/41/${path}.json`).then(data => JSON.parse(data))
Expand Down
10 changes: 5 additions & 5 deletions helpers/calcdata5.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import syncFs from 'fs'
import process from 'process'
import getNode from './get-node.js'
import bullets, { assignGame } from './bullets.js'
const syncFs = require('fs')
const process = require('process')
const getNode = require('./get-node.js')
const bullets = require('./bullets.js')
const fs = syncFs.promises

assignGame(5)
bullets.assignGame(5)

function loadJson(path) {
return fs.readFile(`data/5/${path}.json`).then(data => JSON.parse(data))
Expand Down
2 changes: 1 addition & 1 deletion helpers/get-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ function getId(meta) {
return meta.value[0].value
}

export default getId
module.exports = getId
2 changes: 1 addition & 1 deletion helpers/get-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ function getNode(template, name) {
return template.variables.find(n => n.name === name)
}

export default getNode
module.exports = getNode
2 changes: 1 addition & 1 deletion helpers/growth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function growth({ base, zero, exp, lvMin, lvMax, type, algo }) {
return ret
}

export default growth
module.exports = growth
4 changes: 2 additions & 2 deletions helpers/hexview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import kleur from 'kleur'
const kleur = require('kleur')
const { underline, dim } = kleur
kleur.enabled = process.stdout.isTTY

Expand Down Expand Up @@ -27,4 +27,4 @@ function hexview(buffer, cfg={}) {
)
}

export default hexview
module.exports = hexview
4 changes: 2 additions & 2 deletions helpers/patch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import getNode from './get-node.js'
const getNode = require('./get-node.js')

function patch(template, name, value) {
const node = getNode(template, name)
const v = typeof value === 'function' ? value(node.value, node) : value
node.value = v
}

export default patch
module.exports = patch
4 changes: 2 additions & 2 deletions helpers/weapon-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import blurbs from './blurbs.js'
const blurbs = require('./blurbs.js')

function format(pair) {
if(!pair) return ''
Expand Down Expand Up @@ -144,4 +144,4 @@ function weaponText(template, text) {
.replace('$JUMP$', blurbs.jump)
}

export default weaponText
module.exports = weaponText
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "sgott",
"version": "1.10.0",
"description": "SGO Transformation Tool, SGO to JSON and back.",
"type": "module",
"main": "sgott.js",
"bin": "sgott.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion sgo-json-to-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function sgoJsonToSimple(data) {
return data
}

export default sgoJsonToSimple
module.exports = sgoJsonToSimple
16 changes: 8 additions & 8 deletions sgott.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
import fs from 'fs'
import path from 'path'
import json from 'json-stringify-pretty-compact'
import config from './package.json' assert { type: 'json' }
import sgoToJson from './converters/sgo/to-json.js'
import jsonToSgo from './converters/sgo/from-json.js'
import rmpToJson from './converters/rmp/to-json.js'
import jsonToRmp from './converters/rmp/from-json.js'
const fs = require('fs')
const path = require('path')
const json = require('json-stringify-pretty-compact')
const config = require('./package.json')
const sgoToJson = require('./converters/sgo/to-json.js')
const jsonToSgo = require('./converters/sgo/from-json.js')
const rmpToJson = require('./converters/rmp/to-json.js')
const jsonToRmp = require('./converters/rmp/from-json.js')

function isSgo(obj) {
if(/^sgo$/i.test(obj.format)) return true
Expand Down
28 changes: 14 additions & 14 deletions sgottstrap.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node
import fs from 'fs'
import deepEqual from 'fast-deep-equal'
import CSON from 'cson'
import sgoToJson from './converters/sgo/to-json.js'
import jsonToSgo from './converters/sgo/from-json.js'
import generateWeaponText from './helpers/weapon-text.js'

import config41 from './data/41/CONFIG.json' assert { type: 'json' }
import weaponTable41 from './data/41/weapon/_WEAPONTABLE.json' assert { type: 'json' }
import weaponText41 from './data/41/weapon/_WEAPONTEXT.json' assert { type: 'json' }

import config5 from './data/5/CONFIG.json' assert { type: 'json' }
import weaponTable5 from './data/5/weapon/WEAPONTABLE.json' assert { type: 'json' }
import weaponText5 from './data/5/weapon/WEAPONTEXT.json' assert { type: 'json' }
const fs = require('fs')
const deepEqual = require('fast-deep-equal')
const CSON = require('cson')
const sgoToJson = require('./converters/sgo/to-json.js')
const jsonToSgo = require('./converters/sgo/from-json.js')
const generateWeaponText = require('./helpers/weapon-text.js')

const config41 = require('./data/41/CONFIG.json')
const weaponTable41 = require('./data/41/weapon/_WEAPONTABLE.json')
const weaponText41 = require('./data/41/weapon/_WEAPONTEXT.json')

const config5 = require('./data/5/CONFIG.json')
const weaponTable5 = require('./data/5/weapon/WEAPONTABLE.json')
const weaponText5 = require('./data/5/weapon/WEAPONTEXT.json')

const edfVersion = fs.existsSync('EDF5.exe') ? 5 : 41
const edfName = edfVersion === 5 ? 'EDF5' : 'EDF4.1'
Expand Down

0 comments on commit 289a577

Please sign in to comment.