chore: http -> web

This commit is contained in:
cha0s 2022-03-22 20:43:16 -05:00
parent 50cca7bb9f
commit 5a1f85ecd9
34 changed files with 48 additions and 48 deletions

View File

@ -99,7 +99,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
this.#daemons = Object.values(await this.constructor.loadScripts(daemons, this.#context));
this.#routines = await this.constructor.loadScripts(this.params.routines, this.#context);
this.updateCurrentRoutine(this.state.currentRoutine);
super.isBehaving = 'http' !== process.env.FLECKS_CORE_BUILD_TARGET;
super.isBehaving = 'web' !== process.env.FLECKS_CORE_BUILD_TARGET;
}
methods() {

View File

@ -37,7 +37,7 @@ export default (Trait, flecks) => class DialogInitiator extends Trait {
...super.methods(),
openDialog: async (text) => {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const {Entity} = flecks.get('$avocado/resource.resources');
if (!this.entity.list) {
return;

View File

@ -36,7 +36,7 @@ export default (flecks) => {
async load(json) {
await super.load(json);
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.entity.node.className = 'dialog';
const {text} = this.entity;
if (text) {
@ -81,7 +81,7 @@ export default (flecks) => {
}
tick(elapsed) {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#nextLetter -= elapsed;
if (this.#nextLetter <= 0) {
this.#thisLetter += 1;

View File

@ -51,7 +51,7 @@ export default (flecks) => {
entity.emit('addedToList');
entity.once('destroying', () => this.onEntityDestroying(entity));
this.emit('entityAdded', entity);
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#informedEntities.set(entity, []);
}
this.startSynchronizing(entity);
@ -158,7 +158,7 @@ export default (flecks) => {
return;
}
this.stopSynchronizing(entity);
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#informedEntities.delete(entity);
}
// eslint-disable-next-line no-param-reassign

View File

@ -15,7 +15,7 @@ import hotEntities from '../hot-entities';
const debug = D('@avocado/entity');
let numericUid = 'http' !== process.env.FLECKS_CORE_BUILD_TARGET ? 1 : 1000000000;
let numericUid = 'web' !== process.env.FLECKS_CORE_BUILD_TARGET ? 1 : 1000000000;
export default (flecks) => {
const decorate = compose(

View File

@ -42,7 +42,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
static defaultParams() {
return {
deathCheck: 'return entity.life <= 0',
deathScript: `if ('http' === FLECKS_CORE_BUILD_TARGET) {
deathScript: `if ('web' === FLECKS_CORE_BUILD_TARGET) {
await TickingPromise.all([
entity.playSound("deathSound"),
entity.transition(
@ -159,7 +159,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
}
tick() {
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if (!this.#isDying) {
this.#deathCheck.evaluate(({value: died}) => {
if (died) {

View File

@ -90,7 +90,7 @@ export default () => class DomNode extends decorate(Trait) {
async load(json) {
await super.load(json);
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.entity.node = window.document.createElement('entity');
Object.entries(this.params.style).forEach(([key, value]) => {
this.entity.node.style[key] = value;
@ -100,7 +100,7 @@ export default () => class DomNode extends decorate(Trait) {
}
tick() {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET && this.#scheduledRuleApplication) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET && this.#scheduledRuleApplication) {
this.#scheduledRuleApplication = false;
this.applyStyleRules();
}

View File

@ -6,7 +6,7 @@ export default () => class DomText extends Trait {
constructor() {
super();
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#text = window.document.createElement('span');
}
}

View File

@ -50,7 +50,7 @@ export default () => class Positioned extends decorate(Trait) {
this.trackedPosition = [x, y];
this.entity.position[0] = x;
this.entity.position[1] = y;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.serverPosition = this.trackedPosition;
this.serverPositionDirty = false;
}
@ -59,7 +59,7 @@ export default () => class Positioned extends decorate(Trait) {
// eslint-disable-next-line camelcase
onTrackedPositionChanged(oldPosition, newPosition) {
[this.entity.position[0], this.entity.position[1]] = newPosition;
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
[this.state.x, this.state.y] = newPosition;
this.markAsDirty();
}

View File

@ -36,7 +36,7 @@ describe('Alive', () => {
it('exists', async () => {
expect(entity.is('Alive')).to.be.true;
});
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('can die', async () => {
let isDying = false;
entity.once('startedDying', () => {
@ -53,7 +53,7 @@ describe('Alive', () => {
entity.maxLife = 50;
expect(entity.life).to.equal(50);
});
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('can have a custom death condition', async () => {
const entity = await Entity.load({
traits: {
@ -116,7 +116,7 @@ describe('Alive', () => {
expect(entity2.life).to.equal(80);
expect(entity2.maxLife).to.equal(90);
});
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('generates and accepts death packets', async () => {
entity.life = 0;
entity.tick();

View File

@ -35,7 +35,7 @@ describe('Positioned', () => {
it('exists', async () => {
expect(entity.is('Positioned')).to.be.true;
});
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('generates and accepts movement packets', async () => {
entity.setPosition([1, 1]);
const packets = entity.trait('Positioned').packetsFor();

View File

@ -13,7 +13,7 @@ export default class Canvas extends decorate(Class) {
constructor(size = [0, 0]) {
super();
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {RenderTexture, Texture} = require('@pixi/core');
this.renderTexture = RenderTexture.create();

View File

@ -12,7 +12,7 @@ export default class Container extends Renderable {
constructor() {
super();
this.$$children = [];
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {Container: PIXIContainer} = require('@pixi/display');
this.container = new PIXIContainer();

View File

@ -40,7 +40,7 @@ export default class Image extends Resource {
async load(buffer, uri) {
if (buffer) {
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
const {height, width} = imageSize(Buffer.from(buffer));
this.texture = {
height,

View File

@ -1,4 +1,4 @@
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const [
{SCALE_MODES}, {Renderer, BatchRenderer}, {settings},
] = [

View File

@ -14,7 +14,7 @@ export default class Primitives extends Renderable {
constructor() {
super();
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {Graphics} = require('@pixi/graphics');
this.primitives = new Graphics();

View File

@ -3,7 +3,7 @@ import {Vector} from '@avocado/math';
export default class Renderer {
constructor(size = [0, 0]) {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {Renderer: PIXIRenderer} = require('@pixi/core');
this.renderer = new PIXIRenderer({

View File

@ -5,7 +5,7 @@ export default class Sprite extends Renderable {
constructor(image) {
super();
this.$$image = image;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {Sprite: PIXISprite} = require('@pixi/sprite');
this.sprite = new PIXISprite(image.texture);

View File

@ -6,7 +6,7 @@ export default class Text extends Renderable {
constructor(text, style) {
super();
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
// eslint-disable-next-line global-require
const {Text: PIXIText} = require('@pixi/text');
const pixiText = new PIXIText(text, style);

View File

@ -18,7 +18,7 @@ export default (flecks) => {
constructor() {
super();
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#container = new Container();
this.#container.on('parentChanged', this.onParentChanged, this);
}
@ -91,7 +91,7 @@ export default (flecks) => {
async load(json) {
await super.load(json);
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
if (this.#container) {
this.#container.alpha = this.entity.opacity;
this.#container.rotation = this.entity.rotation;

View File

@ -46,7 +46,7 @@ export default class InputNormalizer extends decorate(Class) {
if (this.target) {
return;
}
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
Gamepads.start();
Gamepads.addEventListener('connect', this.onGamepadConnect);
Gamepads.addEventListener('disconnect', this.onGamepadDisconnect);

View File

@ -62,7 +62,7 @@ export default () => class Controllable extends decorate(Trait) {
.invokeHookFlat('acceptAction', actionStream[i])
.every((result) => false !== result)
) {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#queued.push(actionStream[i]);
}
}
@ -83,7 +83,7 @@ export default () => class Controllable extends decorate(Trait) {
}
tick() {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const drained = this.#actionRegistry.drain();
this.entity.acceptActionStream(drained);
}

View File

@ -16,7 +16,7 @@ export default () => class Initiator extends Trait {
constructor() {
super();
this.#ticker.on('tick', this.determineTarget, this);
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#adjustmentThrobber = {brightness: 1.5};
this.#adjustmentThrobber.lfo = new LfoResult(
this.#adjustmentThrobber,
@ -93,7 +93,7 @@ export default () => class Initiator extends Trait {
return {
acceptAction: ({action, value}) => {
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('Interact' === action && value) {
if (this.#target) {
this.#target.interact(this.entity);
@ -109,7 +109,7 @@ export default () => class Initiator extends Trait {
targetChanged(oldTarget) {
oldTarget?.container?.removeFilter('interactive', 'adjustment');
oldTarget?.container?.removeFilter('interactive', 'glow');
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#adjustmentThrobber.lfo.properties.brightness.location = 0;
this.#adjustmentThrobber.lfo.tick(0);
this.#glowThrobber.lfo.properties.outerStrength.location = 0;

View File

@ -235,7 +235,7 @@ export default (flecks) => class Collider extends decorate(Trait) {
}
tick() {
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.checkActiveCollision();
}
}

View File

@ -187,7 +187,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
},
json,
);
if (transmit && 'http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if (transmit && 'web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#emitting.push(augmentedJson);
this.markAsDirty();
}

View File

@ -27,7 +27,7 @@ export default () => class Physical extends decorate(Trait) {
body.setCollisionForEntity(this.entity);
world.addBody(body);
this.#body = body;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
if (this.entity.is('Visible') && this.params.isDebugging) {
this.#bodyView = new BodyView(body);
this.#bodyView.position = Vector.scale(this.entity.position, -1);

View File

@ -38,7 +38,7 @@ export default () => class Shaped extends decorate(Trait) {
return {
traitAdded: () => {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
if (this.entity.is('Visible') && this.params.isDebugging) {
if (!this.#shapeView) {
this.#shapeView = new ShapeView(this.entity.shape);

View File

@ -2,7 +2,7 @@ export const bufferify = (value) => Buffer.from(JSON.stringify(value));
export const parse = (buffer) => {
let string;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const decoder = new TextDecoder();
string = decoder.decode(buffer);
}

View File

@ -54,7 +54,7 @@ export default class Resource extends decorate(Class) {
}
try {
let resource;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const response = await window.fetch(join('/', this.root, uri));
if (!response.ok) {
throw new Error('Not found');

View File

@ -1,4 +1,4 @@
import Client from './client';
import Server from './server';
export default process.env.FLECKS_CORE_BUILD_TARGET === 'http' ? Client : Server;
export default process.env.FLECKS_CORE_BUILD_TARGET === 'web' ? Client : Server;

View File

@ -45,7 +45,7 @@ const pull = () => {
setTimeout(pull, Math.max(20, hmi + hmi * (Math.random() - 0.5)));
};
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
setTimeout(pull, MAX_INTERVAL);
}
@ -57,7 +57,7 @@ export default class Sound extends JsonResource {
await super.load(json);
const {volume = 1} = json;
const src = json.src || json.uri.replace('.sound.json', '.wav');
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#audio = new FakeAudio();
return;
}
@ -91,7 +91,7 @@ export default class Sound extends JsonResource {
}
play() {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
play(this.#audio, this.uri);
}
}

View File

@ -88,7 +88,7 @@ export default () => class Audible extends Trait {
// eslint-disable-next-line no-empty
catch (error) {}
}
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
Promise.resolve(this.#sounds[key]).then((sound) => {
debug('Playing %s', key);
sound.play();

View File

@ -9,7 +9,7 @@ export default class AnimationView extends Container {
constructor(animation) {
super();
this.animation = animation;
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
if (this.animation.imageUri) {
Image.load(this.animation.imageUri).then((image) => {
this.sprite = new Sprite(image);

View File

@ -209,7 +209,7 @@ export default (flecks) => {
return;
}
this.#data[index] = tile;
if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#updates.push([[x, y], [1, 1], [tile]]);
this.#hasUpdates = true;
}
@ -268,7 +268,7 @@ export default (flecks) => {
sx -= w;
sy += 1;
}
if (isDirty && 'http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if (isDirty && 'web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#updates.push([[x, y], [w, h], tiles]);
this.#hasUpdates = true;
}