chore: 3.0.0

This commit is contained in:
cha0s 2022-03-11 05:08:59 -06:00
parent c7f4039836
commit c9d3f6f8e6
321 changed files with 7796 additions and 232569 deletions

2
.gitignore vendored
View File

@ -114,3 +114,5 @@ dist
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
/packages/*/yarn.lock

View File

@ -1,8 +0,0 @@
**/*.js
**/*.map
/assets
!/.*
!/postcss.config.js
!/webpack.config.js
!src/**/*.js
!/test/**/*.js

View File

@ -1,21 +0,0 @@
{
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "latus-build",
"clean": "latus-build clean",
"fp": "latus-build forcepublish",
"lint": "latus-build lint",
"test": "latus-build test"
},
"files": [
"index.js",
"index.js.map",
"test.js",
"test.js.map"
],
"dependencies": {},
"devDependencies": {
"@latus/build": "1.x"
}
}

View File

@ -1,5 +0,0 @@
import {expect} from 'chai';
it('exists', () => {
expect(true).to.be.true;
});

View File

@ -2,5 +2,5 @@
"packages": [ "packages": [
"packages/*" "packages/*"
], ],
"version": "1.0.0" "version": "3.0.0"
} }

View File

@ -1,37 +0,0 @@
const {execSync} = require('child_process');
const {join} = require('path');
const fs = require('fs-extra')
const cwd = process.cwd();
const [exe, script, package] = process.argv;
const path = join(cwd, 'packages', package);
try {
fs.accessSync(path);
console.error(`Package '${package}' already exists, aborting.`);
process.exit(1);
}
catch (error) {}
const [scope] = require('./package.json').name.split('/');
const name = [scope, package].join('/');
console.log(`Copying new project '${name}' to ${path}...`);
fs.copySync(
join(cwd, 'config/package'),
path,
);
const json = {
...require(join(path, 'package.json')),
name,
};
fs.writeFileSync(
join(path, 'package.json'),
JSON.stringify(json, null, 2),
);
const exec = (cmd) => execSync(cmd, {cwd: path, stdio: 'inherit'});
console.log(`Installing...`);
exec('yarn');
console.log(`Testing...`);
exec('yarn run test');

View File

@ -1,19 +1,24 @@
{ {
"name": "@avocado/monorepo", "name": "@avocado/monorepo",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git"
},
"private": true, "private": true,
"scripts": { "scripts": {
"build": "lerna run build", "build": "FLECKS_ENV_FLECKS_SERVER_start=0 npm run build:only",
"clean": "lerna run clean --concurrency=1", "build:only": "flecks build",
"dev": "lerna run dev", "debug": "DEBUG=*,-babel* npm run dev",
"fp": "lerna run fp", "dev": "npm run -- build:only -hv",
"lint": "lerna run lint", "link-all": "yarn link $(for i in $(ls node_modules/@flecks); do echo -n \"@flecks/$i \"; done)",
"package": "node ./package.js", "postinstall": "patch-package",
"refresh": "yarn run clean && npx lerna exec link-all && yarn run build && yarn run test", "repl": "npx flecks repl --rlwrap",
"test": "lerna run test --no-bail -- --silent", "start": "DEBUG=@flecks*,honeybee,-@flecks/core/flecks* npm run dev",
"watch": "lerna run watch --parallel" "unlink-all": "yarn unlink $(for i in $(ls node_modules/@flecks); do echo -n \"@flecks/$i \"; done) && yarn install --force",
"up": "yarn add $(for i in $(ls node_modules/@flecks); do echo -n \"@flecks/$i \"; done)"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x", "@flecks/create-fleck": "^1.3.0",
"lerna": "^3.22.1" "lerna": "^3.22.1"
} }
} }

View File

@ -1,8 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!/postcss.config.js yarn-debug.log*
!/webpack.config.js yarn-error.log*
!src/**/*.js lerna-debug.log*
!/test/**/*.js
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -0,0 +1,6 @@
'@flecks/core': {}
'@flecks/fleck': {}
'@flecks/http': {}
'@flecks/http/server':
build: false
'@flecks/react': {}

View File

@ -1,28 +1,38 @@
{ {
"version": "1.0.0", "name": "@avocado/behavior-persea",
"version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/behavior-persea"
},
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/math-persea": "^1.0.0", "@avocado/math-persea": "^3.0.0",
"@avocado/react": "^1.0.0", "@avocado/react": "^3.0.0",
"@avocado/resource-persea": "^1.0.0", "@avocado/resource-persea": "^3.0.0",
"@latus/react": "^2.0.0", "@flecks/core": "^1.3.0",
"@flecks/react": "^1.3.0",
"natsort": "^2.0.2" "natsort": "^2.0.2"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0",
}, "@flecks/http": "^1.3.0"
"name": "@avocado/behavior-persea" }
} }

View File

@ -5,7 +5,7 @@ import {useJsonPatcher} from '@avocado/resource-persea';
import { import {
PropTypes, PropTypes,
React, React,
} from '@latus/react'; } from '@flecks/react';
const ScriptComponent = ({path, resource}) => { const ScriptComponent = ({path, resource}) => {
const patch = useJsonPatcher(); const patch = useJsonPatcher();

View File

@ -1,4 +1,4 @@
import {gatherComponents} from '@latus/react'; import {Flecks, Hooks} from '@flecks/core';
import ScriptController from './controllers/script'; import ScriptController from './controllers/script';
@ -7,12 +7,13 @@ export {
}; };
export default { export default {
hooks: { [Hooks]: {
'@avocado/resource-persea/controllers': () => [ '@avocado/resource-persea.controllers': () => [
ScriptController, ScriptController,
], ],
'@avocado/traits-persea/components': gatherComponents( '@avocado/traits-persea.components': Flecks.provide(
require.context('./traits', false, /\.jsx$/), require.context('./traits', false, /\.jsx$/),
{invoke: false},
), ),
}, },
}; };

View File

@ -11,7 +11,7 @@ import {
Tabs, Tabs,
TabList, TabList,
TabPanel, TabPanel,
} from '@latus/react'; } from '@flecks/react';
import {Code} from '@avocado/react'; import {Code} from '@avocado/react';
const Behaved = ({ const Behaved = ({

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,32 +1,40 @@
{ {
"name": "@avocado/behavior", "name": "@avocado/behavior",
"version": "2.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/behavior"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/core": "2.0.0", "@avocado/core": "^3.0.0",
"@avocado/resource": "^2.0.0", "@avocado/resource": "^3.0.0",
"@avocado/sandbox": "^1.0.0", "@avocado/traits": "^3.0.0",
"@avocado/traits": "^2.0.0",
"@babel/parser": "^7.13.13", "@babel/parser": "^7.13.13",
"@latus/core": "2.0.0", "@flecks/core": "^1.3.0",
"babeler": "^1.0.0",
"lru-cache": "^6.0.0" "lru-cache": "^6.0.0"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0"
} }
} }

View File

@ -1,9 +1,9 @@
import {TickingPromise} from '@avocado/core'; import {TickingPromise} from '@avocado/core';
export default (latus) => ({ export default (flecks) => ({
console, console,
latus, flecks,
SIDE: process.env.SIDE, FLECKS_CORE_BUILD_TARGET: process.env.FLECKS_CORE_BUILD_TARGET,
TickingPromise, TickingPromise,
wait: (duration) => new TickingPromise( wait: (duration) => new TickingPromise(
(resolve) => { (resolve) => {

View File

@ -1,37 +1,14 @@
import {gatherWithLatus} from '@latus/core'; import {Flecks, Hooks} from '@flecks/core';
import globals from './globals'; import globals from './globals';
export default { export default {
hooks: { [Hooks]: {
'@avocado/behavior/globals': globals, '@avocado/behavior.globals': globals,
'@avocado/resource/resources': gatherWithLatus( '@avocado/resource.resources': Flecks.provide(require.context('./resources', false, /\.js$/)),
require.context('./resources', false, /\.js$/), '@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
), '@flecks/core.starting': async (flecks) => {
'@avocado/traits/traits': gatherWithLatus( flecks.set('$avocado/behavior.globals', flecks.invokeMerge('@avocado/behavior.globals'));
require.context('./traits', false, /\.js$/),
),
'@latus/core/starting': async (latus) => {
latus.set('%behaviorCompilers', latus.invokeReduce('@avocado/behavior/compilers'));
latus.set('%behaviorGlobals', latus.invokeReduce('@avocado/behavior/globals'));
const types = (await latus.invokeOrdered('@avocado/behavior/types'))
.reduce((r, types) => ({...r, ...types}), {});
latus.set(
'%behavior-types',
latus.invokeComposed('@avocado/behavior/types.decorate', types),
);
}, },
'@latus/core/config': () => ({
types: [
'@avocado/math',
'@avocado/entity',
'@avocado/timing',
// ...
'@avocado/behavior',
],
'types.decorate': [
'@avocado/timing',
],
}),
}, },
}; };

View File

@ -1,10 +1,12 @@
import {TickingPromise} from '@avocado/core'; import {TickingPromise} from '@avocado/core';
import {Resource} from '@avocado/resource'; import {Resource} from '@avocado/resource';
import {Sandbox} from '@avocado/sandbox';
import {parse} from '@babel/parser'; import {parse} from '@babel/parser';
import {compose, EventEmitter} from '@latus/core'; import {compose, EventEmitter} from '@flecks/core';
import {Sandbox} from 'babeler';
import LRU from 'lru-cache'; import LRU from 'lru-cache';
const Populated = Symbol.for('@avocado/behavior.populated');
const cache = 'production' === process.env.NODE_ENV const cache = 'production' === process.env.NODE_ENV
? new LRU({ ? new LRU({
max: 128, max: 128,
@ -25,7 +27,7 @@ const empty = {
}, },
}; };
export default (latus) => { export default (flecks) => {
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,
); );
@ -47,12 +49,12 @@ export default (latus) => {
} }
static createContext(locals = {}) { static createContext(locals = {}) {
if (locals.__populated) { if (locals[Populated]) {
return locals; return locals;
} }
return { return {
__populated: true, [Populated]: true,
...latus.get('%behaviorGlobals'), ...flecks.get('$avocado/behavior.globals'),
...locals, ...locals,
}; };
} }

View File

@ -1,3 +0,0 @@
import {Sandbox} from '@avocado/sandbox';

View File

@ -1,6 +1,6 @@
import {mapValuesAsync} from '@avocado/core'; import {mapValuesAsync} from '@avocado/core';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
StateProperty('activeCollective'), StateProperty('activeCollective'),
@ -12,7 +12,7 @@ const decorate = compose(
const STATIC_INTERVAL = 0.25; const STATIC_INTERVAL = 0.25;
export default (latus) => class Behaved extends decorate(Trait) { export default (flecks) => class Behaved extends decorate(Trait) {
#accumulator = 0; #accumulator = 0;
@ -31,7 +31,7 @@ export default (latus) => class Behaved extends decorate(Trait) {
({ ({
currentRoutine: this.#currentRoutine, currentRoutine: this.#currentRoutine,
} = this.constructor.defaultState()); } = this.constructor.defaultState());
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
this.#context = Script.createContext(); this.#context = Script.createContext();
} }
@ -134,7 +134,7 @@ export default (latus) => class Behaved extends decorate(Trait) {
static async loadScripts(scripts, context) { static async loadScripts(scripts, context) {
return mapValuesAsync(scripts, async (codeOrUri) => { return mapValuesAsync(scripts, async (codeOrUri) => {
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
const script = await Script.load(codeOrUri); const script = await Script.load(codeOrUri);
script.context = context; script.context = context;
return script; return script;
@ -143,7 +143,7 @@ export default (latus) => class Behaved extends decorate(Trait) {
async load(json) { async load(json) {
await super.load(json); await super.load(json);
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
this.#context = Script.createContext({ this.#context = Script.createContext({
entity: this.entity, entity: this.entity,
}); });
@ -154,7 +154,7 @@ export default (latus) => class Behaved extends decorate(Trait) {
this.#daemons = Object.values(await this.constructor.loadScripts(daemons, this.#context)); this.#daemons = Object.values(await this.constructor.loadScripts(daemons, this.#context));
this.#routines = await this.constructor.loadScripts(this.params.routines, this.#context); this.#routines = await this.constructor.loadScripts(this.params.routines, this.#context);
this.updateCurrentRoutine(this.state.currentRoutine); this.updateCurrentRoutine(this.state.currentRoutine);
super.isBehaving = 'client' !== process.env.SIDE; super.isBehaving = 'http' !== process.env.FLECKS_CORE_BUILD_TARGET;
} }
methods() { methods() {

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,29 +1,36 @@
{ {
"name": "@avocado/color", "name": "@avocado/color",
"version": "1.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/color"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/traits": "^2.0.0", "@flecks/core": "^1.3.0",
"@latus/core": "^2.0.0",
"lodash.get": "^4.4.2", "lodash.get": "^4.4.2",
"lodash.set": "^4.3.2" "lodash.set": "^4.3.2"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0"
} }
} }

View File

@ -1,12 +1,10 @@
import {gatherWithLatus} from '@latus/core'; import {Flecks, Hooks} from '@flecks/core';
import dialogFunctions from './dialog-functions'; import dialogFunctions from './dialog-functions';
export default { export default {
hooks: { [Hooks]: {
'@avocado/dialog/functions': dialogFunctions, '@avocado/dialog.functions': dialogFunctions,
'@avocado/traits/traits': gatherWithLatus( '@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
require.context('./traits', false, /\.js$/),
),
}, },
}; };

View File

@ -1,128 +1,131 @@
import {StateProperty, Trait} from '@avocado/traits'; import {compose} from '@flecks/core';
import {compose} from '@latus/core';
import hsv2rgb from '../hsv2rgb'; import hsv2rgb from '../hsv2rgb';
import rgb2hsv from '../rgb2hsv'; import rgb2hsv from '../rgb2hsv';
const decorate = compose( export default (flecks) => {
StateProperty('red', { const {StateProperty, Trait} = flecks.fleck('@avocado/traits');
track: true,
}),
StateProperty('green', {
track: true,
}),
StateProperty('blue', {
track: true,
}),
);
export default () => class Colorized extends decorate(Trait) { const decorate = compose(
StateProperty('red', {
track: true,
}),
StateProperty('green', {
track: true,
}),
StateProperty('blue', {
track: true,
}),
);
static children() { return class Colorized extends decorate(Trait) {
return {
red: {
type: 'number',
},
green: {
type: 'number',
},
blue: {
type: 'number',
},
hue: {
type: 'number',
},
saturation: {
type: 'number',
},
value: {
type: 'number',
},
};
}
get blue() { static children() {
return this.state.blue; return {
} red: {
type: 'number',
set blue(blue) { },
this.wrapRgbSet(() => { green: {
super.blue = blue; type: 'number',
}); },
} blue: {
type: 'number',
static defaultState() { },
return { hue: {
red: 0, type: 'number',
green: 0, },
blue: 0, saturation: {
}; type: 'number',
} },
value: {
get green() { type: 'number',
return this.state.green; },
} };
set green(green) {
this.wrapRgbSet(() => {
super.green = green;
});
}
get hue() {
return rgb2hsv([this.red, this.green, this.blue])[0];
}
set hue(hue) {
this.wrapHsvSet(0, hue);
}
get red() {
return this.state.red;
}
set red(red) {
this.wrapRgbSet(() => {
super.red = red;
});
}
get saturation() {
return rgb2hsv([this.red, this.green, this.blue])[1];
}
set saturation(saturation) {
this.wrapHsvSet(1, saturation);
}
get value() {
return rgb2hsv([this.red, this.green, this.blue])[2];
}
set value(value) {
this.wrapHsvSet(2, value);
}
wrapHsvSet(i, nv) {
const hsv = rgb2hsv([this.red, this.green, this.blue]);
const keys = ['hue', 'saturation', 'value'];
if (nv !== hsv[i]) {
hsv[i] = nv;
[this.red, this.green, this.blue] = hsv2rgb(hsv);
this.entity.emit(`${keys[i]}Changed`);
} }
}
wrapRgbSet(fn) { get blue() {
const o = rgb2hsv([this.red, this.green, this.blue]); return this.state.blue;
fn(); }
const n = rgb2hsv([this.red, this.green, this.blue]);
['hue', 'saturation', 'value'].forEach((key, i) => { set blue(blue) {
if (n[i] !== o[i]) { this.wrapRgbSet(() => {
this.entity.emit(`${key}Changed`); super.blue = blue;
});
}
static defaultState() {
return {
red: 0,
green: 0,
blue: 0,
};
}
get green() {
return this.state.green;
}
set green(green) {
this.wrapRgbSet(() => {
super.green = green;
});
}
get hue() {
return rgb2hsv([this.red, this.green, this.blue])[0];
}
set hue(hue) {
this.wrapHsvSet(0, hue);
}
get red() {
return this.state.red;
}
set red(red) {
this.wrapRgbSet(() => {
super.red = red;
});
}
get saturation() {
return rgb2hsv([this.red, this.green, this.blue])[1];
}
set saturation(saturation) {
this.wrapHsvSet(1, saturation);
}
get value() {
return rgb2hsv([this.red, this.green, this.blue])[2];
}
set value(value) {
this.wrapHsvSet(2, value);
}
wrapHsvSet(i, nv) {
const hsv = rgb2hsv([this.red, this.green, this.blue]);
const keys = ['hue', 'saturation', 'value'];
if (nv !== hsv[i]) {
hsv[i] = nv;
[this.red, this.green, this.blue] = hsv2rgb(hsv);
this.entity.emit(`${keys[i]}Changed`);
} }
}); }
} wrapRgbSet(fn) {
const o = rgb2hsv([this.red, this.green, this.blue]);
fn();
const n = rgb2hsv([this.red, this.green, this.blue]);
['hue', 'saturation', 'value'].forEach((key, i) => {
if (n[i] !== o[i]) {
this.entity.emit(`${key}Changed`);
}
});
}
};
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,24 +1,35 @@
{ {
"name": "@avocado/core", "name": "@avocado/core",
"version": "2.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/core"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": {}, "dependencies": {
"@flecks/core": "^1.3.0",
"chai": "4.2.0"
},
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0"
} }
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable no-underscore-dangle */
export default class TickingPromise extends Promise { export default class TickingPromise extends Promise {
constructor(executor, ticker) { constructor(executor, ticker) {

View File

@ -1,5 +0,0 @@
import {expect} from 'chai';
it('exists', () => {
expect(true).to.be.true;
});

View File

@ -9,7 +9,11 @@ describe('Property', () => {
}); });
it('dies if duplicate properties are defined', () => { it('dies if duplicate properties are defined', () => {
expect(() => { expect(() => {
Property('property')(class {property() {}}); Property('property')(class {
property() {}
});
}).to.throw(); }).to.throw();
}); });
it('accepts initializer', () => { it('accepts initializer', () => {
@ -18,14 +22,15 @@ describe('Property', () => {
initialize() { initialize() {
hasInitialized = this instanceof Class; hasInitialized = this instanceof Class;
}, },
})(class {}) {}; })(class {}) {}
// eslint-disable-next-line no-unused-vars
const object = new Class(); const object = new Class();
expect(hasInitialized).to.be.true; expect(hasInitialized).to.be.true;
}); });
it('accepts defaults', () => { it('accepts defaults', () => {
class Class extends Property('property', { class Class extends Property('property', {
default: 420, default: 420,
})(class {}) {}; })(class {}) {}
const object = new Class(); const object = new Class();
expect(object.property).to.equal(420); expect(object.property).to.equal(420);
}); });
@ -35,7 +40,7 @@ describe('Property', () => {
get() { get() {
return 420; return 420;
}, },
})(class {}) {}; })(class {}) {}
const object = new Class(); const object = new Class();
expect(object.property).to.equal(420); expect(object.property).to.equal(420);
}); });
@ -45,7 +50,7 @@ describe('Property', () => {
set(value) { set(value) {
s = value; s = value;
}, },
})(class {}) {}; })(class {}) {}
const object = new Class(); const object = new Class();
object.property = 420; object.property = 420;
expect(s).to.equal(420); expect(s).to.equal(420);
@ -55,8 +60,12 @@ describe('Property', () => {
class Class extends Property('property', { class Class extends Property('property', {
track: true, track: true,
})(class {}) { })(class {}) {
emit(type, o, v) {emitted = ('propertyChanged' === type && 420 === v)}
}; emit(type, o, v) {
emitted = ('propertyChanged' === type && 420 === v);
}
}
const object = new Class(); const object = new Class();
expect(emitted).to.be.false; expect(emitted).to.be.false;
object.property = 420; object.property = 420;
@ -69,7 +78,7 @@ describe('Property', () => {
emitted = ('propertyChanged' === type && 420 === v); emitted = ('propertyChanged' === type && 420 === v);
}, },
track: true, track: true,
})(class {}) {}; })(class {}) {}
const object = new Class(); const object = new Class();
expect(emitted).to.be.false; expect(emitted).to.be.false;
object.property = 420; object.property = 420;
@ -77,7 +86,7 @@ describe('Property', () => {
}); });
it('accepts comparator', () => { it('accepts comparator', () => {
let emitted = false; let emitted = false;
const emit = (type, o, v) => { const emit = (type) => {
emitted = ('propertyChanged' === type); emitted = ('propertyChanged' === type);
}; };
class Class extends Property('property', { class Class extends Property('property', {
@ -85,7 +94,7 @@ describe('Property', () => {
emit, emit,
eq: (l, r) => l[0] === r[0] && l[1] === r[1], eq: (l, r) => l[0] === r[0] && l[1] === r[1],
track: true, track: true,
})(class {}) {}; })(class {}) {}
const object = new Class(); const object = new Class();
expect(emitted).to.be.false; expect(emitted).to.be.false;
object.property = [0, 0]; object.property = [0, 0];

View File

@ -1,9 +1,10 @@
import {assert, expect} from 'chai'; import {assert} from 'chai';
import TickingPromise from '../src/ticking-promise'; import TickingPromise from '../src/ticking-promise';
const createTickingPromise = (duration) => new TickingPromise( const createTickingPromise = (duration) => new TickingPromise(
() => {}, () => {},
(elapsed, resolve, reject) => { (elapsed, resolve) => {
// eslint-disable-next-line no-param-reassign
duration -= elapsed; duration -= elapsed;
if (duration <= 0) { if (duration <= 0) {
resolve(); resolve();
@ -14,7 +15,7 @@ const createTickingPromise = (duration) => new TickingPromise(
describe('TickingPromise', () => { describe('TickingPromise', () => {
it('can behave as a promise', async () => { it('can behave as a promise', async () => {
try { try {
await new TickingPromise((resolve, reject) => { await new TickingPromise((resolve) => {
resolve(); resolve();
}); });
} }
@ -40,7 +41,7 @@ describe('TickingPromise', () => {
}); });
it('implements a compatible .all', async () => { it('implements a compatible .all', async () => {
await TickingPromise.all([ await TickingPromise.all([
new Promise((resolve, reject) => { new Promise((resolve) => {
resolve(); resolve();
}), }),
]); ]);

View File

@ -1,4 +1,4 @@
import {assert, expect} from 'chai'; import {expect} from 'chai';
import virtualize from '../src/virtualize'; import virtualize from '../src/virtualize';
const NoMethod = virtualize(['method'], class {}); const NoMethod = virtualize(['method'], class {});

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,26 +1,33 @@
{ {
"name": "@avocado/dialog", "name": "@avocado/dialog",
"version": "1.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/dialog"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/traits": "^2.0.0", "@avocado/entity": "^3.0.0",
"@latus/core": "^2.0.0", "@flecks/core": "^1.3.0",
"@latus/socket": "^2.0.0",
"lodash.get": "^4.4.2", "lodash.get": "^4.4.2",
"lodash.set": "^4.3.2", "lodash.set": "^4.3.2",
"remark-mdx": "2.0.0-next.8", "remark-mdx": "2.0.0-next.8",
@ -29,6 +36,6 @@
"unist-util-visit-parents": "^3.1.1" "unist-util-visit-parents": "^3.1.1"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0"
} }
} }

View File

@ -1,34 +1,31 @@
import {decorateWithLatus, gatherWithLatus} from '@latus/core'; import {Flecks, Hooks} from '@flecks/core';
import dialogFunctions from './dialog-functions'; import dialogFunctions from './dialog-functions';
import parse from './parser'; import parse from './parser';
import wordize from './wordize'; import wordize from './wordize';
export default { export default {
hooks: { [Hooks]: {
'@avocado/dialog/functions': dialogFunctions, '@avocado/dialog.functions': dialogFunctions,
'@avocado/traits/traits.decorate': decorateWithLatus( '@avocado/traits.traits.decorate': (
require.context('./traits/decorators', false, /\.js$/), Flecks.decorate(require.context('./traits/decorators', false, /\.js$/))
), ),
'@avocado/traits/traits': gatherWithLatus( '@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
require.context('./traits', false, /\.js$/), '@flecks/core.starting': (flecks) => {
), const dialogFunctions = flecks.invokeMerge('@avocado/dialog.functions');
'@latus/core/starting': (latus) => {
const dialogFunctions = latus.invokeReduce('@avocado/dialog/functions');
const resolver = (type) => (dialogFunctions[type] ? dialogFunctions[type] : (i) => i); const resolver = (type) => (dialogFunctions[type] ? dialogFunctions[type] : (i) => i);
latus.set('%dialogParser', async (text) => { flecks.set('$avocado/dialog.parser', async (text) => {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const letters = await Promise.all( const letters = await Promise.all(
parse(text, resolver).map((letter) => Entity.load({traits: letter})), parse(text, resolver)
.map((letter) => Entity.load({traits: letter})),
); );
return { return {
letters, letters,
words: await wordize(letters, latus), words: await wordize(letters, flecks),
}; };
}); });
}, },
'@latus/socket/packets': gatherWithLatus( '@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)),
require.context('./packets', false, /\.js$/),
),
}, },
}; };

View File

@ -1,11 +1,12 @@
import {Packet} from '@latus/socket'; export default (flecks) => {
const {Packet} = flecks.fleck('@flecks/socket');
return class OpenDialogPacket extends Packet {
export default () => class OpenDialogPacket extends Packet { static get data() {
return {
static get data() { text: 'string',
return { };
text: 'string', }
};
}
};
}; };

View File

@ -1,4 +1,4 @@
export default (Trait, latus) => class DialogInitiator extends Trait { export default (Trait, flecks) => class DialogInitiator extends Trait {
#open = []; #open = [];
@ -37,8 +37,8 @@ export default (Trait, latus) => class DialogInitiator extends Trait {
...super.methods(), ...super.methods(),
openDialog: async (text) => { openDialog: async (text) => {
if ('client' === process.env.SIDE) { if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
if (!this.entity.list) { if (!this.entity.list) {
return; return;
} }

View File

@ -1,16 +1,19 @@
import {StateProperty, Trait} from '@avocado/traits'; import {compose} from '@flecks/core';
import {compose} from '@latus/core';
const decorate = compose( export default (flecks) => {
StateProperty('rate'), const {StateProperty, Trait} = flecks.fleck('@avocado/traits');
);
export default () => class DialogText extends decorate(Trait) { const decorate = compose(
StateProperty('rate'),
);
static defaultState() { return class DialogText extends decorate(Trait) {
return {
rate: 0.1,
};
}
static defaultState() {
return {
rate: 0.1,
};
}
};
}; };

View File

@ -1,100 +1,101 @@
import {Trait} from '@avocado/traits'; export default (flecks) => {
const {Trait} = flecks.fleck('@avocado/traits');
return class Dialog extends Trait {
export default (latus) => class Dialog extends Trait { #dialog;
#dialog; #letters = [];
#letters = []; #nextLetter = 0;
#nextLetter = 0; #thisLetter = 0;
#thisLetter = 0; #words = [];
#words = []; static defaultParams() {
return {
rate: 0.05,
};
}
static defaultParams() { static dependencies() {
return { return [
rate: 0.05, 'Textual',
}; 'DomNode',
} ];
}
static dependencies() { // eslint-disable-next-line class-methods-use-this
return [ hooks() {
'Textual', return {
'DomNode',
];
}
// eslint-disable-next-line class-methods-use-this visibleAabbs: () => [-64, -64, 64, 64],
hooks() {
return {
visibleAabbs: () => [-64, -64, 64, 64], };
}
}; async load(json) {
} await super.load(json);
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
async load(json) { this.entity.node.className = 'dialog';
await super.load(json); const {text} = this.entity;
if ('client' === process.env.SIDE) { if (text) {
this.entity.node.className = 'dialog'; ({
const {text} = this.entity; letters: this.#letters,
if (text) { words: this.#words,
({ } = await flecks.get('$avocado/dialog.parser')(
letters: this.#letters, `<rate frequency={${this.params.rate}}>${text}</rate>`,
words: this.#words, ));
} = await latus.get('%dialogParser')( if (this.#letters.length > 0) {
`<rate frequency={${this.params.rate}}>${text}</rate>`, this.showThisLetter();
)); this.#words.forEach((word) => {
if (this.#letters.length > 0) { // eslint-disable-next-line no-param-reassign
this.showThisLetter(); word.parentNode = this.entity.node;
this.#words.forEach((word) => { });
// eslint-disable-next-line no-param-reassign }
word.parentNode = this.entity.node;
});
} }
} }
} }
}
methods() { methods() {
return { return {
skip: () => { skip: () => {
if (this.#nextLetter === Infinity) { if (this.#nextLetter === Infinity) {
this.entity.destroy(); this.entity.destroy();
return; return;
} }
for (let i = 0; i < this.#letters.length; ++i) { for (let i = 0; i < this.#letters.length; ++i) {
this.#letters[i].opacity = 1; this.#letters[i].opacity = 1;
} }
this.#nextLetter = Infinity;
},
};
}
showThisLetter() {
const letter = this.#letters[this.#thisLetter];
this.#nextLetter += letter.rate;
letter.opacity = 1;
}
tick(elapsed) {
if ('client' === process.env.SIDE) {
this.#nextLetter -= elapsed;
if (this.#nextLetter <= 0) {
this.#thisLetter += 1;
if (this.#thisLetter >= this.#letters.length) {
this.#nextLetter = Infinity; this.#nextLetter = Infinity;
return; },
};
}
showThisLetter() {
const letter = this.#letters[this.#thisLetter];
this.#nextLetter += letter.rate;
letter.opacity = 1;
}
tick(elapsed) {
if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.#nextLetter -= elapsed;
if (this.#nextLetter <= 0) {
this.#thisLetter += 1;
if (this.#thisLetter >= this.#letters.length) {
this.#nextLetter = Infinity;
return;
}
this.showThisLetter();
}
for (let i = 0; i < this.#words.length; ++i) {
this.#words[i].tick(elapsed);
} }
this.showThisLetter();
}
for (let i = 0; i < this.#words.length; ++i) {
this.#words[i].tick(elapsed);
} }
} }
}
};
}; };

View File

@ -1,5 +1,5 @@
const createWord = async (letters, latus) => { const createWord = async (letters, flecks) => {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const word = await Entity.load({ const word = await Entity.load({
traits: { traits: {
DomNode: { DomNode: {
@ -27,19 +27,19 @@ const createWord = async (letters, latus) => {
return word; return word;
}; };
export default async (letters, latus) => { export default async (letters, flecks) => {
const words = []; const words = [];
let word = []; let word = [];
for (let i = 0; i < letters.length; i++) { for (let i = 0; i < letters.length; i++) {
const {text} = letters[i]; const {text} = letters[i];
word.push(letters[i]); word.push(letters[i]);
if (text.match(/[^a-zA-Z0-9_]/)) { if (text.match(/[^a-zA-Z0-9_]/)) {
words.push(createWord(word, latus)); words.push(createWord(word, flecks));
word = []; word = [];
} }
} }
if (word.length > 0) { if (word.length > 0) {
words.push(createWord(word, latus)); words.push(createWord(word, flecks));
} }
return Promise.all(words); return Promise.all(words);
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!/postcss.config.js yarn-debug.log*
!/webpack.config.js yarn-error.log*
!src/**/*.js lerna-debug.log*
!/test/**/*.js
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -0,0 +1,6 @@
'@flecks/core': {}
'@flecks/fleck': {}
'@flecks/http': {}
'@flecks/http/server':
build: false
'@flecks/react': {}

View File

@ -1,30 +1,41 @@
{ {
"version": "1.0.0", "name": "@avocado/entity-persea",
"version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/entity-persea"
},
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/graphics": "^2.0.0", "@avocado/graphics": "^3.0.0",
"@avocado/math": "^2.0.0", "@avocado/math": "^3.0.0",
"@avocado/react": "^1.0.0", "@avocado/react": "^3.0.0",
"@avocado/resource-persea": "^1.0.0", "@avocado/resource-persea": "^3.0.0",
"@latus/react": "^2.0.0", "@flecks/core": "^1.3.0",
"@flecks/react": "^1.3.0",
"lodash.difference": "^4.5.0", "lodash.difference": "^4.5.0",
"react-autosuggest": "^10.1.0" "react-autosuggest": "^10.1.0",
"react-tabs": "^4.0.1"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0",
}, "@flecks/http": "^1.3.0"
"name": "@avocado/entity-persea" }
} }

View File

@ -10,10 +10,10 @@ import {
TabList, TabList,
TabPanel, TabPanel,
useEffect, useEffect,
useLatus, useFlecks,
useParams, useParams,
useState, useState,
} from '@latus/react'; } from '@flecks/react';
import Traits from './traits'; import Traits from './traits';
import View from './view'; import View from './view';
@ -22,9 +22,9 @@ const EntityComponent = ({
resource, resource,
path, path,
}) => { }) => {
const latus = useLatus(); const flecks = useFlecks();
const {uri} = useParams(); const {uri} = useParams();
const {Entity, EntityList} = latus.get('%resources'); const {Entity, EntityList} = flecks.get('$avocado/resource.resources');
const [entity, setEntity] = useState(); const [entity, setEntity] = useState();
useEffect(() => { useEffect(() => {
setEntity(); setEntity();

View File

@ -1,4 +1,4 @@
@import '~@latus/react/tabs.scss'; @import '~react-tabs/style/react-tabs.scss';
.entity-renderer { .entity-renderer {
height: 100%; height: 100%;

View File

@ -1,7 +1,7 @@
import {JsonController} from '@avocado/resource-persea'; import {JsonController} from '@avocado/resource-persea';
export default (buffer, latus) => { export default (buffer, flecks) => {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const json = Entity.withDefaults(JsonController.fromBuffer(buffer)); const json = Entity.withDefaults(JsonController.fromBuffer(buffer));
return { return {
...json, ...json,

View File

@ -6,7 +6,7 @@ import {
React, React,
useEffect, useEffect,
useState, useState,
} from '@latus/react'; } from '@flecks/react';
import {Stage} from '@avocado/graphics'; import {Stage} from '@avocado/graphics';

View File

@ -1,7 +1,7 @@
import {JsonController} from '@avocado/resource-persea'; import {JsonController} from '@avocado/resource-persea';
export default (resource, latus) => { export default (resource, flecks) => {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const json = Entity.withoutDefaults(resource); const json = Entity.withoutDefaults(resource);
return JsonController.toBuffer({ return JsonController.toBuffer({
...json, ...json,

View File

@ -11,10 +11,10 @@ import {
Tabs, Tabs,
TabList, TabList,
TabPanel, TabPanel,
useLatus, useFlecks,
useRef, useRef,
useState, useState,
} from '@latus/react'; } from '@flecks/react';
import difference from 'lodash.difference'; import difference from 'lodash.difference';
import Suggest from './suggest'; import Suggest from './suggest';
@ -37,7 +37,7 @@ const Traits = ({
}) => { }) => {
const patch = useJsonPatcher(); const patch = useJsonPatcher();
const buttonRef = useRef(); const buttonRef = useRef();
const latus = useLatus(); const flecks = useFlecks();
const [isSelecting, setIsSelecting] = useState(false); const [isSelecting, setIsSelecting] = useState(false);
const types = Object.keys(json).sort((l, r) => (l < r ? -1 : 1)); const types = Object.keys(json).sort((l, r) => (l < r ? -1 : 1));
const tabs = types.map((type) => ( const tabs = types.map((type) => (
@ -58,14 +58,14 @@ const Traits = ({
</button> </button>
</Tab> </Tab>
)); ));
const Traits = latus.get('%traits'); const Traits = flecks.get('$avocado/traits.traits');
const suggestible = difference( const suggestible = difference(
Object.entries(Traits) Object.entries(Traits)
.filter(([key]) => !Number.isInteger(parseInt(key, 10))) .filter(([key]) => !Number.isInteger(parseInt(key, 10)))
.map(([, {type}]) => type), .map(([, {type}]) => type),
types, types,
); );
const Components = latus.get('%trait-components'); const Components = flecks.get('$avocado/traits-persea.components');
const tabPanels = types.map((type) => { const tabPanels = types.map((type) => {
const Component = Components[type] || JsonTraitComponent; const Component = Components[type] || JsonTraitComponent;
return ( return (

View File

@ -4,7 +4,7 @@ import {
useEffect, useEffect,
useRef, useRef,
useState, useState,
} from '@latus/react'; } from '@flecks/react';
import Autosuggest from 'react-autosuggest'; import Autosuggest from 'react-autosuggest';
const Suggest = ({ const Suggest = ({

View File

@ -3,7 +3,7 @@ import './index.scss';
import { import {
PropTypes, PropTypes,
React, React,
} from '@latus/react'; } from '@flecks/react';
import EntityStage from '../stage'; import EntityStage from '../stage';

View File

@ -1,4 +1,4 @@
import {gatherComponents} from '@latus/react'; import {Flecks, Hooks} from '@flecks/react';
import EntityController from './controllers/entity'; import EntityController from './controllers/entity';
@ -7,12 +7,13 @@ export {
}; };
export default { export default {
hooks: { [Hooks]: {
'@avocado/resource-persea/controllers': () => [ '@avocado/resource-persea.controllers': () => [
EntityController, EntityController,
], ],
'@avocado/traits-persea/components': gatherComponents( '@avocado/traits-persea.components': Flecks.provide(
require.context('./traits', false, /\.jsx$/), require.context('./traits', false, /\.jsx$/),
{invoke: false},
), ),
}, },
}; };

View File

@ -6,7 +6,7 @@ import {
hot, hot,
PropTypes, PropTypes,
React, React,
} from '@latus/react'; } from '@flecks/react';
import {useJsonPatcher} from '@avocado/resource-persea'; import {useJsonPatcher} from '@avocado/resource-persea';
const Alive = ({ const Alive = ({
@ -34,6 +34,7 @@ const Alive = ({
/> />
</div> </div>
</div> </div>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label> <label>
<div>Life</div> <div>Life</div>
<div className="alive__life"> <div className="alive__life">

View File

@ -7,13 +7,14 @@ import {
hot, hot,
PropTypes, PropTypes,
React, React,
} from '@latus/react'; } from '@flecks/react';
import {useJsonPatcher} from '@avocado/resource-persea'; import {useJsonPatcher} from '@avocado/resource-persea';
const Directional = ({json, path}) => { const Directional = ({json, path}) => {
const patch = useJsonPatcher(); const patch = useJsonPatcher();
return ( return (
<div className="directional"> <div className="directional">
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label> <label>
Direction count Direction count
<select <select
@ -28,6 +29,7 @@ const Directional = ({json, path}) => {
<option value={8}>8-direction</option> <option value={8}>8-direction</option>
</select> </select>
</label> </label>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label> <label>
Track movement Track movement
{json.params.trackMovement ? '' : '?'} {json.params.trackMovement ? '' : '?'}
@ -37,6 +39,7 @@ const Directional = ({json, path}) => {
type="checkbox" type="checkbox"
/> />
</label> </label>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label> <label>
Direction Direction
<Number <Number

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,37 +1,45 @@
{ {
"name": "@avocado/entity", "name": "@avocado/entity",
"version": "2.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/entity"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/behavior": "2.0.0", "@avocado/behavior": "^3.0.0",
"@avocado/core": "2.0.0", "@avocado/core": "^3.0.0",
"@avocado/graphics": "^2.0.0", "@avocado/graphics": "^3.0.0",
"@avocado/math": "2.0.0", "@avocado/math": "^3.0.0",
"@avocado/resource": "2.0.0", "@avocado/resource": "^3.0.0",
"@avocado/s13n": "2.0.0", "@avocado/s13n": "^3.0.0",
"@avocado/traits": "^2.0.0", "@avocado/traits": "^3.0.0",
"@latus/core": "2.0.0", "@flecks/core": "^1.3.0",
"@latus/socket": "2.0.0", "@flecks/socket": "^1.3.0",
"debug": "4.3.1", "debug": "4.3.1",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",
"lodash.without": "^4.4.0" "lodash.without": "^4.4.0"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0"
} }
} }

View File

@ -1,6 +1,6 @@
export default async (latus) => { export default async (flecks) => {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const Traits = latus.get('%traits'); const Traits = flecks.get('$avocado/traits.traits');
const AllTraits = Object.fromEntries( const AllTraits = Object.fromEntries(
Object.entries(Traits) Object.entries(Traits)
.filter(([key]) => !Number.isInteger(parseInt(key, 10))), .filter(([key]) => !Number.isInteger(parseInt(key, 10))),

View File

@ -1,4 +1,4 @@
import {gatherWithLatus} from '@latus/core'; import {Flecks, Hooks} from '@flecks/core';
import hotEntities from './hot-entities'; import hotEntities from './hot-entities';
@ -6,12 +6,10 @@ export {default as EntityListView} from './entity-list-view';
export {default as fullEntity} from './full-entity'; export {default as fullEntity} from './full-entity';
export default { export default {
hooks: { [Hooks]: {
'@avocado/resource/resources': gatherWithLatus( '@avocado/resource.resources': Flecks.provide(require.context('./resources', false, /\.js$/)),
require.context('./resources', false, /\.js$/), '@flecks/core.hmr.gathered': (Class, hook) => {
), if ('@avocado/traits.traits' === hook) {
'@latus/core/gathered/hmr': (Class, hook) => {
if ('@avocado/traits/traits' === hook) {
const {type} = Class; const {type} = Class;
const it = hotEntities.values(); const it = hotEntities.values();
for (let current = it.next(); current.done !== true; current = it.next()) { for (let current = it.next(); current.done !== true; current = it.next()) {
@ -27,11 +25,7 @@ export default {
} }
} }
}, },
'@avocado/traits/traits': gatherWithLatus( '@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
require.context('./traits', false, /\.js$/), '@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)),
),
'@latus/socket/packets': gatherWithLatus(
require.context('./packets', false, /\.js$/),
),
}, },
}; };

View File

@ -1,3 +1,3 @@
import {Packet} from '@latus/socket'; import {Packet} from '@flecks/socket';
export default () => class DiedPacket extends Packet {}; export default () => class DiedPacket extends Packet {};

View File

@ -1,4 +1,4 @@
import {Packet} from '@latus/socket'; import {Packet} from '@flecks/socket';
export default () => class TraitUpdateAlivePacket extends Packet { export default () => class TraitUpdateAlivePacket extends Packet {

View File

@ -1,4 +1,4 @@
import {Packet} from '@latus/socket'; import {Packet} from '@flecks/socket';
export default () => class TraitUpdateDirectionalDirectionPacket extends Packet { export default () => class TraitUpdateDirectionalDirectionPacket extends Packet {

View File

@ -1,4 +1,4 @@
import {Packet} from '@latus/socket'; import {Packet} from '@flecks/socket';
export default () => class TraitUpdateMobilePacket extends Packet { export default () => class TraitUpdateMobilePacket extends Packet {

View File

@ -1,6 +1,6 @@
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
import {Packet} from '@latus/socket'; import {Packet} from '@flecks/socket';
const decorate = compose( const decorate = compose(
Vector.Packer(), Vector.Packer(),

View File

@ -1,12 +1,12 @@
import {compose, EventEmitter} from '@latus/core'; import {compose, EventEmitter} from '@flecks/core';
import {QuadTree, Rectangle} from '@avocado/math'; import {QuadTree, Rectangle} from '@avocado/math';
import {JsonResource} from '@avocado/resource'; import {JsonResource} from '@avocado/resource';
import {Synchronized} from '@avocado/s13n'; import {Synchronized} from '@avocado/s13n';
export default (latus) => { export default (flecks) => {
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,
Synchronized(latus), Synchronized(flecks),
); );
return class EntityList extends decorate(JsonResource) { return class EntityList extends decorate(JsonResource) {
@ -26,7 +26,7 @@ export default (latus) => {
await super.acceptPacket(packet); await super.acceptPacket(packet);
const {s13nType} = packet; const {s13nType} = packet;
if ('create' === s13nType) { if ('create' === s13nType) {
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const {id} = packet.data.synchronized; const {id} = packet.data.synchronized;
const entity = this.synchronized(Entity.resourceId, id); const entity = this.synchronized(Entity.resourceId, id);
if (entity) { if (entity) {
@ -51,7 +51,7 @@ export default (latus) => {
entity.emit('addedToList'); entity.emit('addedToList');
entity.once('destroying', () => this.onEntityDestroying(entity)); entity.once('destroying', () => this.onEntityDestroying(entity));
this.emit('entityAdded', entity); this.emit('entityAdded', entity);
if ('client' !== process.env.SIDE) { if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#informedEntities.set(entity, []); this.#informedEntities.set(entity, []);
} }
this.startSynchronizing(entity); this.startSynchronizing(entity);
@ -86,7 +86,7 @@ export default (latus) => {
return; return;
} }
await this.destroyEntities(); await this.destroyEntities();
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity))); const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity)));
for (let i = 0; i < entityInstances.length; i++) { for (let i = 0; i < entityInstances.length; i++) {
this.addEntity(entityInstances[i]); this.addEntity(entityInstances[i]);
@ -106,7 +106,7 @@ export default (latus) => {
packetsFor(informed) { packetsFor(informed) {
const packets = []; const packets = [];
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
// Visible entities. // Visible entities.
const {areaToInform} = informed; const {areaToInform} = informed;
const previousVisibleEntities = this.#informedEntities.get(informed); const previousVisibleEntities = this.#informedEntities.get(informed);
@ -158,7 +158,7 @@ export default (latus) => {
return; return;
} }
this.stopSynchronizing(entity); this.stopSynchronizing(entity);
if ('client' !== process.env.SIDE) { if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
this.#informedEntities.delete(entity); this.#informedEntities.delete(entity);
} }
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign

View File

@ -7,7 +7,7 @@ import {
TickingPromise, TickingPromise,
} from '@avocado/core'; } from '@avocado/core';
import {Synchronized} from '@avocado/s13n'; import {Synchronized} from '@avocado/s13n';
import {compose, EventEmitter} from '@latus/core'; import {compose, EventEmitter} from '@flecks/core';
import {JsonResource} from '@avocado/resource'; import {JsonResource} from '@avocado/resource';
import {defineTraitAccessors, enumerateTraitAccessorKeys} from '../accessors'; import {defineTraitAccessors, enumerateTraitAccessorKeys} from '../accessors';
@ -15,12 +15,12 @@ import hotEntities from '../hot-entities';
const debug = D('@avocado/entity'); const debug = D('@avocado/entity');
let numericUid = 'client' !== process.env.SIDE ? 1 : 1000000000; let numericUid = 'http' !== process.env.FLECKS_CORE_BUILD_TARGET ? 1 : 1000000000;
export default (latus) => { export default (flecks) => {
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,
Synchronized(latus), Synchronized(flecks),
); );
return class Entity extends decorate(JsonResource) { return class Entity extends decorate(JsonResource) {
@ -75,8 +75,8 @@ export default (latus) => {
}); });
} }
async _addTrait(type, json = {}) { async $$addTrait(type, json = {}) {
const {[type]: Trait} = latus.get('%traits'); const {[type]: Trait} = flecks.get('$avocado/traits.traits');
if (!Trait) { if (!Trait) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(`Tried to add trait "${type}" which isn't registered!`); console.error(`Tried to add trait "${type}" which isn't registered!`);
@ -152,7 +152,7 @@ export default (latus) => {
} }
async addTraits(traits) { async addTraits(traits) {
const Traits = latus.get('%traits'); const Traits = flecks.get('$avocado/traits.traits');
const reorganized = {}; const reorganized = {};
const add = (type) => { const add = (type) => {
const deps = Traits[type]?.dependencies() || []; const deps = Traits[type]?.dependencies() || [];
@ -173,7 +173,7 @@ export default (latus) => {
for (let i = 0; i < entries.length; i++) { for (let i = 0; i < entries.length; i++) {
const [type, json] = entries[i]; const [type, json] = entries[i];
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
instances[type] = await this._addTrait(type, json); instances[type] = await this.$$addTrait(type, json);
} }
return instances; return instances;
} }
@ -194,7 +194,7 @@ export default (latus) => {
} }
createContext(locals = {}) { createContext(locals = {}) {
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
return Script.createContext({ return Script.createContext({
...this.contextOrDefault, ...this.contextOrDefault,
...locals, ...locals,
@ -321,7 +321,7 @@ export default (latus) => {
const implementation = this.#hooks[hook].find(({type: hookType}) => hookType === type); const implementation = this.#hooks[hook].find(({type: hookType}) => hookType === type);
this.#hooks[hook].splice(this.#hooks[hook].indexOf(implementation), 1); this.#hooks[hook].splice(this.#hooks[hook].indexOf(implementation), 1);
} }
const {[type]: Trait} = latus.get('%traits'); const {[type]: Trait} = flecks.get('$avocado/traits.traits');
const properties = enumerateTraitAccessorKeys(Trait.prototype); const properties = enumerateTraitAccessorKeys(Trait.prototype);
for (let i = 0; i < properties.length; ++i) { for (let i = 0; i < properties.length; ++i) {
const property = properties[i]; const property = properties[i];
@ -416,7 +416,7 @@ export default (latus) => {
} }
static withDefaults(json = {}) { static withDefaults(json = {}) {
const Traits = latus.get('%traits'); const Traits = flecks.get('$avocado/traits.traits');
return { return {
...json, ...json,
traits: Object.entries(json.traits) traits: Object.entries(json.traits)
@ -430,7 +430,7 @@ export default (latus) => {
} }
static withoutDefaults(json) { static withoutDefaults(json) {
const Traits = latus.get('%traits'); const Traits = flecks.get('$avocado/traits.traits');
const without = { const without = {
...json, ...json,
traits: Object.entries(json.traits) traits: Object.entries(json.traits)

View File

@ -1,6 +1,6 @@
import {TickingPromise} from '@avocado/core'; import {TickingPromise} from '@avocado/core';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
StateProperty('life', { StateProperty('life', {
@ -11,7 +11,7 @@ const decorate = compose(
}), }),
); );
export default (latus) => class Alive extends decorate(Trait) { export default (flecks) => class Alive extends decorate(Trait) {
#deathCheck; #deathCheck;
@ -42,7 +42,7 @@ export default (latus) => class Alive extends decorate(Trait) {
static defaultParams() { static defaultParams() {
return { return {
deathCheck: 'return entity.life <= 0', deathCheck: 'return entity.life <= 0',
deathScript: `if ('client' === SIDE) { deathScript: `if ('http' === FLECKS_CORE_BUILD_TARGET) {
await TickingPromise.all([ await TickingPromise.all([
entity.playSound("deathSound"), entity.playSound("deathSound"),
entity.transition( entity.transition(
@ -68,7 +68,7 @@ export default (latus) => class Alive extends decorate(Trait) {
async die() { async die() {
this.entity.emit('startedDying'); this.entity.emit('startedDying');
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
const deathScript = await Script.load(this.params.deathScript, this.entity.contextOrDefault); const deathScript = await Script.load(this.params.deathScript, this.entity.contextOrDefault);
await this.entity.addTickingPromise(deathScript.tickingPromise()); await this.entity.addTickingPromise(deathScript.tickingPromise());
const died = this.entity.invokeHookFlat('died'); const died = this.entity.invokeHookFlat('died');
@ -117,7 +117,7 @@ export default (latus) => class Alive extends decorate(Trait) {
async load(json) { async load(json) {
await super.load(json); await super.load(json);
const {Script} = latus.get('%resources'); const {Script} = flecks.get('$avocado/resource.resources');
this.#deathCheck = await Script.load(this.params.deathCheck, this.entity.contextOrDefault); this.#deathCheck = await Script.load(this.params.deathCheck, this.entity.contextOrDefault);
} }
@ -159,7 +159,7 @@ export default (latus) => class Alive extends decorate(Trait) {
} }
tick() { tick() {
if ('client' !== process.env.SIDE) { if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
if (!this.#isDying) { if (!this.#isDying) {
this.#deathCheck.evaluate(({value: died}) => { this.#deathCheck.evaluate(({value: died}) => {
if (died) { if (died) {

View File

@ -1,6 +1,6 @@
import {randomNumber, Vector} from '@avocado/math'; import {randomNumber, Vector} from '@avocado/math';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
StateProperty('direction', { StateProperty('direction', {

View File

@ -1,6 +1,6 @@
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
StateProperty('parentNode', { StateProperty('parentNode', {
@ -90,7 +90,7 @@ export default () => class DomNode extends decorate(Trait) {
async load(json) { async load(json) {
await super.load(json); await super.load(json);
if ('client' === process.env.SIDE) { if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.entity.node = window.document.createElement('entity'); this.entity.node = window.document.createElement('entity');
Object.entries(this.params.style).forEach(([key, value]) => { Object.entries(this.params.style).forEach(([key, value]) => {
this.entity.node.style[key] = value; this.entity.node.style[key] = value;
@ -100,7 +100,7 @@ export default () => class DomNode extends decorate(Trait) {
} }
tick() { tick() {
if ('client' === process.env.SIDE && this.#scheduledRuleApplication) { if ('http' === process.env.FLECKS_CORE_BUILD_TARGET && this.#scheduledRuleApplication) {
this.#scheduledRuleApplication = false; this.#scheduledRuleApplication = false;
this.applyStyleRules(); this.applyStyleRules();
} }

View File

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

View File

@ -1,7 +1,7 @@
import {TickingPromise} from '@avocado/core'; import {TickingPromise} from '@avocado/core';
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose, EventEmitter} from '@latus/core'; import {compose, EventEmitter} from '@flecks/core';
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,

View File

@ -1,5 +1,5 @@
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
StateProperty('name'), StateProperty('name'),

View File

@ -1,5 +1,5 @@
import {Trait} from '@avocado/traits'; import {Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
); );

View File

@ -1,6 +1,6 @@
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {Trait} from '@avocado/traits'; import {Trait} from '@avocado/traits';
import {compose, EventEmitter} from '@latus/core'; import {compose, EventEmitter} from '@flecks/core';
const decorate = compose( const decorate = compose(
EventEmitter, EventEmitter,
@ -88,7 +88,7 @@ export default () => class Positioned extends decorate(Trait) {
this.trackedPosition = [x, y]; this.trackedPosition = [x, y];
this.entity.position[0] = x; this.entity.position[0] = x;
this.entity.position[1] = y; this.entity.position[1] = y;
if ('client' === process.env.SIDE) { if ('http' === process.env.FLECKS_CORE_BUILD_TARGET) {
this.serverPosition = this.trackedPosition; this.serverPosition = this.trackedPosition;
this.serverPositionDirty = false; this.serverPositionDirty = false;
} }
@ -97,7 +97,7 @@ export default () => class Positioned extends decorate(Trait) {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
onTrackedPositionChanged(oldPosition, newPosition) { onTrackedPositionChanged(oldPosition, newPosition) {
[this.entity.position[0], this.entity.position[1]] = newPosition; [this.entity.position[0], this.entity.position[1]] = newPosition;
if ('client' !== process.env.SIDE) { if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
[this.state.x, this.state.y] = newPosition; [this.state.x, this.state.y] = newPosition;
this.markAsDirty(); this.markAsDirty();
} }

View File

@ -1,4 +1,4 @@
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
import {StateProperty, Trait} from '@avocado/traits'; import {StateProperty, Trait} from '@avocado/traits';
import merge from 'deepmerge'; import merge from 'deepmerge';
@ -9,7 +9,7 @@ const decorate = compose(
StateProperty('maxSpawns'), StateProperty('maxSpawns'),
); );
export default (latus) => class Spawner extends decorate(Trait) { export default (flecks) => class Spawner extends decorate(Trait) {
#children; #children;
@ -248,7 +248,7 @@ export default (latus) => class Spawner extends decorate(Trait) {
const childIndex = this.#children.length; const childIndex = this.#children.length;
this.#children.push(null); this.#children.push(null);
const list = this.destinationEntityList(); const list = this.destinationEntityList();
const {Entity} = latus.get('%resources'); const {Entity} = flecks.get('$avocado/resource.resources');
const child = await Entity.load(json); const child = await Entity.load(json);
this.#children[childIndex] = child; this.#children[childIndex] = child;
// Listen for destroy event. // Listen for destroy event.

View File

@ -1,6 +1,6 @@
import {Property} from '@avocado/core'; import {Property} from '@avocado/core';
import {Trait} from '@avocado/traits'; import {Trait} from '@avocado/traits';
import {compose} from '@latus/core'; import {compose} from '@flecks/core';
const decorate = compose( const decorate = compose(
Property('text', { Property('text', {

View File

@ -1,142 +1,142 @@
import { // import {
buildCondition, // buildCondition,
buildExpression, // buildExpression,
buildInvoke, // buildInvoke,
} from '@avocado/behavior'; // } from '@avocado/behavior';
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {normalize} from '@latus/socket'; // import {normalize} from '@flecks/socket';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/behavior': require('@avocado/behavior'), // '@avocado/behavior': require('@avocado/behavior'),
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
'@latus/socket': require('@latus/socket'), // '@flecks/socket': require('@flecks/socket'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity} = latus.get('%resources')); // ({Entity} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Alive', () => { // describe('Alive', () => {
let entity; // let entity;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Alive: {}, // Alive: {},
}, // },
}); // });
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Alive')).to.be.true; // expect(entity.is('Alive')).to.be.true;
}); // });
if ('client' !== process.env.SIDE) { // if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('can die', async () => { // it('can die', async () => {
let isDying = false; // let isDying = false;
entity.once('startedDying', () => { // entity.once('startedDying', () => {
isDying = true; // isDying = true;
}); // });
entity.life = 0; // entity.life = 0;
entity.tick(0); // entity.tick(0);
expect(isDying).to.be.true; // expect(isDying).to.be.true;
}); // });
} // }
it('clamps life', async () => { // it('clamps life', async () => {
entity.life = 120; // entity.life = 120;
expect(entity.life).to.equal(100); // expect(entity.life).to.equal(100);
entity.maxLife = 50; // entity.maxLife = 50;
expect(entity.life).to.equal(50); // expect(entity.life).to.equal(50);
}); // });
if ('client' !== process.env.SIDE) { // if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('can have a custom death condition', async () => { // it('can have a custom death condition', async () => {
const entity = await Entity.load({ // const entity = await Entity.load({
traits: { // traits: {
Alive: { // Alive: {
params: { // params: {
deathCondition: buildCondition('<=', [ // deathCondition: buildCondition('<=', [
buildExpression(['entity', 'life']), // buildExpression(['entity', 'life']),
10, // 10,
]), // ]),
}, // },
}, // },
}, // },
}); // });
let isDying = false; // let isDying = false;
entity.on('startedDying', () => { // entity.on('startedDying', () => {
isDying = true; // isDying = true;
}); // });
entity.tick(0); // entity.tick(0);
expect(isDying).to.be.false; // expect(isDying).to.be.false;
entity.life = 10; // entity.life = 10;
entity.tick(0); // entity.tick(0);
expect(isDying).to.be.true; // expect(isDying).to.be.true;
}); // });
} // }
it('runs actions on death', async () => { // it('runs actions on death', async () => {
let didActions; // let didActions;
const entity = await Entity.load({ // const entity = await Entity.load({
traits: { // traits: {
Alive: { // Alive: {
params: { // params: {
deathActions: { // deathActions: {
type: 'expressions', // type: 'expressions',
expressions: [ // expressions: [
buildInvoke(['entity', 'ded']), // buildInvoke(['entity', 'ded']),
], // ],
}, // },
}, // },
}, // },
}, // },
}); // });
entity.ded = () => { // entity.ded = () => {
didActions = true; // didActions = true;
}; // };
const handle = setInterval(() => { // const handle = setInterval(() => {
entity.tick(); // entity.tick();
}, 16.66); // }, 16.66);
await entity.die(); // await entity.die();
clearInterval(handle); // clearInterval(handle);
expect(didActions).to.be.true; // expect(didActions).to.be.true;
}); // });
describe('Packets', () => { // describe('Packets', () => {
let entity2; // let entity2;
beforeEach(async () => { // beforeEach(async () => {
entity2 = await Entity.load({ // entity2 = await Entity.load({
traits: { // traits: {
Alive: {}, // Alive: {},
}, // },
}); // });
}); // });
it('generates and accepts life packets', async () => { // it('generates and accepts life packets', async () => {
entity.life = 80; // entity.life = 80;
entity.maxLife = 90; // entity.maxLife = 90;
const packets = entity.trait('Alive').packetsFor(); // const packets = entity.trait('Alive').packetsFor();
expect(packets).to.have.lengthOf(1); // expect(packets).to.have.lengthOf(1);
expect(packets[0][0]).to.equal('TraitUpdateAlive'); // expect(packets[0][0]).to.equal('TraitUpdateAlive');
expect(packets[0][1]).to.deep.equal({life: 80, maxLife: 90}); // expect(packets[0][1]).to.deep.equal({life: 80, maxLife: 90});
entity2.trait('Alive').acceptPacket(normalize(latus, packets[0])); // entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0]));
expect(entity2.life).to.equal(80); // expect(entity2.life).to.equal(80);
expect(entity2.maxLife).to.equal(90); // expect(entity2.maxLife).to.equal(90);
}); // });
if ('client' !== process.env.SIDE) { // if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('generates and accepts death packets', async () => { // it('generates and accepts death packets', async () => {
entity.life = 0; // entity.life = 0;
entity.tick(); // entity.tick();
const packets = entity.trait('Alive').packetsFor(); // const packets = entity.trait('Alive').packetsFor();
expect(packets).to.have.lengthOf(2); // expect(packets).to.have.lengthOf(2);
expect(packets[0][0]).to.equal('Died'); // expect(packets[0][0]).to.equal('Died');
expect(packets[1][0]).to.equal('TraitUpdateAlive'); // expect(packets[1][0]).to.equal('TraitUpdateAlive');
expect(packets[1][1]).to.deep.equal({life: 0, maxLife: 100}); // expect(packets[1][1]).to.deep.equal({life: 0, maxLife: 100});
const promise = new Promise((resolve) => { // const promise = new Promise((resolve) => {
entity2.once('startedDying', resolve); // entity2.once('startedDying', resolve);
}); // });
entity2.trait('Alive').acceptPacket(normalize(latus, packets[0])); // entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0]));
entity2.trait('Alive').acceptPacket(normalize(latus, packets[1])); // entity2.trait('Alive').acceptPacket(normalize(flecks, packets[1]));
expect(entity2.life).to.equal(0); // expect(entity2.life).to.equal(0);
return promise; // return promise;
}); // });
} // }
}); // });
}); // });

View File

@ -1,58 +1,58 @@
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {normalize} from '@latus/socket'; // import {normalize} from '@flecks/socket';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
'@latus/socket': require('@latus/socket'), // '@flecks/socket': require('@flecks/socket'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity} = latus.get('%resources')); // ({Entity} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Directional', () => { // describe('Directional', () => {
let entity; // let entity;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Directional: { // Directional: {
params: { // params: {
directionCount: 4, // directionCount: 4,
}, // },
}, // },
}, // },
}); // });
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Directional')).to.be.true; // expect(entity.is('Directional')).to.be.true;
}); // });
it('tracks movement', async () => { // it('tracks movement', async () => {
entity.emit('movementRequest', [1, 0]); // entity.emit('movementRequest', [1, 0]);
expect(entity.direction).to.equal(1); // expect(entity.direction).to.equal(1);
entity.emit('movementRequest', [0, 1]); // entity.emit('movementRequest', [0, 1]);
expect(entity.direction).to.equal(2); // expect(entity.direction).to.equal(2);
entity.emit('movementRequest', [-1, 0]); // entity.emit('movementRequest', [-1, 0]);
expect(entity.direction).to.equal(3); // expect(entity.direction).to.equal(3);
entity.emit('movementRequest', [0, -1]); // entity.emit('movementRequest', [0, -1]);
expect(entity.direction).to.equal(0); // expect(entity.direction).to.equal(0);
}); // });
it('generates and accepts direction packets', async () => { // it('generates and accepts direction packets', async () => {
entity.direction = 2; // entity.direction = 2;
const packets = entity.trait('Directional').packetsFor(); // const packets = entity.trait('Directional').packetsFor();
expect(packets).to.have.lengthOf(1); // expect(packets).to.have.lengthOf(1);
expect(packets[0][0]).to.equal('TraitUpdateDirectionalDirection'); // expect(packets[0][0]).to.equal('TraitUpdateDirectionalDirection');
expect(packets[0][1]).to.equal(2); // expect(packets[0][1]).to.equal(2);
const entity2 = await Entity.load({ // const entity2 = await Entity.load({
traits: { // traits: {
Directional: {}, // Directional: {},
}, // },
}); // });
expect(entity2.direction).to.equal(0); // expect(entity2.direction).to.equal(0);
entity2.trait('Directional').acceptPacket(normalize(latus, packets[0])); // entity2.trait('Directional').acceptPacket(normalize(flecks, packets[0]));
expect(entity2.direction).to.equal(2); // expect(entity2.direction).to.equal(2);
}); // });
}); // });

View File

@ -1,93 +1,93 @@
import {Trait, traits} from '@avocado/traits'; // import {Trait, traits} from '@avocado/traits';
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity} = latus.get('%resources')); // ({Entity} = flecks.get('$avocado/resource.resources'));
}); // });
it('has sane defaults', () => { // it('has sane defaults', () => {
const entity = new Entity(); // const entity = new Entity();
expect(entity.traits).to.deep.equal({}); // expect(entity.traits).to.deep.equal({});
expect(entity.traitTypes()).to.deep.equal([]); // expect(entity.traitTypes()).to.deep.equal([]);
}); // });
it('can add and remove traits', async () => { // it('can add and remove traits', async () => {
const entity = new Entity(); // const entity = new Entity();
const TestTrait = class extends Trait { // const TestTrait = class extends Trait {
static get type() { // static get type() {
return 'TestTrait'; // return 'TestTrait';
} // }
}; // };
latus.set('%traits.TestTrait', TestTrait); // flecks.set('$avocado/traits.traits.TestTrait', TestTrait);
await entity.addTrait('TestTrait'); // await entity.addTrait('TestTrait');
expect(entity.is('TestTrait')).to.be.true; // expect(entity.is('TestTrait')).to.be.true;
entity.removeTrait('TestTrait'); // entity.removeTrait('TestTrait');
expect(entity.is('TestTrait')).to.be.false; // expect(entity.is('TestTrait')).to.be.false;
}); // });
it('can add traits asynchronously', async () => { // it('can add traits asynchronously', async () => {
const DELAY = 30; // const DELAY = 30;
class AsyncTrait extends Trait { // class AsyncTrait extends Trait {
static async extendJson(json) { // static async extendJson(json) {
const extended = await super.extendJson(json); // const extended = await super.extendJson(json);
await new Promise((resolve) => setTimeout(resolve, DELAY)); // await new Promise((resolve) => setTimeout(resolve, DELAY));
return extended; // return extended;
} // }
} // }
latus.set('%traits.Async', AsyncTrait); // flecks.set('$avocado/traits.traits.Async', AsyncTrait);
let start = Date.now(); // let start = Date.now();
const entity = await Entity.load({ // const entity = await Entity.load({
traits: { // traits: {
Async: {}, // Async: {},
}, // },
}); // });
expect(Date.now() - start).to.be.at.least(DELAY * 0.9); // expect(Date.now() - start).to.be.at.least(DELAY * 0.9);
}); // });
it('can invoke hooks', async () => { // it('can invoke hooks', async () => {
class AnotherTrait extends Trait { // class AnotherTrait extends Trait {
hooks() { // hooks() {
return { // return {
testHook: () => 69, // testHook: () => 69,
}; // };
} // }
static get type() { // static get type() {
return 'AnotherTrait'; // return 'AnotherTrait';
} // }
} // }
class YetAnotherTrait extends Trait { // class YetAnotherTrait extends Trait {
hooks() { // hooks() {
return { // return {
testHook: () => 420, // testHook: () => 420,
}; // };
} // }
static get type() { // static get type() {
return 'YetAnotherTrait'; // return 'YetAnotherTrait';
} // }
} // }
latus.set('%traits.AnotherTrait', AnotherTrait); // flecks.set('$avocado/traits.traits.AnotherTrait', AnotherTrait);
latus.set('%traits.YetAnotherTrait', YetAnotherTrait); // flecks.set('$avocado/traits.traits.YetAnotherTrait', YetAnotherTrait);
const entity = new Entity(); // const entity = new Entity();
await entity.addTrait('AnotherTrait'); // await entity.addTrait('AnotherTrait');
await entity.addTrait('YetAnotherTrait'); // await entity.addTrait('YetAnotherTrait');
expect(entity.invokeHook('testHook')).to.deep.equal({AnotherTrait: 69, YetAnotherTrait: 420}); // expect(entity.invokeHook('testHook')).to.deep.equal({AnotherTrait: 69, YetAnotherTrait: 420});
}); // });

View File

@ -1,5 +0,0 @@
import {expect} from 'chai';
it('exists', () => {
expect(true).to.be.true;
});

View File

@ -1,59 +1,59 @@
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
let EntityList; // let EntityList;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity, EntityList} = latus.get('%resources')); // ({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Mobile', () => { // describe('Mobile', () => {
let entity; // let entity;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Mobile: {}, // Mobile: {},
Positioned: {}, // Positioned: {},
}, // },
}); // });
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Mobile')).to.be.true; // expect(entity.is('Mobile')).to.be.true;
}); // });
it('can request movement', async () => { // it('can request movement', async () => {
entity.speed = 100; // entity.speed = 100;
entity.requestMovement([1, 0]); // entity.requestMovement([1, 0]);
entity.tick(1); // entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]); // expect(entity.position).to.deep.equal([100, 0]);
entity.tick(1); // entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]); // expect(entity.position).to.deep.equal([100, 0]);
entity.isMobile = false; // entity.isMobile = false;
entity.requestMovement([1, 0]); // entity.requestMovement([1, 0]);
entity.tick(1); // entity.tick(1);
expect(entity.position).to.deep.equal([100, 0]); // expect(entity.position).to.deep.equal([100, 0]);
}); // });
it('can force movement', async () => { // it('can force movement', async () => {
expect(entity.speed).to.equal(0); // expect(entity.speed).to.equal(0);
entity.forceMovement([10, 0]); // entity.forceMovement([10, 0]);
expect(entity.position).to.deep.equal([10, 0]); // expect(entity.position).to.deep.equal([10, 0]);
}); // });
it('can move for a time', async () => { // it('can move for a time', async () => {
entity.speed = 10; // entity.speed = 10;
const tickingPromise = entity.moveFor([1, 0], 1); // const tickingPromise = entity.moveFor([1, 0], 1);
entity.addTickingPromise(tickingPromise); // entity.addTickingPromise(tickingPromise);
expect(entity.position).to.deep.equal([0, 0]); // expect(entity.position).to.deep.equal([0, 0]);
entity.tick(0.25); // entity.tick(0.25);
expect(entity.position).to.deep.equal([2.5, 0]); // expect(entity.position).to.deep.equal([2.5, 0]);
entity.tick(0.25); // entity.tick(0.25);
expect(entity.position).to.deep.equal([5, 0]); // expect(entity.position).to.deep.equal([5, 0]);
entity.tick(0.5); // entity.tick(0.5);
expect(entity.position).to.deep.equal([10, 0]); // expect(entity.position).to.deep.equal([10, 0]);
return tickingPromise; // return tickingPromise;
}); // });
}); // });

View File

@ -1,44 +1,44 @@
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
let EntityList; // let EntityList;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity, EntityList} = latus.get('%resources')); // ({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Perishable', () => { // describe('Perishable', () => {
let entity; // let entity;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Perishable: { // Perishable: {
params: { // params: {
ttl: 10, // ttl: 10,
}, // },
}, // },
}, // },
}); // });
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Perishable')).to.be.true; // expect(entity.is('Perishable')).to.be.true;
}); // });
it('expires', async () => { // it('expires', async () => {
const promise = Promise.all([ // const promise = Promise.all([
new Promise((resolve) => { // new Promise((resolve) => {
entity.on('destroying', resolve); // entity.on('destroying', resolve);
}), // }),
new Promise((resolve) => { // new Promise((resolve) => {
entity.on('destroyed', resolve); // entity.on('destroyed', resolve);
}), // }),
]); // ]);
entity.tick(10); // entity.tick(10);
return promise; // return promise;
}); // });
}); // });

View File

@ -1,48 +1,48 @@
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {normalize} from '@latus/socket'; // import {normalize} from '@flecks/socket';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
let EntityList; // let EntityList;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
'@latus/socket': require('@latus/socket'), // '@flecks/socket': require('@flecks/socket'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity, EntityList} = latus.get('%resources')); // ({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Positioned', () => { // describe('Positioned', () => {
let entity; // let entity;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Positioned: {}, // Positioned: {},
}, // },
}); // });
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Positioned')).to.be.true; // expect(entity.is('Positioned')).to.be.true;
}); // });
if ('client' !== process.env.SIDE) { // if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
it('generates and accepts movement packets', async () => { // it('generates and accepts movement packets', async () => {
entity.setPosition([1, 1]); // entity.setPosition([1, 1]);
const packets = entity.trait('Positioned').packetsFor(); // const packets = entity.trait('Positioned').packetsFor();
expect(packets).to.have.lengthOf(1); // expect(packets).to.have.lengthOf(1);
expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition'); // expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition');
expect(packets[0][1]).to.deep.equal([1, 1]); // expect(packets[0][1]).to.deep.equal([1, 1]);
const entity2 = await Entity.load({ // const entity2 = await Entity.load({
traits: { // traits: {
Positioned: {}, // Positioned: {},
}, // },
}); // });
expect(entity2.position).to.deep.equal([0, 0]); // expect(entity2.position).to.deep.equal([0, 0]);
const trait = entity2.trait('Positioned'); // const trait = entity2.trait('Positioned');
trait.acceptPacket(normalize(latus, packets[0])); // trait.acceptPacket(normalize(flecks, packets[0]));
expect(trait.serverPosition).to.deep.equal([1, 1]); // expect(trait.serverPosition).to.deep.equal([1, 1]);
}); // });
} // }
}); // });

View File

@ -1,89 +1,89 @@
import {Latus} from '@latus/core'; // import {Flecks} from '@flecks/core';
import {expect} from 'chai'; // import {expect} from 'chai';
let latus; // let flecks;
let Entity; // let Entity;
let EntityList; // let EntityList;
beforeEach(async () => { // beforeEach(async () => {
latus = Latus.mock({ // flecks = Flecks.mock({
'@avocado/behavior': require('@avocado/behavior'), // '@avocado/behavior': require('@avocado/behavior'),
'@avocado/entity': require('../src'), // '@avocado/entity': require('../src'),
'@avocado/resource': require('@avocado/resource'), // '@avocado/resource': require('@avocado/resource'),
'@avocado/traits': require('@avocado/traits'), // '@avocado/traits': require('@avocado/traits'),
}); // });
await Promise.all(latus.invokeFlat('@latus/core/starting')); // await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
({Entity, EntityList} = latus.get('%resources')); // ({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
}); // });
describe('Spawner', () => { // describe('Spawner', () => {
let entity; // let entity;
let list; // let list;
beforeEach(async () => { // beforeEach(async () => {
entity = await Entity.load({ // entity = await Entity.load({
traits: { // traits: {
Spawner: { // Spawner: {
params: { // params: {
spawns: { // spawns: {
testy: { // testy: {
traits: { // traits: {
Alive: {}, // Alive: {},
Positioned: {}, // Positioned: {},
}, // },
}, // },
}, // },
}, // },
}, // },
}, // },
}); // });
list = new EntityList(); // list = new EntityList();
list.addEntity(entity); // list.addEntity(entity);
}); // });
it('exists', async () => { // it('exists', async () => {
expect(entity.is('Spawner')).to.be.true; // expect(entity.is('Spawner')).to.be.true;
}); // });
it('can spawn from key', async () => { // it('can spawn from key', async () => {
const spawned = await entity.spawn('testy'); // const spawned = await entity.spawn('testy');
expect(spawned.is('Alive')).to.be.true; // expect(spawned.is('Alive')).to.be.true;
const spawned2 = await entity.spawn('testy', { // const spawned2 = await entity.spawn('testy', {
traits: { // traits: {
Alive: { // Alive: {
state: { // state: {
life: 50, // life: 50,
}, // },
}, // },
}, // },
}); // });
expect(spawned2.life).to.equal(50); // expect(spawned2.life).to.equal(50);
const spawned3 = await entity.spawnAt('testy', [69, 420]); // const spawned3 = await entity.spawnAt('testy', [69, 420]);
expect(spawned3.position).to.deep.equal([69, 420]); // expect(spawned3.position).to.deep.equal([69, 420]);
}); // });
it('can spawn from arbitrary JSON', async () => { // it('can spawn from arbitrary JSON', async () => {
const spawned = await entity.spawnRaw({ // const spawned = await entity.spawnRaw({
traits: { // traits: {
Mobile: {}, // Mobile: {},
}, // },
}); // });
expect(spawned.is('Mobile')).to.be.true; // expect(spawned.is('Mobile')).to.be.true;
const spawned2 = await entity.spawnRawAt( // const spawned2 = await entity.spawnRawAt(
{ // {
traits: { // traits: {
Mobile: {}, // Mobile: {},
}, // },
}, // },
[311, 200], // [311, 200],
); // );
expect(spawned2.position).to.deep.equal([311, 200]); // expect(spawned2.position).to.deep.equal([311, 200]);
}); // });
it('can kill all children', async () => { // it('can kill all children', async () => {
const COUNT = 15; // const COUNT = 15;
for (let i = 0; i < COUNT; ++i) { // for (let i = 0; i < COUNT; ++i) {
await entity.spawnRaw({ // await entity.spawnRaw({
traits: { // traits: {
Mobile: {}, // Mobile: {},
}, // },
}); // });
} // }
expect(Object.keys(list.entities)).to.have.lengthOf(COUNT + 1); // expect(Object.keys(list.entities)).to.have.lengthOf(COUNT + 1);
await entity.killAllChildren(); // await entity.killAllChildren();
expect(Object.keys(list.entities)).to.have.lengthOf(1); // expect(Object.keys(list.entities)).to.have.lengthOf(1);
}); // });
}); // });

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!/postcss.config.js yarn-debug.log*
!/webpack.config.js yarn-error.log*
!src/**/*.js lerna-debug.log*
!/test/**/*.js
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -0,0 +1,6 @@
'@flecks/core': {}
'@flecks/fleck': {}
'@flecks/http': {}
'@flecks/http/server':
build: false
'@flecks/react': {}

View File

@ -1,25 +1,35 @@
{ {
"version": "1.0.0", "name": "@avocado/graphics-persea",
"version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/graphics-persea"
},
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
"src",
"test",
"test.js", "test.js",
"test.js.map" "test.js.map"
], ],
"dependencies": { "dependencies": {
"@avocado/resource-persea": "^1.0.0", "@avocado/resource-persea": "^3.0.0",
"@latus/react": "^2.0.0" "@flecks/core": "^1.3.0",
"@flecks/react": "^1.3.0"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0",
}, "@flecks/http": "^1.3.0"
"name": "@avocado/graphics-persea" }
} }

View File

@ -5,7 +5,7 @@ import './component.scss';
import { import {
PropTypes, PropTypes,
React, React,
} from '@latus/react'; } from '@flecks/react';
const ImageComponent = ({resource}) => { const ImageComponent = ({resource}) => {
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define

View File

@ -1,3 +1,5 @@
import {Hooks} from '@flecks/core';
import ImageController from './controllers/image'; import ImageController from './controllers/image';
export { export {
@ -5,8 +7,8 @@ export {
}; };
export default { export default {
hooks: { [Hooks]: {
'@avocado/resource-persea/controllers': () => [ '@avocado/resource-persea.controllers': () => [
ImageController, ImageController,
], ],
}, },

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,116 @@
**/*.js # Logs
**/*.map logs
/assets *.log
!/.* npm-debug.log*
!src/**/*.js yarn-debug.log*
!/test/**/*.js yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -1,6 +1,6 @@
module.exports = () => ({ module.exports = {
dependencies: { stubs: {
dom: [ server: [
'@pixi/constants', '@pixi/constants',
'@pixi/core', '@pixi/core',
'@pixi/display', '@pixi/display',
@ -16,4 +16,4 @@ module.exports = () => ({
'@pixi/text', '@pixi/text',
], ],
}, },
}); };

View File

@ -0,0 +1,6 @@
'@flecks/core': {}
'@flecks/fleck': {}
'@flecks/http': {}
'@flecks/http/server':
build: false
'@flecks/react': {}

View File

@ -1,32 +1,38 @@
{ {
"name": "@avocado/graphics", "name": "@avocado/graphics",
"version": "2.0.0", "version": "3.0.0",
"repository": {
"type": "git",
"url": "https://git.hq.cha0s.io/cha0s/avocado.git",
"directory": "packages/graphics"
},
"main": "index.js", "main": "index.js",
"author": "cha0s", "author": "cha0s",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "latus-build", "build": "flecks build",
"clean": "latus-build clean", "clean": "flecks clean",
"fp": "latus-build forcepublish", "lint": "flecks lint",
"lint": "latus-build lint", "postversion": "cp package.json dist",
"test": "latus-build test" "test": "flecks test"
}, },
"files": [ "files": [
".flecksrc.js",
"build",
"index.js", "index.js",
"index.js.map", "index.js.map",
".latusrc.js", "src",
"test/fixtures", "test",
"test.js", "test.js",
"test.js.map" "test.js.map",
"test/fixtures"
], ],
"dependencies": { "dependencies": {
"@avocado/core": "2.0.0", "@avocado/core": "^3.0.0",
"@avocado/math": "2.0.0", "@avocado/math": "^3.0.0",
"@avocado/resource": "2.0.0", "@avocado/resource": "^3.0.0",
"@avocado/traits": "^2.0.0", "@flecks/core": "^1.3.0",
"@latus/core": "^2.0.0", "@flecks/react": "^1.3.0",
"@latus/react": "^2.0.0",
"@latus/socket": "2.0.0",
"@pixi/constants": "^5.3.9", "@pixi/constants": "^5.3.9",
"@pixi/core": "^5.3.9", "@pixi/core": "^5.3.9",
"@pixi/display": "^5.3.9", "@pixi/display": "^5.3.9",
@ -44,6 +50,7 @@
"rc-slider": "^9.7.1" "rc-slider": "^9.7.1"
}, },
"devDependencies": { "devDependencies": {
"@latus/build": "1.x" "@flecks/fleck": "^1.3.0",
"@flecks/http": "^1.3.0"
} }
} }

Some files were not shown because too many files have changed in this diff Show More