Skip to content

Commit

Permalink
Entity - inflateEntity() use default build on remote ents that fail
Browse files Browse the repository at this point in the history
`EntityBuilder` - Add restitution property
`EntityBuilder` - Color mixing should now always yield valid color
`utils` - Adds missing colors to ensure color ints
`CrossWindows` - Updates paths for CI
  • Loading branch information
Marak committed Mar 8, 2024
1 parent 6ab05aa commit db1872a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
10 changes: 7 additions & 3 deletions mantra-game/Entity/EntityBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export default class EntityBuilder {
return this;
}

restitution(value) {
this.config.restitution = value;
return this;
}

// Health and scoring
health(value) {
this.config.health = value;
Expand Down Expand Up @@ -636,12 +641,11 @@ export default class EntityBuilder {
}
}

// Function to blend two colors
function blendColors(color1, color2) {
const r = ((color1 >> 16) + (color2 >> 16)) >> 1;
const r = (((color1 >> 16) & 0xFF) + ((color2 >> 16) & 0xFF)) >> 1;
const g = (((color1 >> 8) & 0xFF) + ((color2 >> 8) & 0xFF)) >> 1;
const b = ((color1 & 0xFF) + (color2 & 0xFF)) >> 1;
return (r << 16) | (g << 8) | b;
return ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}

/* TODO: refactor to store Map() of OG references for granular removals / updates
Expand Down
11 changes: 6 additions & 5 deletions mantra-game/plugins/crosswindow/CrossWindow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// CrossWindow.js - Mantra Plugin - Marak Squires 2024
// see: CrossWindow.js: https://github.com/yantra-core/CrossWindow.js

import * as CW from '../../../../CrossWindow.js/browser-shim.js';
import * as CWDEBUG from '../../../../CrossWindow.js/browser-shim-debugger.js';
// import crosswindow from 'crosswindow';
// import { CrossWindow as CW, CrossWindowDebugger } from '../../../../CrossWindow.js/index.js'
import { CrossWindow as CW, CrossWindowDebugger } from 'crosswindow';

export default class CrossWindow {
static id = 'crosswindow';
Expand All @@ -13,15 +14,15 @@ export default class CrossWindow {

init(game) {
this.game = game;
console.log('CrossWindow plugin initialized', CW);
//console.log('CrossWindow plugin initialized', CrossWindow);
// Initialize CrossWindow instance
this.crosswindow = new CW.CrossWindow(window, {
this.crosswindow = new CW(window, {
broadcastMouseEvents: true,
broadcastKeyboardEvents: true,
});

// Optionally initialize CrossWindow debugger
this.crossWindowDebugger = new CWDEBUG.CrossWindowDebugger(this.crosswindow, {
this.crossWindowDebugger = new CrossWindowDebugger(this.crosswindow, {
showOtherWindows: true,
showWindowLegend: true,
showWindowCount: true,
Expand Down
25 changes: 22 additions & 3 deletions mantra-game/plugins/entity/lib/inflateEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ export default function inflateEntity(entityData) {
}
}
catch (err) {
console.warn('Failed to build remote entity by type:', type, err);
console.warn('Failed to build remote entity by type:', type, err, 'using default build');
defaultBuild(game, entityData)
}

//console.log('proceeding with typed data', entityData)
console.log('proceeding with typed data', entityData)

} else {
defaultBuild(game, entityData);
}

return updateOrCreate(game, entityData);
Expand All @@ -71,12 +74,28 @@ export default function inflateEntity(entityData) {

}

function defaultBuild(game, entityData) {
// merge default build make
let defaultConfig = game.make().build();
for (let p in defaultConfig) {
if (typeof entityData[p] === 'undefined' || entityData[p] === null) {
entityData[p] = defaultConfig[p];
}
}
// remove any undefined values or null values ( should not be necessary at this stage ) ( more tests )
for (let p in entityData) {
if (typeof entityData[p] === 'undefined' || entityData[p] === null) {
delete entityData[p];
}
}
}

function updateOrCreate(game, entityData) {
// After handling potential source conflicts, proceed to create or update the entity
let localEntity = game.entities.get(entityData.id);
if (!localEntity) {
// If it's a new entity or a remote entity not seen before, create it
// console.log("createEntity LOCAL", entityData);
//console.log("createEntity LOCAL", entityData);
return game.createEntity(entityData);
} else {
//console.log("updateEntity LOCAL", entityData);
Expand Down
4 changes: 3 additions & 1 deletion mantra-game/plugins/entity/lib/util/ensureColorInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export default function ensureColorInt(color) {
const colorNameToHex = {
red: '#FF0000',
green: '#00FF00',
blue: '#fff007',
blue: '#0000FF',
black: '#000000',
white: '#FFFFFF',
yellow: '#FFFF00',
purple: '#800080',
orange: '#FFA500',
pink: '#FFC0CB',
indigo: '#4B0082',
violet: '#EE82EE',
// Add more common colors as needed
};

Expand Down

0 comments on commit db1872a

Please sign in to comment.