Skip to content

Commit

Permalink
Merge pull request #15 from flowerLoader/devel-windows
Browse files Browse the repository at this point in the history
Integrate Devel-Windows fixes into core
  • Loading branch information
RobynLlama committed May 27, 2024
2 parents 482ba52 + 97a706b commit 7461601
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 29 deletions.
7 changes: 7 additions & 0 deletions build/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const ENABLED_PLUGINS = [
/*
* each entry in this list should be a quoted string with the full name
* of the file relative to the plugins folder and end in a comma
* "flowerteam.plugintemplate.js", <= like this
*/
];
13 changes: 7 additions & 6 deletions flowerful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export class flowerCore<T>

async LoadAllPlugins(plugin_root: string): Promise<void>
{
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
const fs = require('fs');
const plugin_dir = `${plugin_root}/flower-plugins/`;
// load json from local file
const str = `./config.js`
const js = await import(str);

const files = fs.readdirSync(plugin_dir, {})
const files: string[] = js.ENABLED_PLUGINS;
this.MyLogSource.writeDebug(`Loading ${files.length} plugins`);

for (const file of files)
Expand All @@ -44,8 +44,9 @@ export class flowerCore<T>
} catch (e: any)
{
this.MyLogSource.write(`Error loading ${guid}: ${e.message}`);

//Delete patches from bad boys that fail on Awake()
delete this.Plugins[guid];
//Strech goals: Delete patches from bad boys that fail on Awake()
}

}
Expand Down Expand Up @@ -113,7 +114,7 @@ export class flowerCore<T>
this.Patcher = new flowerPatcher(this.MyLogSource);

//API nonsense
API.RegisterPatch = this.Patcher.RegisterPatch;
API.RegisterPatch = this.Patcher.RegisterPatch.bind(this.Patcher);
this.API = API;
}
}
43 changes: 29 additions & 14 deletions gameSupport/games.coaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ import { FlowerAPI, LogSource } from "@flowerloader/api";
import { GameDataCOAW, tGameMain } from "@flowerloader/coawtypes";
import { flowerCore } from "../flowerful";

/**
* Returns the platform specific game location
*/
function GetGameRoot(): string
{
//chrome-extension://eobfdhbhahidclhbabnladfbafcbfdmn/gamedata/game/flower/flower-plugins/
//Get the window location
let base = nw.Window.get().window.location.toString()
console.log(base)

base = base.replace("index.html", "")
console.log(base)

//@ts-ignore
base = base.replace("chrome-extension://eobfdhbhahidclhbabnladfbafcbfdmn", nw.global.__dirname);
console.log(base)

return base
}

/**
* This is how long flower waits in ms before setting up at the start
* This will need to be configurable on a per-game basis
Expand All @@ -16,7 +36,6 @@ const timeout = 100;
let logger: any = {} as { window: Window };

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
declare const nw: any;
declare const tWgm: tGameMain;

const flowerAPI: FlowerAPI<GameDataCOAW> = {
Expand All @@ -31,7 +50,6 @@ let core: flowerCore<GameDataCOAW> = new flowerCore(new LogSource("Flower", Writ

function WriteLog(title: string, message: string)
{

const logBody = logger.window.document.getElementById("log-body");
const el = logger.window.document.createElement("div");
el.className = "log-entry"
Expand All @@ -52,17 +70,13 @@ function WriteDebug(title: string, message: string)
function SetupLogger()
{
//Logger window
const url = "file:///" + nw.global.__dirname + "/gamedata/game/logger.html";
nw.Window.open(url, {
/*frame: debbug,*/
width: 600,
height: 800,
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
}, function (win: any)
const url = "./flower/logger.html";

const win = window.open(url, 'Logger', 'popup=1,width=600,height=800')
win!.addEventListener('load', function ()
{
win.once('loaded', function ()
{
onLoggerWindowLoaded(win);
onLoggerWindowLoaded({
window: win,
});
});
}
Expand All @@ -74,7 +88,7 @@ function onLoggerWindowLoaded(win: any)
//win.window.document.body.innerHTML += "<h2>Executable Started</h2>";

//Start patchloading here
core.LoadAllPlugins(nw.global.__dirname + "/gamedata/game/js/game");
core.LoadAllPlugins("./flower");
}

window.onload = function ()
Expand All @@ -85,4 +99,5 @@ window.onload = function ()
}, timeout);
};

export default function GetFlowerAPI() { return flowerAPI }
//pretty sure we don't need this
//export default function GetFlowerAPI() { return flowerAPI }
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
"eslint": "^8.57.0",
"globals": "^15.2.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.9.0"
"typescript-eslint": "^7.9.0",
"@types/nw.gui": "^0.0.25",
"@types/nw.js": "^0.13.21"
},
"dependencies": {
"@flowerloader/api": "^1.2.0",
"@flowerloader/coawtypes": "^1.0.0"
}
}
}
22 changes: 15 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,34 @@ To find Your base install directory right click on steam and select Manage>Brows
You should see the files `index.html` and `empty.html`. This folder is your base install directory. All instructions will be given with this folder as the root in mind.
</details>

3. Copy the contents of your release zip directly into the base install directory. You should now have `logger.html` and `logger.css` alongside the files `index.html` and `empty.html` from before like so:
3. Copy the contents of your release zip directly into the base install directory. You should now have a `flower` folder alongside the files `index.html` and `empty.html` from before like so:

```plaintext
- base_install_directory
+- logger.html
+- logger.css
+- index.html
+- empty.html
++ flower
+- flowerful.js
+- config.js
++ flower-plugins
+- feed_me_plugins
<There will be more folders and files>
```

4. Open the file index.html in your base install directory and locate the following line:
```html
<script src="./js/game/union.js"></script>
```
Add a reference to flower.js directly below that line so it looks like the following:
Add a reference to flowerful.js directly below that line so it looks like the following:
```html
<script src="./js/game/union.js"></script>
<script type="module" src="./js/game/flowerful.js"></script>
<script type="module" src="./flower/flowerful.js"></script>
```

Congrats, Flower is now installed!

Flower keeps its plugins in the folder `js/game/flower-plugins/` under your base install directory. You can copy in any plugins you wish to use into this directory and flower will find them automatically. If flower reports that a plugin you want to use is disabled, you can edit the JS file and set `enabled=true` on the plugin's meta information. You can also do the opposite if you wish to disable a plugin without deleting it from your plugins folder.
Flower keeps its plugins in the folder `/flower/flower-plugins/` under your base install directory. You can copy in any plugins you wish to use into this directory and then add them to the config.js file to use them. If flower reports that a plugin you want to use is disabled, you can edit the JS file and set `enabled=true` on the plugin's meta information. You can also do the opposite if you wish to disable a plugin without deleting it from your plugins folder or config.js.

### From Source

Expand Down Expand Up @@ -122,7 +126,7 @@ You can simply run the build task from VSCode if you're using it or run the esbu
npx esbuild --bundle flowerful.ts --format=esm --outdir=build/ --platform=node
```

You will then need to copy the resulting `flowerful.js` file into your base install directory under `/js/game/` alongside `union.js`. In the same location you will need a `flower-plugins` folder for your plugins. Finally, you will need to copy `logger.html` and `logger.css` into your base install directory and configure you `index.html`.
After compilation is complete, navigate to the base install directory and then `/flower` under that, creating it if it does not already exist. You will want to copy the following files to this location: `flowerful.js` `logger.html` and `logger.css` and finally create a folder called `flower-plugins` if it does not exist. You will also need a `config.js` file that lists the plugins flower will load. If you don't already have one from a previous install you can copy a blank one from the `/build` folder in the project.

For more information on your base install directory and how to configure `index.html` see [Manual install instructions](#from-a-released-version)

Expand All @@ -139,5 +143,9 @@ We welcome contributions! More information will be added soon!
- The simplest and fastest way is to run `verify game files` for the game on steam.
- Alternatively, you may remove the line you added to `index.html` and flower will no longer be loaded.
- Finally, either way, you may remove all the files you copied in to your base game directory or leave them, they won't be loaded or effect the game in any way anymore

- **How do I configure what plugins Flower loads?**
- Simply edit the `config.js` file under your base install directory in the `flower` folder. There are comments inside this file that explain how to set flower to load plugins.


- More troubleshooting tips and frequently asked questions will be added soon.

0 comments on commit 7461601

Please sign in to comment.