27
28
29
30
31
32
33
34
35
36
37
38
39
40
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
local job_t = starlit.store.compilerJob
local conf = state.pgm.file.body.conf
table.insert(conf, {
key='job', value=job_t.enc {
schematic = scm.id;
cyclesLeft = scm.sw.cost and scm.sw.cost.cycles or 0;
timeLeft = (fab.time and fab.time.print or 0);
}
})
end
local function compilerCanPrint(user, cpl, scm)
local E = starlit.mod.electronics
local output = ItemStack(scm.sw.output):get_definition()
................................................................................
user.entity:get_inventory():get_list 'main';
}
local cost = {
fab = fab, output = output;
consume = consume, unsat = unsat, leftover = leftover, itemSpec = itemSpec;
runtimeEstimate = scm.speed + cpl.speed + (fab.time and fab.time.print or 0);
power = cpl.powerCost + scm.powerCost;
ram = (cpl.cost and cpl.cost.ram or 0)
+ (scm.cost and scm.cost.ram or 0);
cycles = (cpl.cost and cpl.cost.cycles or 0)
+ (scm.cost and scm.cost.cycles or 0);
}
local userComp = E.chip.sumCompute(
user.entity:get_inventory():get_list 'starlit_suit_chips'
)
if ok and cost.power <= user:suitCharge() and cost.ram <= userComp.ram then
................................................................................
end
end
end
end;
render = function(state, user)
local sel, pgmSelector = state.select, {}
state.fetch()
state.ctx.pullConf()
local function pushSelector(id, item, label, desc, req)
local rh = .5
local label = {kind = 'text', w = 10-1.5, h=1.5;
text = '<global valign=middle>'..lib.str.htsan(label) }
if req then
label.h = label.h - rh - .2
local imgs = {}
for ci,c in ipairs(req) do
for ei, e in ipairs(c.list) do
table.insert(imgs, {kind = 'img', w=rh, h=rh, img=e.img})
end
end
label = {kind = 'vert', w = 10-1.5, h=1.5;
label;
{kind ='hztl', w=10-1.5, h=rh; unpack(imgs); }
}
end
table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.5;
{kind = 'contact', id=id, w=1.5, h=1.5;
item = item;
color = {hue=220, sat=0, lum=0};
desc = desc;
};
label;
})
end
local back = {kind = 'button', id='back', label = '<- Back', w=10,h=1.2}
if sel.chips == nil then
table.insert(pgmSelector, {kind = 'img', img = 'starlit-ui-alert.png', w=2, h=2})
elseif sel.chip == nil then
for i, c in ipairs(sel.chips.order) do
-- TODO filter out chips without schematics?
pushSelector('chip_' .. c.data.uuid, c.stack, c.data.label)
end
if next(sel.chips.order) then
table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.5;
{kind = 'button', w=5,h=1.5; id='showAll', label='Show All'};
{kind = 'button', w=5,h=1.5; id='find', label='Find'};
})
end
else
if sel.scm == nil then
for idx, ent in ipairs(sel.scms) do
local fab = ent.sw.input
if fab.flag and fab.flag.print then
local req = fab:visualize()
pushSelector('scm_' .. idx, ent.sw.output, ent.sw.name, nil, req)
end
end
table.insert(pgmSelector, back)
else
local scm = sel.scms[sel.scm]
local output = ItemStack(scm.sw.output):get_definition()
local fab = scm.sw.input
local sw = scm.sw
local function unmet(str)
return lib.color(1,.3,.3):fmt(str)
end
table.insert(pgmSelector, {kind = 'hztl', w=10, h=1.2;
{kind = 'img', item = sw.output, w=1.2, h=1.2, desc=output.description};
{kind = 'text', text = string.format('<global valign=middle><b>%s</b>', lib.str.htsan(sw.name)), w=10-1.2,h=1.2};
})
local inputTbl = {kind = 'vert', w=5,h=0;
{kind = 'hbar', w=5, h=.5, text=sel.input and 'Input Plan' or 'Input'}};
local costTbl = {kind = 'vert', w=5,h=0;
{kind = 'hbar', w=5, h=.5, text=sel.input and 'Process Plan' or 'Process'}};
local reqPane = {kind = 'pane', id='reqPane', w=10, h=7;
{kind = 'hztl', w=10,h=0; inputTbl, costTbl}
}
local function pushCost(x, t, val)
table.insert(costTbl, {kind='label', w=4.5,h=.5,x=x;
text=string.format('%s: %s',t,val);
})
end
local function pushComputeCosts(header, p)
if p then
table.insert(costTbl, {kind = 'label', w=5, h=.5, x=0; text=header});
if p.cycles then
pushCost(.5, 'Compute', lib.math.siUI({'cycle','cycles'}, p.cycles, true))
end
if p.power then
local str = lib.math.siUI('J', p.power)
if p.power > user:suitCharge() then str = unmet(str) end
pushCost(.5, 'Power', str)
................................................................................
pushCost(.5, 'Memory', str)
end
end
end
local function fabToUI(x, inputTbl, req)
for ci,c in ipairs(req) do
table.insert(inputTbl, {kind = 'label', w=5-x, h=.5, x=x;
text=lib.str.capitalize(c.header)});
for ei,e in ipairs(c.list) do
table.insert(inputTbl, {kind = 'hztl', w=4.5-x, h=.5, x=x+.5;
{kind='img', w=.5,h=.5, img=e.img};
{kind='label', w=3.3,h=.5,x=.2, text=lib.str.capitalize(e.label)};
});
end
end
end
local commitHue, commitLabel = 120
if not sel.input then
................................................................................
end
fabToUI(0, inputTbl, vis)
end
if not ok then commitHue = 0 end
end
table.insert(pgmSelector, reqPane)
table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.2;
{kind = 'button', id='back', label = '← Back', w=5,h=1.2};
{kind = 'button', id='commit', label = commitLabel .. ' →', w=5,h=1.2, color={hue=commitHue,sat=0,lum=0}};
})
end
end
local rec = getRecentJobs(state)
local recentList = {kind = 'hwrap', cols=3}
if rec then
for i,id in ipairs(rec) do
local out = ItemStack(starlit.item.sw.db[id].output)
table.insert(recentList, {kind='contact',w=1.5,h=1.5,id=string.format('recent_%s',i), item = out})
end
end
local queue = {kind='pane', w=5, h=9.5}
for i,v in ipairs(state.pgm.file.body.conf) do
if v.key == 'job' then
local job = starlit.store.compilerJob.dec(v.value)
local scm = starlit.item.sw.db[job.schematic]
local cycTotal = (scm.cost and scm.cost.cycles or 0)
local secTotal = (scm.input.time and scm.input.time.print or 0)
local cycPct = cycTotal == 0 and 1 or (1 - job.cyclesLeft/cycTotal)
local secPct = secTotal == 0 and 1 or (1 - job.timeLeft/secTotal)
local out = ItemStack(scm.output)
local cycBar = {kind = 'hbar', fac = cycPct, w=5-1.5, h = .5;
color={hue=150,sat=0,lum=0}; text=string.format("Compute %s%%", math.floor(cycPct*100));
}
local secBar = {kind = 'hbar', fac = secPct, w=5-1.5, h = .5;
color={hue=50,sat=0,lum=0}; text=string.format("Assemble %s%%", math.floor(secPct*100));
}
table.insert(queue, {kind='hztl'; w=5, h=1.5;
{kind = 'contact', w=1.5,h=1.5, id=string.format('cancel_%s', i), item = out};
{kind = 'vert', w=5-1.5, h=1.5;
{kind = 'label', text=out:get_definition().short_description, w=5-1.5, h=.75};
(cycPct < 1 and cycBar or secBar);
}
})
end
end
return starlit.ui.build {
kind = 'hztl', padding = 0.5; w = 20, h = 10, mode = 'sw';
{kind = 'vert', w = 5, h = 5;
{kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><left>Recent Prints</left></b>'};
recentList;
};
{kind = 'vert', w = 10, h = 10;
{kind = 'hbar', fac=0, w = 10, h = .5, text = '<b>Program Select</b>'};
{kind = 'pane', w = 10, h = 9.5, id='pgmSelect';
unpack(pgmSelector)
};
};
{kind = 'vert', w = 5, h = 10;
{kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><right>Print Queue</right></b>'};
queue;
};
}
end;
};
};
})
|
>
>
|
>
>
|
|
>
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
|
<
<
<
|
|
|
|
>
>
>
>
>
>
>
>
>
<
<
>
>
>
>
>
>
>
>
>
>
|
>
|
|
|
<
>
>
|
|
|
|
|
|
|
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
...
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
local job_t = starlit.store.compilerJob
local conf = state.pgm.file.body.conf
table.insert(conf, {
key='job', value=job_t.enc {
schematic = scm.id;
cyclesLeft = scm.sw.cost and scm.sw.cost.cycles or 0;
timeLeft = (fab.time and fab.time.print or 0);
powerLeft = cost.power;
numinaLeft = cost.numina;
}
})
end
local function compilerCanPrint(user, cpl, scm)
local E = starlit.mod.electronics
local output = ItemStack(scm.sw.output):get_definition()
................................................................................
user.entity:get_inventory():get_list 'main';
}
local cost = {
fab = fab, output = output;
consume = consume, unsat = unsat, leftover = leftover, itemSpec = itemSpec;
runtimeEstimate = scm.speed + cpl.speed + (fab.time and fab.time.print or 0);
power = cpl.powerCost + scm.powerCost
+ (sw.input.cost and sw.input.cost.power);
ram = (cpl.cost and cpl.cost.ram or 0)
+ (scm.cost and scm.cost.ram or 0);
cycles = (cpl.cost and cpl.cost.cycles or 0)
+ (scm.cost and scm.cost.cycles or 0);
numina = fab.cost and fab.cost.numina or 0;
}
local userComp = E.chip.sumCompute(
user.entity:get_inventory():get_list 'starlit_suit_chips'
)
if ok and cost.power <= user:suitCharge() and cost.ram <= userComp.ram then
................................................................................
end
end
end
end;
render = function(state, user)
local sel, pgmSelector = state.select, {kind = 'vert'}
state.fetch()
state.ctx.pullConf()
local function pushSelector(tbl, id, item, label, desc, req, w)
w = w or 12
local rh = .5
local label = {kind = 'text', w = w-1.5, h=1.6;
text = '<global valign=middle>'..lib.str.htsan(label) }
if req then
label.h = label.h - rh - .2
local imgs = {}
for ci,c in ipairs(req) do
for ei, e in ipairs(c.list) do
table.insert(imgs, {kind = 'img', w=rh, h=rh, img=e.img})
end
end
label = {kind = 'vert', w = w-1.5, h=1.8;
label;
{kind ='hztl', w=w-1.5, h=rh; unpack(imgs); }
}
end
table.insert(tbl, {kind = 'hztl', w=w,h=1.8;
{kind = 'contact', id=id, w=1.5, h=1.5;
item = item;
color = {hue=220, sat=0, lum=0};
desc = desc;
};
label;
})
end
local back = {kind = 'button', id='back', label = '<- Back', w=12,h=1.2}
if sel.chips == nil then
table.insert(pgmSelector, {kind = 'img', img = 'starlit-ui-alert.png', w=2, h=2})
elseif sel.chip == nil then
for i, c in ipairs(sel.chips.order) do
-- TODO filter out chips without schematics?
pushSelector(pgmSelector, 'chip_' .. c.data.uuid, c.stack, c.data.label)
end
if next(sel.chips.order) then
table.insert(pgmSelector, {kind = 'hztl', w=12,h=1.5;
{kind = 'button', w=6,h=1.5; id='showAll', label='Show All'};
{kind = 'button', w=6,h=1.5; id='find', label='Find'};
})
end
else
if sel.scm == nil then
-- l m a o
-- pgmSelector.kind = 'hwrap'
-- pgmSelector.cols = 2
local wrap = {kind='hwrap',cols=2,w=12}
for idx, ent in ipairs(sel.scms) do
local fab = ent.sw.input
if fab.flag and fab.flag.print then
local req = fab:visualize()
pushSelector(wrap,'scm_' .. idx, ent.sw.output, ent.sw.name, nil, req,6)
end
end
table.insert(pgmSelector, wrap)
table.insert(pgmSelector, back)
else
local scm = sel.scms[sel.scm]
local output = ItemStack(scm.sw.output):get_definition()
local fab = scm.sw.input
local sw = scm.sw
local function unmet(str)
return lib.color(1,.3,.3):fmt(str)
end
table.insert(pgmSelector, {kind = 'hztl', w=12, h=1.2;
{kind = 'img', item = sw.output, w=1.2, h=1.2, desc=output.description};
{kind = 'text', text = string.format('<global valign=middle><b>%s</b>', lib.str.htsan(sw.name)), w=12-1.2,h=1.2};
})
local inputTbl = {kind = 'vert', w=6,h=0;
{kind = 'hbar', w=6, h=.5, text=sel.input and 'Input Plan' or 'Input'}};
local costTbl = {kind = 'vert', w=6,h=0;
{kind = 'hbar', w=6, h=.5, text=sel.input and 'Process Plan' or 'Process'}};
local reqPane = {kind = 'pane', id='reqPane', w=12, h=8;
{kind = 'hztl', w=12,h=0; inputTbl, costTbl}
}
local function pushCost(x, t, val)
table.insert(costTbl, {kind='label', w=5.5,h=.5,x=x;
text=string.format('%s: %s',t,val);
})
end
local function pushComputeCosts(header, p)
if p then
table.insert(costTbl, {kind = 'label', w=6, h=.5, x=0; text=header});
if p.cycles then
pushCost(.5, 'Compute', lib.math.siUI({'cycle','cycles'}, p.cycles, true))
end
if p.power then
local str = lib.math.siUI('J', p.power)
if p.power > user:suitCharge() then str = unmet(str) end
pushCost(.5, 'Power', str)
................................................................................
pushCost(.5, 'Memory', str)
end
end
end
local function fabToUI(x, inputTbl, req)
for ci,c in ipairs(req) do
table.insert(inputTbl, {kind = 'label', w=6-x, h=.5, x=x;
text=lib.str.capitalize(c.header)});
for ei,e in ipairs(c.list) do
table.insert(inputTbl, {kind = 'hztl', w=5.5-x, h=.5, x=x+.5;
{kind='img', w=.5,h=.5, img=e.img};
{kind='label', w=4.3,h=.5,x=.2, text=lib.str.capitalize(e.label)};
});
end
end
end
local commitHue, commitLabel = 120
if not sel.input then
................................................................................
end
fabToUI(0, inputTbl, vis)
end
if not ok then commitHue = 0 end
end
table.insert(pgmSelector, reqPane)
table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.2;
{kind = 'button', id='back', label = '← Back', w=6,h=1.2};
{kind = 'button', id='commit', label = commitLabel .. ' →', w=6,h=1.2, color={hue=commitHue,sat=0,lum=0}};
})
end
end
local rec = getRecentJobs(state)
local recentList = {kind = 'hwrap', cols=3}
if rec then
for i,id in ipairs(rec) do
local out = ItemStack(starlit.item.sw.db[id].output)
table.insert(recentList, {kind='contact',w=1.5,h=1.5,id=string.format('recent_%s',i), item = out})
end
end
local queue = {kind='pane', w=5, h=9.5}
local cst = state.ctx.availableChips()
for i,v in ipairs(state.pgm.file.body.conf) do
if v.key == 'job' then
local job = starlit.store.compilerJob.dec(v.value)
local scm = starlit.mod.electronics.chip.usableSoftware(cst, {{
id = job.schematic;
sw = starlit.item.sw.db[job.schematic];
}})[1]
if scm == nil then goto badJob end
local steps = {
{label = 'Compute', n = job.cyclesLeft, color=lib.color(0,1,0);
total = scm.sw.cost and scm.sw.cost.cycles or 0};
{label = 'Energize', n = job.powerLeft, color=lib.color(0,.5,1);
total = (scm.powerCost or 0)
+ (state.pgm.powerCost or 0)
+ (scm.sw.input.cost and scm.sw.input.cost.power or 0)};
{label = 'Assemble', n = job.timeLeft, color=lib.color(1,.2,0);
total = scm.sw.input.time and scm.sw.input.time.print or 0};
{label = 'Numenize', n = job.numinaLeft, color=lib.color(1,0,1);
total = scm.sw.cost and scm.sw.cost.numina or 0};
}
local bar = {kind = 'hbar', text = 'Complete', fac=1, w=5-1.5, h = .5}
for i, s in ipairs(steps) do
if s.n > 0 then
local pct = 1 - s.n/s.total
bar.color = s.color
bar.fac = pct
bar.text = string.format("%s %s%%", s.label, math.floor(pct*100))
break
end
end
local out = ItemStack(scm.sw.output)
table.insert(queue, {kind='hztl'; w=6, h=1.5;
{kind = 'contact', w=1.5,h=1.5, id=string.format('cancel_%s', i), item = out};
{kind = 'vert', w=6-1.5, h=1.5;
{kind = 'label', text=out:get_definition().short_description, w=6-1.5, h=.75};
bar;
}
})
end
::badJob::
end
return starlit.ui.build {
kind = 'hztl', padding = 0.5; w = 22, h = 11, mode = 'sw';
{kind = 'vert', w = 5, h = 15;
{kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><left>Recent Prints</left></b>'};
recentList;
};
{kind = 'vert', w = 12, h = 11;
{kind = 'hbar', fac=0, w = 12, h = .5, text = '<b>Program Select</b>'};
{kind = 'pane', w = 12, h = 10.5, id='pgmSelect';
pgmSelector
};
};
{kind = 'vert', w = 5, h = 11;
{kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><right>Print Queue</right></b>'};
queue;
};
}
end;
};
};
})
|