Commit 1e3b2138 authored by Andrew Danger Lyon's avatar Andrew Danger Lyon

finally got a great working vizz layer. workers are arranged in a ring around...

finally got a great working vizz layer. workers are arranged in a ring around the economy, compnies inside (no arrangement), orders and labor pull compnies around, "pings" are sent to signify order direction. working/looking fantastic. i want to try some more stuff with worker arrangements (so its not so strictly radial) but for now this is a great checkin point
parent 157f7778
module.exports = {
// how many milliseconds to us equals an hour in our economy (1:1 would be
// 3600000)
time_scale: 100,
//
// NOTE: anything less than 200 can make some things wonky, for instance
// the clock-in transactions might not process before the clock-out
// transactions start, which throws things out of sync.
time_scale: 200,
// the port we run our event log off of (which vizz uses to show things)
http_port: 3001,
......
......@@ -61,7 +61,9 @@ exports.create = async function(name, options) {
meta: '{}',
created: new Date().toISOString(),
});
workers[uid] = worker_name;
workers[uid] = {
name: worker_name,
};
if(!res.success) {
throw new Error('company.create() -- problem adding worker: '+res.description);
}
......@@ -93,7 +95,7 @@ exports.create = async function(name, options) {
if(!res.success) {
throw new Error('company.create() -- problem adding member: '+res.description);
}
console.log(` + member: ${workers[wid]} -- ${id}:${wid}`);
console.log(` + member: ${workers[wid].name} -- ${id}:${wid}`);
});
// mark it, dude
......@@ -225,84 +227,61 @@ async function receive_order(order_id) {
const emit = function(evname) {
event(evname, {order});
};
switch(company.name) {
case 'grocer':
case 'power-planty':
var res = await trans.send_as(worker, tx.order.TxUpdateStatus, {
id: order_id,
process_status: 'finalized',
updated: last_time.toISOString(),
});
if(!res.success) {
throw new Error('receive_order: err: '+res.description);
}
product.inputs.forEach((inp) => {
const inp_product = companies[inp.company].products[inp.product];
inc_inventory(company, inp_product.id, -inp.amount * amount);
});
company.bus.emit('order:start');
emit('order:start');
company.bus.emit('order:complete');
emit('order:complete');
company.bus.emit('order:ship');
emit('order:ship');
company_from.bus.emit('order:'+order_id+':complete');
company_from.bus.emit('order:'+order_id+':delivered');
emit('order:delivered');
break;
case 'farmy':
var res = await trans.send_as(worker, tx.order.TxUpdateStatus, {
id: order_id,
process_status: 'accepted',
updated: last_time.toISOString(),
});
if(!res.success) {
throw new Error('receive_order: err: '+res.description);
}
product.inputs.forEach((inp) => {
const inp_product = companies[inp.company].products[inp.product];
inc_inventory(company, inp_product.id, -inp.amount);
});
company.bus.emit('order:start');
emit('order:start');
company.bus.emit('order:complete');
emit('order:completed');
company_from.bus.emit('order:'+order_id+':complete');
company.bus.emit('order:ship');
emit('order:ship');
await wait_ticks(company, 1 * 24);
company_from.bus.emit('order:'+order_id+':delivered');
emit('order:delivered');
break;
default:
var res = await trans.send_as(worker, tx.order.TxUpdateStatus, {
id: order_id,
process_status: 'accepted',
updated: last_time.toISOString(),
});
if(!res.success) {
throw new Error('receive_order: err: '+res.description);
}
product.inputs.forEach((inp) => {
const inp_product = companies[inp.company].products[inp.product];
inc_inventory(company, inp_product.id, -inp.amount);
});
company.bus.emit('order:start');
emit('order:start');
// wait 3 days. we kind of just assume infinite scale at each company
// for now (obviously eventually we'll want to implement some for of
// order queuing)
await wait_ticks(company, 3 * 24);
company.bus.emit('order:complete');
emit('order:complete');
company_from.bus.emit('order:'+order_id+':complete');
company.bus.emit('order:ship');
emit('order:ship');
await wait_ticks(company, 1 * 24);
company_from.bus.emit('order:'+order_id+':delivered');
emit('order:delivered');
break;
const update_order = async (status, options) => {
options || (options = {});
var res = await trans.send_as(worker, tx.order.TxUpdateStatus, {
id: order_id,
process_status: status,
updated: last_time.toISOString(),
});
if(!res.success) {
throw new Error('receive_order: err: '+res.description);
}
if(options.wait) {
await wait_ticks(company, options.wait);
}
};
const is_type = (...types) => types.indexOf(company.name) >= 0;
const wait_opts = is_type('grocer') ? {} : {wait: 1};
// adjust our inventory
product.inputs.forEach((inp) => {
const inp_product = companies[inp.company].products[inp.product];
inc_inventory(company, inp_product.id, -inp.amount);
});
await update_order('accepted', wait_opts);
company.bus.emit('order:start');
emit('order:start');
if(!is_type('grocer', 'power-planty')) {
// wait 3 days. we kind of just assume infinite scale at each company
// for now (obviously eventually we'll want to implement some form of
// order queuing)
await wait_ticks(company, 3 * 24);
}
await update_order('completed', wait_opts);
company.bus.emit('order:complete');
emit('order:complete');
company_from.bus.emit('order:'+order_id+':complete');
await update_order('proxying', wait_opts);
company.bus.emit('order:ship');
emit('order:ship');
if(!is_type('grocer', 'power-planty')) {
// shipping time, if applicable
await wait_ticks(company, 1 * 24);
}
// always wait an hours to finalize an order.
await wait_ticks(company, 1);
await update_order('finalized', wait_opts);
company_from.bus.emit('order:'+order_id+':delivered');
emit('order:delivered');
}
function setup_inventory(company) {
......@@ -386,6 +365,10 @@ function manage_labor(now, company) {
const promises = [];
Object.keys(company.workers).forEach((worker_id) => {
if(cron.matches(now, '0 0 9 * * *')) {
if(company.labor[worker_id]) {
//console.log(`* clock in: ${company.name} -- ${company.workers[worker_id].name} is already clocked in...????`);
return;
}
// was nice sleep and gud toast but now is time for serious wurk
const labor_id = uuid();
const chain = trans.send_as(worker_id, tx.labor.TxCreate, {
......@@ -395,7 +378,7 @@ function manage_labor(now, company) {
created: now.toISOString(),
}).then(function(res) {
if(res.success) {
//console.log(`> clock in: ${company.name} -- ${company.workers[worker_id]}`);
//console.log(`> clock in: ${company.name} -- ${company.workers[worker_id].name}`);
event('worker:clock-in', {worker_id, company_id: company.id, labor_id});
company.labor[worker_id] = labor_id;
} else {
......@@ -408,7 +391,10 @@ function manage_labor(now, company) {
if(cron.matches(now, '0 0 17 * * *')) {
// wow 8 hrs wut a day tiem to go home
const labor_id = company.labor[worker_id];
if(!labor_id) return;
if(!labor_id) {
//console.log(`* clock out: ${company.name} -- ${company.workers[worker_id].name} is not clocked in...????`);
return;
}
const chain = trans.send_as(worker_id, tx.labor.TxSetTime, {
id: labor_id,
start: new Date(0).toISOString(),
......@@ -416,9 +402,9 @@ function manage_labor(now, company) {
updated: now.toISOString(),
}).then(function(res) {
if(res.success) {
//console.log(`> clock out: ${company.name} -- ${company.workers[worker_id]}`);
//console.log(`> clock out: ${company.name} -- ${company.workers[worker_id].name}`);
event('worker:clock-out', {worker_id, company_id: company.id, labor_id});
delete company.workers[worker_id].labor_id;
delete company.labor[worker_id];
} else {
event('error', {action: 'clock-out', err: res.description});
throw new Error('labor: clock-out: '+res.description);
......
const proto = require('../build/protobuf');
const Events = require('./events');
const Vizz = require('./vizz');
const Vizz = require('./vizz/index');
const Transactions = require('./transactions');
document.addEventListener('DOMContentLoaded', async () => {
......
This diff is collapsed.
const RADS = Math.PI / 180;
module.exports = function radial(i, {radius, centerx, centery, len}) {
const start_angle = 30;
const current_angle = start_angle + ((360 / len) * i);
const radians = current_angle * RADS;
return {
x: centerx + radius * Math.cos(radians),
y: centery + radius * Math.sin(radians),
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment