Dodano ładowanie pliku wiedzy
This commit is contained in:
parent
ce440ee778
commit
82c3de94ef
@ -1,4 +1,4 @@
|
|||||||
name icon category
|
name icon categories
|
||||||
airFrashener fa-wind home accessories
|
airFrashener fa-wind home accessories
|
||||||
apple fa-apple-alt food, fruits, fresh
|
apple fa-apple-alt food, fruits, fresh
|
||||||
babyAccessories fa-baby-carriage kids, accessories, hygiene
|
babyAccessories fa-baby-carriage kids, accessories, hygiene
|
||||||
|
|
@ -6,31 +6,20 @@ function flattenToUnique(array, view) {
|
|||||||
}, new Set())
|
}, new Set())
|
||||||
}
|
}
|
||||||
|
|
||||||
class SemanticNetwork {
|
function intoProduct({ name, icon }) {
|
||||||
/**
|
return new Product(name, icon)
|
||||||
* @param {string} definition
|
|
||||||
*/
|
|
||||||
constructor(definition) {
|
|
||||||
/**
|
|
||||||
* @param {string} stmt
|
|
||||||
* @returns {[{ name: string; categories: string[]; locations: string[] }]}
|
|
||||||
*/
|
|
||||||
function parseStatement(stmt) {
|
|
||||||
const [name, ...keywords] = stmt.split(':').map(x => x.trim())
|
|
||||||
const o = { name }
|
|
||||||
for (const keyword of keywords) {
|
|
||||||
const command = keyword[0]
|
|
||||||
const items = keyword.slice(1).split(',').map(x => x.trim()).filter(x => x.length > 0)
|
|
||||||
switch (command) {
|
|
||||||
case 'c': o.categories = items; break
|
|
||||||
case 'p': o.locations = items; break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return o
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data = definition.split('\n').filter(x => x.trim().length > 0)
|
class SemanticNetwork {
|
||||||
.map(parseStatement)
|
/**
|
||||||
|
* @param {{
|
||||||
|
* name: string;
|
||||||
|
* icon: string;
|
||||||
|
* categories: string[];
|
||||||
|
* }[]} data
|
||||||
|
*/
|
||||||
|
constructor(data) {
|
||||||
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllNames() {
|
getAllNames() {
|
||||||
@ -41,10 +30,6 @@ class SemanticNetwork {
|
|||||||
return flattenToUnique(this.data, ({ categories }) => categories)
|
return flattenToUnique(this.data, ({ categories }) => categories)
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllLocations() {
|
|
||||||
return flattenToUnique(this.data, ({ locations }) => locations)
|
|
||||||
}
|
|
||||||
|
|
||||||
findByName(nameToFind) {
|
findByName(nameToFind) {
|
||||||
return this.data.find(({ name }) => name === nameToFind)
|
return this.data.find(({ name }) => name === nameToFind)
|
||||||
}
|
}
|
||||||
@ -53,12 +38,19 @@ class SemanticNetwork {
|
|||||||
return this.data.filter(({ categories }) => categories.indexOf(categoryToFind) >= 0)
|
return this.data.filter(({ categories }) => categories.indexOf(categoryToFind) >= 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
findAllByLocation(locationToFind) {
|
getRandom() {
|
||||||
return this.data.filter(({ locations }) => locations.indexOf(locationToFind) >= 0)
|
const { floor, random } = Math;
|
||||||
}
|
return this.data[floor(random() * this.data.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
class AgentSemanticNetwork extends SemanticNetwork {}
|
findProductByName(nameToFind) {
|
||||||
|
return intoProduct(this.findByName(nameToFind));
|
||||||
|
}
|
||||||
|
|
||||||
|
getRandomProduct() {
|
||||||
|
return intoProduct(this.getRandom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function nearbyStorageUnitsCoords(gridX, gridY) {
|
function nearbyStorageUnitsCoords(gridX, gridY) {
|
||||||
function outsideOfStorageCenter(v) {
|
function outsideOfStorageCenter(v) {
|
||||||
@ -80,38 +72,45 @@ function nearbyStorageUnitsIndexes(gridX, gridY) {
|
|||||||
.map(({ x, y }) => x * UnitsCount + y * UnitsCount * RowsOfGroupsCount)
|
.map(({ x, y }) => x * UnitsCount + y * UnitsCount * RowsOfGroupsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Arrangement {
|
|
||||||
constructor() {
|
|
||||||
this.products = [...Array(UnitsCount)].map(() => ({
|
|
||||||
product: '',
|
|
||||||
count: 0,
|
|
||||||
icon: ''
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
nearbyProducts(gridX, gridY) {
|
|
||||||
return nearbyStorageUnitsIndexes(gridX, gridY)
|
|
||||||
.map(i => this.products[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Knowledge {
|
class Knowledge {
|
||||||
static semanticNetwork
|
|
||||||
static agentSemanticNetwork
|
|
||||||
static arrangement
|
|
||||||
|
|
||||||
constructor(definition) {
|
/**
|
||||||
|
* @type{SemanticNetwork}
|
||||||
|
*/
|
||||||
|
static semanticNetwork
|
||||||
|
|
||||||
|
static async loadFromFile(path) {
|
||||||
|
const response = await fetch(path);
|
||||||
|
const text = await response.text();
|
||||||
|
|
||||||
|
const [header, ...rows] = text.split('\n')
|
||||||
|
.map(x => x.trim())
|
||||||
|
.filter(x => x)
|
||||||
|
.map(x => x.split('\t')
|
||||||
|
.map(cell => cell.split(',').map(x => x.trim())));
|
||||||
|
|
||||||
|
const data = rows.map(row =>
|
||||||
|
row.reduce((p, c, i) => ({
|
||||||
|
...p,
|
||||||
|
[header[i]]: i == 2 ? c : c[0] }), {}));
|
||||||
|
|
||||||
|
Knowledge.semanticNetwork = new SemanticNetwork(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
Knowledge.semanticNetwork = new SemanticNetwork(definition)
|
Knowledge.semanticNetwork = new SemanticNetwork(definition)
|
||||||
Knowledge.agentSemanticNetwork = new AgentSemanticNetwork(definition)
|
|
||||||
Knowledge.arrangement = new Arrangement()
|
Knowledge.arrangement = new Arrangement()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
keywords:
|
keywords:
|
||||||
p - powiązane pomieszczenia / miejsca
|
p - powiązane pomieszczenia / miejsca
|
||||||
c - category
|
c - category
|
||||||
*/
|
|
||||||
new Knowledge(`
|
new Knowledge(`
|
||||||
Piłka :c sport,rozrywka, piłka nożna
|
Piłka :c sport,rozrywka, piłka nożna
|
||||||
Kubek klubowy :c sport,rozrywka,piłka nożna :p kuchnia
|
Kubek klubowy :c sport,rozrywka,piłka nożna :p kuchnia
|
||||||
@ -128,3 +127,4 @@ new Knowledge(`
|
|||||||
Laptop :c elektronika,gaming :p biuro,szkoła
|
Laptop :c elektronika,gaming :p biuro,szkoła
|
||||||
Telefon :c elektronika :p biuro,szkoła
|
Telefon :c elektronika :p biuro,szkoła
|
||||||
`)
|
`)
|
||||||
|
*/
|
@ -23,131 +23,4 @@ class Product {
|
|||||||
equals(other) {
|
equals(other) {
|
||||||
return this.name === other.name;
|
return this.name === other.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get REGISTRY() {
|
|
||||||
// in alphabetical order
|
|
||||||
return {
|
|
||||||
empty: new Product('', ''),
|
|
||||||
airFrashener: new Product('airFrashener', 'fa-wind'),
|
|
||||||
apple: new Product('apple', 'fa-apple-alt'),
|
|
||||||
babyAccessories: new Product('babyAccessories','fa-baby-carriage'),
|
|
||||||
bacon: new Product('bacon', 'fa-bacon'),
|
|
||||||
bandAid: new Product('bandAid', 'fa-band-aid'),
|
|
||||||
basketballBall: new Product('basketballBall', 'fa-basketball-ball'),
|
|
||||||
beer: new Product('beer','fa-beer'),
|
|
||||||
bell: new Product('bell','fa-bell'),
|
|
||||||
bicycle: new Product('bicycle','fa-bicycle'),
|
|
||||||
bone: new Product('bone', 'fa-bone'),
|
|
||||||
book: new Product('book', 'fa-book'),
|
|
||||||
bread: new Product('bread', 'fa-bread-slice'),
|
|
||||||
cake: new Product('cake', 'fa-birthday-cake'),
|
|
||||||
calculator: new Product('calculator', 'fa-calculator'),
|
|
||||||
calendar: new Product('calendar', 'fa-calendar'),
|
|
||||||
camera: new Product('camera','fa-camera'),
|
|
||||||
campAccessories: new Product('campAccessories','fa-campground'),
|
|
||||||
candyCane: new Product('candyCane', 'fa-candy-cane'),
|
|
||||||
carrot: new Product('carrot', 'fa-carrot'),
|
|
||||||
catAccessories: new Product('catAccessories','fa-cat'),
|
|
||||||
carAccessories: new Product('carAccessories','fa-car'),
|
|
||||||
cigarettes: new Product('cigarettes', 'fa-smoking'),
|
|
||||||
chair: new Product('chair', 'fa-chair'),
|
|
||||||
charger: new Product('charger', 'fa-battery-half'),
|
|
||||||
cheese: new Product('cheese', 'fa-cheese'),
|
|
||||||
chess: new Product('chess', 'fa-chess'),
|
|
||||||
cleaningSupplies: new Product('cleaningSupplies', 'fa-broom'),
|
|
||||||
cloathesAccessories: new Product('cloathesAccessories','fa-glasses'),
|
|
||||||
cocktailSupplies: new Product('cocktailSupplies','fa-cocktail'),
|
|
||||||
coffee: new Product('cofee','fa-coffee'),
|
|
||||||
contactLenses: new Product('contactLenses', 'fa-eye'),
|
|
||||||
cookie: new Product('cookie','fa-cookie'),
|
|
||||||
couch: new Product('couch', 'fa-couch'),
|
|
||||||
coughSyrop: new Product('coughSyrop', 'fa-lungs'),
|
|
||||||
cookie: new Product('cookie', 'fa-cookie'),
|
|
||||||
dictionary: new Product('dictionary', 'fa-language'),
|
|
||||||
dogAccessories: new Product('dogAccessories','fa-dog'),
|
|
||||||
drinks: new Product('drinks', 'fa-glass-whiskey'),
|
|
||||||
drone: new Product('drone','fa-plane'),
|
|
||||||
drum: new Product('drum', 'fa-drum'),
|
|
||||||
envelope: new Product('envelope', 'fa-envelope'),
|
|
||||||
egg: new Product('egg','fa-egg'),
|
|
||||||
electronicAccessories: new Product('electronicAccessories','fa-bolt'),
|
|
||||||
eraser: new Product('eraser','fa-eraser'),
|
|
||||||
extinguisher: new Product('extinguisher','fa-fire'),
|
|
||||||
firstAid: new Product('firstAid','fa-first-aid'),
|
|
||||||
fish: new Product('fish','fa-fish'),
|
|
||||||
gamepad: new Product('gamepad', 'fa-gamepad'),
|
|
||||||
giftWrapping: new Product('giftWrapping', 'fa-gift'),
|
|
||||||
glassAccessories: new Product('glassAccessories','fa-wine-glass'),
|
|
||||||
gps: new Product('gps','fa-street-view'),
|
|
||||||
guitar: new Product('guitar','fa-guitar'),
|
|
||||||
hamburger: new Product('hamburger', 'fa-hamburger'),
|
|
||||||
hammer: new Product('hammer', 'fa-hammer'),
|
|
||||||
halloweenAccessories: new Product('halloweenAccessories', 'fa-ghost'),
|
|
||||||
hauntingAccessories: new Product('hauntingAccessories','fa-binoculars'),
|
|
||||||
headphones: new Product('headphones','fa-headphones'),
|
|
||||||
highlighter: new Product('highlighter','fa-highlighter'),
|
|
||||||
homeSecurity: new Product('homeSecurity','fa-key'),
|
|
||||||
hotdog: new Product('hotdog','fa-hotdog'),
|
|
||||||
icecream: new Product('icecream','fa-ice-cream'),
|
|
||||||
insecticide: new Product('insecticide','fa-spider'),
|
|
||||||
jewelry: new Product('jewelry','fa-gem'),
|
|
||||||
keyboard: new Product('keyboard', 'fa-keyboard'),
|
|
||||||
kitchenSupplies: new Product('kitchenSupplies', 'fa-blender'),
|
|
||||||
laptop: new Product('laptop', 'fa-laptop'),
|
|
||||||
lemon: new Product('lemon','fa-lemon'),
|
|
||||||
lightbulb: new Product('lightbulb', 'fa-lightbulb'),
|
|
||||||
microphone: new Product('microphone', 'fa-microphone'),
|
|
||||||
mask: new Product('mask', 'fa-head-side-mask'),
|
|
||||||
monitor: new Product('monitor', 'fa-desktop'),
|
|
||||||
movingAccessories: new Product('movingAccessories','fa-boxes'),
|
|
||||||
newbornAccessorries: new Product('newbornAccessorries','fa-baby-carriage'),
|
|
||||||
newspaper: new Product('newspaper','fa-newspaper'),
|
|
||||||
paintBrush: new Product('paintBrush','fa-paint-brush'),
|
|
||||||
paintRoller: new Product('paintRoller', 'fa-paint-roller'),
|
|
||||||
paper: new Product('paper','fa-paperclip'),
|
|
||||||
partyAccessories: new Product('partyAccessories','fa-glass-cheers'),
|
|
||||||
pen: new Product('pen','fa-pen'),
|
|
||||||
pepper: new Product('pepper','fa-pepper-hot'),
|
|
||||||
personalSafetyAccessories: new Product('personalSafetyAccessories','fa-fingerprint'),
|
|
||||||
piggyBank: new Product('piggyBank', 'fa-piggy-bank'),
|
|
||||||
pills: new Product('pills','fa-pills'),
|
|
||||||
pizza: new Product('pizza','fa-pizza-slice'),
|
|
||||||
plants: new Product('plants','fa-seedling'),
|
|
||||||
printer: new Product('printer','fa-print'),
|
|
||||||
puzzle: new Product('puzzle', 'fa-puzzle-piece'),
|
|
||||||
religionAccessories: new Product('religionAccessories','fa-pray'),
|
|
||||||
ruler: new Product('ruler', 'fa-ruler'),
|
|
||||||
runningAccessories: new Product('runningAccessories','fa-running'),
|
|
||||||
sanitizer: new Product('sanitizer', 'fa-spray-can'),
|
|
||||||
scissors: new Product('scissors', 'fa-cut'),
|
|
||||||
seeds: new Product('seeds', 'fa-seedling'),
|
|
||||||
skatingAccessories: new Product('skatingAccessories','fa-skating'),
|
|
||||||
skiingAccessories: new Product('skiingAccessories','fa-skiing'),
|
|
||||||
soap: new Product('soap','fa-pump-soap'),
|
|
||||||
spaAccessories: new Product('spaAccessories','fa-spa'),
|
|
||||||
sportCloathes: new Product('sportCloathes','fa-futbol'),
|
|
||||||
stamp: new Product('stamp', 'fa-stamp'),
|
|
||||||
suitcase: new Product('suitcase', 'fa-suitcase-rolling'),
|
|
||||||
summerHoliday: new Product('summerHoliday','fa-umbrella-beach'),
|
|
||||||
sunscreen: new Product('sunscreen','fa-sun'),
|
|
||||||
swimmingAccessories: new Product('swimmingAccessories','fa-swimmer'),
|
|
||||||
thermometer: new Product('thermometer', 'fa-thermometer'),
|
|
||||||
toiletSupplies: new Product('toiletSupplies','fa-toilet-paper'),
|
|
||||||
tools: new Product('tools','fa-wrench'),
|
|
||||||
toothpaste: new Product('toothpaste', 'fa-tooth'),
|
|
||||||
toys: new Product('toys','fa-horse'),
|
|
||||||
trashBin: new Product('trashBin', 'fa-trash'),
|
|
||||||
tv: new Product('tv', 'fa-tv'),
|
|
||||||
umbrella: new Product('umbrella', 'fa-umbrella'),
|
|
||||||
vinyl: new Product('vinyl', 'fa-record-vinyl'),
|
|
||||||
volleyballBall: new Product('volleyballBall', 'fa-volleyball-ball'),
|
|
||||||
wine: new Product('wine','fa-wine-bottle'),
|
|
||||||
winterCloathes: new Product('winterCloathes','fa-mitten'),
|
|
||||||
winterHoliday: new Product('winterHoliday','fa-tree')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static RANDOM_FROM_REGISTRY() {
|
|
||||||
return Product.REGISTRY[Object.keys(Product.REGISTRY).filter(p => p !== 'empty')[Math.floor(Math.random() * (Object.keys(Product.REGISTRY).length - 1))]];
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
window.addEventListener('DOMContentLoaded', () => document.fonts.load('900 14px "Font Awesome 5 Free"').then(() => {
|
window.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
await document.fonts.load('900 14px "Font Awesome 5 Free"')
|
||||||
|
|
||||||
const floorCanvas = document.getElementById('canvas-floor');
|
const floorCanvas = document.getElementById('canvas-floor');
|
||||||
const gridCanvas = document.getElementById('canvas-grid');
|
const gridCanvas = document.getElementById('canvas-grid');
|
||||||
const agentCanvas = document.getElementById('canvas-agent');
|
const agentCanvas = document.getElementById('canvas-agent');
|
||||||
@ -12,6 +14,8 @@ window.addEventListener('DOMContentLoaded', () => document.fonts.load('900 14px
|
|||||||
const floor = new Floor(floorCanvas);
|
const floor = new Floor(floorCanvas);
|
||||||
const grid = new Grid(gridCanvas);
|
const grid = new Grid(gridCanvas);
|
||||||
const agent = new Agent(agentCanvas);
|
const agent = new Agent(agentCanvas);
|
||||||
|
|
||||||
|
await Knowladge.loadFromFile('/data/products.tsv')
|
||||||
const products = new Products(productsCanvas);
|
const products = new Products(productsCanvas);
|
||||||
|
|
||||||
const fpsElement = document.getElementById('fps');
|
const fpsElement = document.getElementById('fps');
|
||||||
@ -20,7 +24,7 @@ window.addEventListener('DOMContentLoaded', () => document.fonts.load('900 14px
|
|||||||
} else {
|
} else {
|
||||||
document.body.removeChild(fpsElement);
|
document.body.removeChild(fpsElement);
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
|
||||||
function displayFPS(fpsElement) {
|
function displayFPS(fpsElement) {
|
||||||
let old = new Date();
|
let old = new Date();
|
||||||
|
Loading…
Reference in New Issue
Block a user