Skip to content

Commit

Permalink
update dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
neolao committed Jan 29, 2024
1 parent 164a01f commit cb921fc
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 57 deletions.
3 changes: 3 additions & 0 deletions dev-env/.engine/Ikemen_GO/Ikemen_GO_Linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#/bin/bash

echo "Fake Ikemen"
3 changes: 3 additions & 0 deletions dev-env/.engine/Ikemen_GO/Ikemen_GO_MacOS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#/bin/bash

echo "Fake Ikemen"
84 changes: 84 additions & 0 deletions dev-env/.engine/run-ikemen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#/bin/bash

currentDirectory=$(dirname "$(realpath "$0")")
cd "$currentDirectory/Ikemen_GO"

configPath="../../save/config.json"
motifDirectory="../../../motifs"
lifebarDirectory="../../lifebars"
stageDirectory="../../../stages"
characterDirectory="../../../chars"

motif="motif/system.def"
lifebar="01/fight.def"
rounds=2
characterOneColor=1
characterTwoColor=1
characterTwoAI=0

for i in "$@"; do
case $i in
-motif=*)
motif="${i#*=}"
shift
;;
-lifebar=*)
lifebar="${i#*=}"
shift
;;
-p1=*)
characterOne="${i#*=}"
shift
;;
-p1.color=*)
characterOneColor="${i#*=}"
shift
;;
-p2=*)
characterTwo="${i#*=}"
shift
;;
-p2.color=*)
characterTwoColor="${i#*=}"
shift
;;
-p2.ai=*)
characterTwoAI="${i#*=}"
shift
;;
-s=*)
stage="${i#*=}"
shift
;;
-rounds=*)
rounds="${i#*=}"
shift
;;
*)
;;
esac
done

case "$OSTYPE" in
darwin*) #echo "It's a Mac!!" ;
ikemen="./Ikemen_GO_MacOS -AppleMagnifiedMode YES"
;;
linux*)
ikemen="./Ikemen_GO_Linux"
;;
*)
ikemen="./Ikemen_GO_Linux"
;;
esac

$ikemen \
-config "$configPath" \
-r "$motifDirectory/$motif" \
-lifebar "$lifebarDirectory/$lifebar" \
-s "$stageDirectory/$stage" \
-rounds $rounds \
-p1 "$characterDirectory/$characterOne" \
-p1.color $characterOneColor \
-p2 "$characterDirectory/$characterTwo" \
-p2.color $characterTwoColor \
-p2.ai $characterTwoAI
File renamed without changes.
76 changes: 76 additions & 0 deletions dev-env/motifs/system.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[Info]
name = Quick Versus
author = neolao
versiondate = 01,26,2024
mugenversion = 1.1
localcoord = 1280,720
;localcoord = 1920,1080

[Files]
spr = system.sff ;Filename of sprite data
snd = system.snd ;Filename of sound data
select = select.def ;Character and stage selection list
fight = fight.def ;Fight definition filename
font1 = f-4x6.def ;System fonts
font2 = f-6x9.def ;System fonts
font3 = jg.fnt ;System fonts
font4 = Open_Sans.def
font5 = default-3x5-bold.def
font6 = default-3x5.def
module = ;Ikemen feature: External Lua code

[Music]

[Title Info]

[TitleBGdef]

[TitleBG]
type = normal
spriteno = 0,0

[Select Info]

[SelectBGdef]

[SelectBG]
type = normal
spriteno = 0,0

[VS Screen]

[VersusBGdef]

[VersusBG]
type = normal
spriteno = 0,0

[Demo Mode]
[Continue Screen]

[Game Over Screen]

[Victory Screen]

[VictoryBGdef]

[VictoryBG]
type = normal
spriteno = 0,0

[Win Screen]

[Default Ending]

[End Credits]

[Survival Results Screen]

[Option Info]

[OptionBGdef]

[OptionBG]
type = normal
spriteno = 0,0

8 changes: 5 additions & 3 deletions dev-env/quick-versus.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"frame": true,
"motif": "system.def",
"lifebar": "01/fight.def",
"rounds": 2,
"characterColumns": 3,
"ikemenExecutablePath": "mugen.exe",
"sound": {
"volume": 30,
"background": "sound/title.mp3",
Expand All @@ -11,7 +13,7 @@
"selectAILevel": "sound/confirm.wav",
"moveCursor": "sound/move-cursor.wav",
"cancel": "sound/cancel.wav"
},
},
"categories": [
{
"name": "Capcom",
Expand Down Expand Up @@ -242,7 +244,7 @@
"y": "q",
"l1": "d",
"r1": "c",
"quit": "i"
"quit": "escape"
},
"gamepad": {
"left": "A17",
Expand Down
70 changes: 55 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execFile } = require("node:child_process");
const util = require("node:util");
const exec = util.promisify(require("node:child_process").exec);
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const fs = require("fs");
Expand All @@ -14,6 +15,7 @@ try {
function getCurrentDirectory() {
let currentDirectory;
if (process.argv.length >= 3) {
// TODO use a named option
currentDirectory = path.normalize(process.argv[2]);
} else if (isDev) {
currentDirectory = path.resolve(app.getAppPath(), "dev-env");
Expand All @@ -33,22 +35,28 @@ function getCurrentDirectory() {
return currentDirectory;
}

function getConfiguration() {
const currentDirectory = getCurrentDirectory();
const jsonFilePath = path.resolve(currentDirectory, "quick-versus.json");
const yamlFilePath = path.resolve(currentDirectory, "quick-versus.yml");
let config;
if (fs.existsSync(jsonFilePath)) {
config = require(jsonFilePath);
} else if (fs.existsSync(yamlFilePath)) {
config = configYaml(yamlFilePath);
}

return config;
}

function createWindow() {
let width = 1024;
let height = 576;
let fullscreen = false;
let frame = false;

try {
const currentDirectory = getCurrentDirectory();
const jsonFilePath = path.resolve(currentDirectory, "quick-versus.json");
const yamlFilePath = path.resolve(currentDirectory, "quick-versus.yml");
let config;
if (fs.existsSync(jsonFilePath)) {
config = require(jsonFilePath);
} else if (fs.existsSync(yamlFilePath)) {
config = configYaml(yamlFilePath);
}
const config = getConfiguration();

if (config) {
if (config.hasOwnProperty("width")) {
Expand Down Expand Up @@ -99,10 +107,42 @@ function getVersion(event) {
event.returnValue = version;
}

async function executeFile (event, filePath, args, options) {
execFile(filePath, args, options, () => {
event.returnValue = true;
});
async function launchGame(event, options) {
const directoryPath = getCurrentDirectory();
const filePath = `${directoryPath}/.engine/run-ikemen.sh`;
const config = getConfiguration();

let command = `"${filePath}"`;
if (config.rounds) {
command += ` -rounds="${config.rounds}"`;
}
if (config.motif) {
command += ` -motif="${config.motif}"`;
}
if (config.lifebar) {
command += ` -lifebar="${config.lifebar}"`;
}
if (options.characterOne) {
command += ` -p1="${options.characterOne}"`;
}
if (options.characterOneColorIndex) {
command += ` -p1.color="${options.characterOneColorIndex}"`;
}
if (options.characterTwo) {
command += ` -p2="${options.characterTwo}"`;
}
if (options.characterTwoColorIndex) {
command += ` -p2.color="${options.characterTwoColorIndex}"`;
}
if (options.characterTwoAILevel) {
command += ` -p2.ai="${options.characterTwoAILevel}"`;
}
if (options.stage) {
command += ` -s="${options.stage}"`;
}
console.log(command);
await exec(command, { cwd: directoryPath });
return true;
}

function getConfigYaml(event, filePath) {
Expand Down Expand Up @@ -132,7 +172,7 @@ function getCurrentDirectoryExported(event) {
async function start() {
await app.whenReady();
ipcMain.on("getVersion", getVersion);
ipcMain.on("execFile", executeFile);
ipcMain.handle("launchGame", launchGame);
ipcMain.on("existsSync", existsSync);
ipcMain.on("readFileSync", readFileSync);
ipcMain.on("resolve", resolve);
Expand Down
2 changes: 1 addition & 1 deletion preload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { contextBridge, ipcRenderer } = require("electron/renderer");

contextBridge.exposeInMainWorld("mainAPI", {
execFile: async (filePath, args, options) => ipcRenderer.send("execFile", filePath, args, options),
launchGame: (args) => ipcRenderer.invoke("launchGame", args),
existsSync: (filePath) => ipcRenderer.sendSync("existsSync", filePath),
readFileSync: (filePath) => ipcRenderer.sendSync("readFileSync", filePath),
resolve: (...args) => ipcRenderer.sendSync("resolve", args),
Expand Down
13 changes: 0 additions & 13 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,8 @@ export default function App() {
}
}

const ikemenPath = mainAPI.resolve(currentDirectory, configuration.ikemenExecutablePath);
if (!mainAPI.existsSync(ikemenPath)) {
return (
<Requirement>
<p>
Ikemen executable file is missing:
{ikemenPath}
</p>
</Requirement>
);
}

const environment = {
currentDirectory,
ikemenPath,
configurationFilePath
};

Expand Down
36 changes: 11 additions & 25 deletions src/fight/fight.presenter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,34 @@ const BlackScreen = styled.div`
export default function Fight() {
const configuration = useConfiguration();
const navigation = useNavigation();
const environment = useEnvironment();
const dispatch = useNavigationDispatch();
const backgroundSound = useBackgroundSound();

if (navigation.state === TRAINING_FIGHTING || navigation.state === VERSUS_FIGHTING) {
const options = [
"-p1",
navigation.characterOne.definition,
"-p2",
navigation.characterTwo.definition,
"-s",
navigation.stage.definition,
"-rounds",
2
];
if (configuration.motif) {
options.push("-r", configuration.motif);
}
const options = {
characterOne: navigation.characterOne.definition,
characterTwo: navigation.characterTwo.definition,
stage: navigation.stage.definition
};

if (navigation.characterOneColorIndex) {
options.push("-p1.color", navigation.characterOneColorIndex);
options.characterOneColorIndex = navigation.characterOneColorIndex;
}
if (navigation.characterTwoColorIndex) {
options.push("-p2.color", navigation.characterTwoColorIndex);
options.characterTwoColorIndex = navigation.characterTwoColorIndex;
}
if (navigation.characterTwoAILevel > 0) {
options.push("-p2.ai", navigation.characterTwoAILevel);
options.characterTwoAILevel = navigation.characterTwoAILevel;
}

backgroundSound.pause();
mainAPI.minimize();
mainAPI.execFile(
environment.ikemenPath,
options,
{
cwd: environment.currentDirectory
}
).then(() => {
mainAPI.launchGame(options).then(() => {
dispatch(endFight());
backgroundSound.play();
mainAPI.restore();
});
console.log(environment.ikemenPath, options);
console.log("launchGame", options);

return <BlackScreen>Fighting ...</BlackScreen>;
}
Expand Down
Loading

0 comments on commit cb921fc

Please sign in to comment.