Skip to content

Commit

Permalink
make health pack its own plugin, finish dep code
Browse files Browse the repository at this point in the history
  • Loading branch information
onlypuppy7 committed Nov 20, 2024
1 parent 14dc64d commit ad45e54
Show file tree
Hide file tree
Showing 9 changed files with 789 additions and 48 deletions.
3 changes: 2 additions & 1 deletion plugins_default/LegacyShellCore/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

export const dependencies = {
// "is-thirteen": "^2.0.0",
// newmapblocks: "plugin"
modernmapblocks: "plugin",
healthpackitem: "plugin",
};
9 changes: 6 additions & 3 deletions plugins_default/LegacyShellCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const PluginMeta = {
identifier: "legacyshellcore",
name: 'LegacyShellCore',
author: 'onlypuppy7',
version: '1.0.3',
version: '1.0.4',
descriptionShort: 'Used in the public instance', //displayed when loading
descriptionLong: 'Used in the public instance',
legacyShellVersion: 269, //legacy shell version, can be found in /versionEnum.txt, or just on the homescreen
Expand All @@ -27,11 +27,14 @@ export class Plugin {

LegacyShellCorePlugin.registerListeners(this.plugins);
this.plugins.on('client:pluginSourceInsertion', this.pluginSourceInsertion.bind(this));

this.plugins.on('client:prepareBabylon', this.prepareBabylon.bind(this));
this.plugins.on('client:stampImageDirs', this.stampImageDirs.bind(this));
this.plugins.on('game:prepareBabylon', this.prepareBabylon.bind(this));
this.plugins.on('services:initTables', this.initTables.bind(this));


this.plugins.on('client:stampImageDirs', this.stampImageDirs.bind(this));
this.plugins.on('services:initTables', this.initTables.bind(this));

this.plugins.on('game:metaLoop', this.metaLoopHook.bind(this));
this.plugins.on('game:clientPackSyncLoop', this.clientPackSyncLoopHook.bind(this));
};
Expand Down
30 changes: 1 addition & 29 deletions plugins_default/LegacyShellCore/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const LegacyShellCorePlugin = {

this.plugins = pluginManager;

this.plugins.on('game:onMapComplete', this.onMapComplete.bind(this));
this.plugins.on('game:canJump', this.canJump.bind(this));
this.plugins.on('game:AllItems', this.AllItems.bind(this));
this.plugins.on('game:GameTypesInit', this.GameTypesInit.bind(this));
this.plugins.on('game:fireCluck9mm', this.fireCluck9mm.bind(this));

Expand All @@ -35,32 +33,6 @@ export const LegacyShellCorePlugin = {
};
},

onMapComplete(data) {
var gameScene = data.gameScene;

gameScene.getMeshByName("healthpack").material = gameScene.getMaterialByName("standardInstanced");
gameScene.getMeshByName("healthpack.alt").material = gameScene.getMaterialByName("standardInstanced");
},

AllItems(data) {
var AllItems = data.AllItems;

AllItems.push({
codeName: "HEALTH",
mesh: "healthpack.alt",
name: "Health Pack",
actor: data.ItemActor,
poolSize: 50,
collect: function (player, applyToWeaponIdx) {
if (player.hp === 100) return false
if (isServer) {
player.heal(50);
};
return true;
}
});
},

GameTypesInit(data) {
var defaultOptions = data.defaultOptions;

Expand Down Expand Up @@ -268,7 +240,7 @@ export const LegacyShellCorePlugin = {
});
},

registerSampleCommand: function (data) { //example of command registration
registerSampleCommand: function (data) {
console.log("registering sample command... (sample plugin)");
var ctx = data.this;

Expand Down
5 changes: 5 additions & 0 deletions plugins_default/healthpackitem/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//

export const dependencies = {
// "is-thirteen": "^2.0.0",
};
58 changes: 58 additions & 0 deletions plugins_default/healthpackitem/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//basic
import fs from 'node:fs';
import path from 'node:path';
//plugin: samplecommand
import { HealthPackItem } from './shared.js';
//

export const PluginMeta = {
identifier: "healthpackitem",
name: 'Health Pack Item',
author: 'onlypuppy7',
version: '1.0.0',
descriptionShort: 'Adds a new item type which regains 50hp on collection', //displayed when loading
descriptionLong: 'Adds a new item type which regains 50hp on collection',
legacyShellVersion: 324, //legacy shell version, can be found in /versionEnum.txt, or just on the homescreen
};

export var pluginInstance = null;

export class Plugin {
constructor(plugins, thisDir) {
this.plugins = plugins;
this.thisDir = thisDir;

pluginInstance = this;

HealthPackItem.registerListeners(this.plugins);
this.plugins.on('client:pluginSourceInsertion', this.pluginSourceInsertion.bind(this));
this.plugins.on('client:prepareBabylon', this.prepareBabylon.bind(this));
this.plugins.on('game:prepareBabylon', this.prepareBabylon.bind(this));
};

pluginSourceInsertion(data) {
data.pluginInsertion.files.push({
insertBefore: '\nconsole.log("inserting before... (HealthPackItem)");',
filepath: path.join(this.thisDir, 'shared.js'),
insertAfter: '\nconsole.log("inserting after... (HealthPackItem)!");',
position: 'before'
});
};

async prepareBabylon(data) {
// console.log('prepareBabylon', data.filename);
var extraBabylons = data.extraBabylons;

const babylonPath = path.join(this.thisDir, 'models');
const babylonFiles = fs.readdirSync(babylonPath);
for (const file of babylonFiles) {
if (data.filename + ".babylon" === file) {
console.log('found', file);
extraBabylons.push({
filepath: path.join(this.thisDir, 'models', file),
overwrite: false,
});
};
};
};
};
Loading

0 comments on commit ad45e54

Please sign in to comment.