starlit  Diff

Differences From Artifact [6c49562563]:

To Artifact [e3ed80cb5c]:


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
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
end

local function abilityMenu(a)
	-- select primary/secondary abilities or activate ritual abilities
	local p = {kind = 'vert'}
	for _, o in ipairs(a.order) do
		local m = a.menu[o]
		table.insert(p, {kind='label', text=m.label, w=a.w, h = .5})
		table.insert(p, wrapMenu(a.w, a.h, 1.2, 2, m.opts))
	end
	return p
end

local function pptrMatch(a,b)
	if a == nil or b == nil then return false end
................................................................................
					return true
				end
			end;
		};
	};
})


starlit.interface.install(starlit.type.ui {
	id = 'starlit:compile-matter-component';









	pages = {
		index = {
			setupState = function(state, user, ctx)



				if ctx.context == 'suit' then












				end
				state.pgm = ctx.program
			end;



























































			render = function(state, user)






























































































				return starlit.ui.build {
					kind = 'vert', padding = 0.5; w = 5, h = 5, mode = 'sw';
					{kind = 'label', w = 4, h = 1, text = 'hello'};












				}
			end;
		};
	};
})







|







 







>


>
>
>
>
>
>
>
>
>



>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
|
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
<
>
>
>
>
>
>
>
>
>
>
>
>





118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
end

local function abilityMenu(a)
	-- select primary/secondary abilities or activate ritual abilities
	local p = {kind = 'vert'}
	for _, o in ipairs(a.order) do
		local m = a.menu[o]
		table.insert(p, {kind='hbar', fac=0.5, text=string.format("<b>%s</b>",m.label), w=a.w, h = .5})
		table.insert(p, wrapMenu(a.w, a.h, 1.2, 2, m.opts))
	end
	return p
end

local function pptrMatch(a,b)
	if a == nil or b == nil then return false end
................................................................................
					return true
				end
			end;
		};
	};
})

-- TODO destroy suit interfaces when power runs out or suit/chip is otherwise disabled
starlit.interface.install(starlit.type.ui {
	id = 'starlit:compile-matter-component';
	sub = {
		suit = function(state, user, evt)
			if evt.kind == 'disrobe' then state:close()
			elseif evt.kind == 'power' and evt.mode == 'off' then state:close() end
		end;
		playerInventory = function(state,user)
			-- refresh
		end;
	};
	pages = {
		index = {
			setupState = function(state, user, ctx)
				state.pgm = ctx.program
				state.select = {}
				local E = starlit.mod.electronics
				if ctx.context == 'suit' then
					state.fetch = function()
						local cst = user.entity:get_inventory():get_list 'starlit_suit_chips'
						local cl = {order={}, map={}}
						for i, c in ipairs(cst) do
							if not c:is_empty() then
								local d = E.chip.read(c)
								local co = {
									stack = c;
									data = d;
								}
								table.insert(cl.order, co)
								cl.map[d.uuid] = co
							end

						end
						if state.select.chip and not cl.map[state.select.chip.data.uuid] then
							-- chip no longer available
							user:suitSound 'starlit-error'
							state.select = {}
						end
						state.select.chips = cl

						state.select.scms = {}
						if state.select.chip then
							state.select.scms = E.chip.usableSoftware({state.select.chip.stack},nil,
								function(s) return s.sw.kind == 'schematic' end)
						end
					end
				end
			end;

			onClose = function(state, user)
				user:suitSound 'starlit-quit'
			end;
			handle = function(state, user, q)
				local sel = state.select
				state.fetch()
				local chips = state.select.chips
				local function chirp()
					user:suitSound 'starlit-nav'
				end
				local function onPickChip(chip)
					chirp()
					sel.chip = chip
					return true
				end
				local function onPickScm(scm)
					chirp()
					sel.scm = scm
					return true
				end

				if sel.chip == nil then
					for k in next, q do
						local id = k:match "^chip_(%d+)$"
						if id then
							local cm = chips.map[tonumber(id)]
							if cm then return onPickChip(cm) end
						end
					end
				elseif sel.scm == nil then
					if q.back then chirp() sel.chip = nil return true end
					for k in next, q do
						local id = k:match "^scm_(%d+)$"
						if id then
							local cm = state.select.scms[tonumber(id)]
							if cm then return onPickScm(cm) end
						end
					end
				else
					if q.back then chirp() sel.scm = nil return true end
				end
			end;

			render = function(state, user)
				local sel, pgmSelector = state.select, {}
				state.fetch()

				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>'..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
				else
					if sel.scm == nil then
						for idx, ent in ipairs(sel.scms) do
							local fab = ItemStack(ent.sw.output):get_definition()._starlit.fab
							if 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 output = ItemStack(sel.scm.sw.output):get_definition()
						local fab = output._starlit.fab
						local sw = sel.scm.sw
						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>', sw.name), w=10-1.2,h=1.2};
						})
						local inputTbl = {kind = 'vert', w=5,h=0;
							{kind = 'hbar', w=5, h=.5, text='Input'}};
						local costTbl = {kind = 'vert', w=5,h=0; spacing=.25;
							{kind = 'hbar', w=5, h=.5, text='Process'}};
						local reqPane = {kind = 'pane', id='reqPane', w=10, h=7;
							{kind = 'hztl', w=10,h=0; inputTbl, costTbl}
						}
						local req = fab:visualize()
						for ci,c in ipairs(req) do
							table.insert(inputTbl, {kind = 'label', w=4.5, h=1, x=.5;
								text=lib.str.capitalize(c.header)});
							for ei,e in ipairs(c.list) do
								table.insert(inputTbl, {kind = 'hztl', w=4, h=.5, x=1;
									{kind='img',   w=.5,h=.5, img=e.img};
									{kind='label', w=3.3,h=.5,x=.2, text=e.label};
								});
							end
						end
						if sw.cost then
							local function pushCost(t, val)
								table.insert(costTbl, {kind='text', w=4.5,h=.5,x=.5;
									text=string.format('<b>%s</b>: %s',t,val);
								})
							end
							if sw.cost.cycles then
								pushCost('Energy', lib.math.siUI('J', sel.scm.powerCost))
								pushCost('Compute', lib.math.siUI({'cycle','cycles'}, sw.cost.cycles, true))
							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='print', label = 'Print ->', w=5,h=1.2, color={hue=120,sat=0,lum=0}};
						})
					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>'};
					};
					{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>'};
					};
				}
			end;
		};
	};
})