Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharparam committed Mar 22, 2023
0 parents commit 24c475f
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore built packages
*.zip

# Ignore build dir
/build/

# Ignore local setup script
/setup.sh
1 change: 1 addition & 0 deletions .lua-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.2.1
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"justarandomgeek.factoriomod-debug",
"sumneko.lua"
]
}
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug"
},
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug (Settings & Data)",
"hookSettings": true,
"hookData": true
},
{
"type": "factoriomod",
"request": "launch",
"name": "Factorio Mod Debug (Profile)",
"hookMode": "profile"
}
]
}
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Cybersyn Combinator

A mod for Factorio that adds a special combinator for use with the [Project Cybersyn][cybersyn] mod.

## Usage

*TODO*

## License

Copyright ©️ 2023 by [Adam Hellberg][sharparam].

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

[sharparam]: https://sharparam.com
[cybersyn]: https://mods.factorio.com/mod/cybersyn
156 changes: 156 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env bash

set -euo pipefail

VERBOSE=false

println() {
cat <<< "$@"
}

eprintln() {
cat <<< "$@" 1>&2
}

vprintln() {
if [[ "$VERBOSE" == true ]]; then
eprintln "$@"
fi
}

usage() {
cat <<EOF
Usage: $0 [-hvc] [-s SRCDIR] [-o OUTDIR]
-h
Displays this help message.
-v
Enables verbose mode.
-c
Cleans intermediate build files after building.
-s SRCDIR
Specify source directory for mod files (default is 'src').
-o OUTDIR
Specify output directory for release files (default is 'build').
EOF
}

CLEAN=false
SRCDIR="src"
OUTDIR="build"

OPTIND=1

while getopts "hvcs:o:" opt; do
case "$opt" in
h)
usage
exit 0
;;
v)
VERBOSE=true
;;
c)
CLEAN=true
;;
s)
SRCDIR=${OPTARG}
;;
o)
OUTDIR=${OPTARG}
;;
:)
eprintln "Option -$OPTARG requires an argument"
exit 1
;;
\?)
usage 1>&2
exit 1
;;
*)
usage 1>&2
exit 1
;;
esac
done

VERSION="unknown"
VERSION_FULL="unknown"

version() {
local -r fallback='0.1.0'
local gitver
gitver=$(git describe --always)
local -r withcommit='^v([0-9]+\.[0-9]+\.[0-9]+)(-[0-9]+-[[:alnum:]]+)?$'
local -r commit='^[[:alnum:]]+$'
if [[ "$gitver" =~ $withcommit ]]; then
# We have an exact version
VERSION=${BASH_REMATCH[1]}
VERSION_FULL="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
elif [[ "$gitver" =~ $commit ]]; then
VERSION="$fallback"
VERSION_FULL="$fallback-${BASH_REMATCH[0]}"
fi
}

version

if [[ "$VERSION" == "unknown" ]]; then
eprintln "Failed to resolve valid version"
exit 1
fi

if [[ ! -d "$SRCDIR" ]]; then
eprintln "Specified src dir $SRCDIR does not exist"
exit 1
fi

SRCINFO="$SRCDIR/info.json"

if [[ ! -f "$SRCINFO" ]]; then
eprintln "Could not locate info.json in src dir $SRCDIR"
exit 1
fi

MODNAME=$(jq -r .name "$SRCINFO")

vprintln "Detected mod name $MODNAME"
vprintln "Detected version: $VERSION ($VERSION_FULL)"

vprintln "Current working dir: $PWD"

vprintln "Cleaning and creating build dir"
RELNAME="${MODNAME}_${VERSION}"
RELDIR="$OUTDIR/${MODNAME}_$VERSION"
ZIPNAME="${RELNAME}.zip"
rm -rf "$OUTDIR"
mkdir -p "$RELDIR"

vprintln "Copying mod files to $RELDIR"
cp -a "$SRCDIR/." "$RELDIR"
[[ -f README.md ]] && cp -a README.md "$RELDIR"
[[ -f LICENSE ]] && cp -a LICENSE "$RELDIR"

RELINFO="$RELDIR/info.json"
tmpinfo=$(mktemp)
jq --arg version "$VERSION" '.version = $version' "$RELINFO" > "$tmpinfo" && mv "$tmpinfo" "$RELINFO"

vprintln "Zip name: $ZIPNAME"
(
pushd "$OUTDIR" > /dev/null \
&& zip \
-r \
"$ZIPNAME" \
"$RELNAME" \
--exclude \
'*~'
)

if [[ "$CLEAN" == true ]]; then
vprintln "Cleaning $RELDIR"
rm -rf "$RELDIR"
fi
13 changes: 13 additions & 0 deletions bin/fmtk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

fmtk() {
exec npx factoriomod-debug@latest "$@"
}

if [[ -d src ]]; then
(pushd src > /dev/null && fmtk "$@")
else
fmtk
fi
17 changes: 17 additions & 0 deletions src/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "cybersyn-combinator",
"version": "0.0.0",
"title": "Cybersyn Combinator",
"author": "Sharparam",
"contact": "[email protected]",
"homepage": "https://github.com/Sharparm/cybersyn-combinator",
"description": "A specialized combinator for the Project Cybersyn mod",
"factorio_version": "1.1",
"dependencies": [
"cybersyn"
],
"package": {
"readme": "information.md",
"faq": "faq.md"
}
}
2 changes: 2 additions & 0 deletions src/locale/mod.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mod-description]
cybersyn-combinator=A specialized combinator for the Project Cybersyn mod.

0 comments on commit 24c475f

Please sign in to comment.