mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
A renderer's roles: per-layer lighting is part of the look, and roleOf knows only real members
imageryLayer.lit (a layer shaded by the sun) joins the look with surface shading. roleOf answers undefined for a member its port does not have, and the port's own role without a member. The test now fails when two roles claim the same entry.
This commit is contained in:
1 parent
21fdc6a332
commit
46ad53aa35
3 files changed
+22
-7
No files matched your search
@@ -131,6 +131,9 @@ test('PORTS lists every member of every port, required exactly when the type req
|
|||||||
test('every member of every port has one role, and each role names real members', () => {
|
test('every member of every port has one role, and each role names real members', () => {
|
||||||
const ids = ROLES.map((r) => r.id);
|
const ids = ROLES.map((r) => r.id);
|
||||||
assert.equal(new Set(ids).size, ids.length);
|
assert.equal(new Set(ids).size, ids.length);
|
||||||
|
// No entry is claimed by two roles, so the most specific entry is never a tie.
|
||||||
|
const entries = ROLES.flatMap((r) => r.members);
|
||||||
|
assert.equal(new Set(entries).size, entries.length, 'an entry in two roles');
|
||||||
for (const [port, members] of Object.entries(PORTS))
|
for (const [port, members] of Object.entries(PORTS))
|
||||||
for (const member of Object.keys(members))
|
for (const member of Object.keys(members))
|
||||||
assert.ok(
|
assert.ok(
|
||||||
@@ -156,6 +159,9 @@ test('every member of every port has one role, and each role names real members'
|
|||||||
assert.equal(roleOf('globe', 'sky.set'), 'look');
|
assert.equal(roleOf('globe', 'sky.set'), 'look');
|
||||||
assert.equal(roleOf('globe', 'setSurfaceShading'), 'look');
|
assert.equal(roleOf('globe', 'setSurfaceShading'), 'look');
|
||||||
assert.equal(roleOf('nowhere', 'x'), undefined);
|
assert.equal(roleOf('nowhere', 'x'), undefined);
|
||||||
|
assert.equal(roleOf('globe', 'bogus'), undefined);
|
||||||
|
assert.equal(roleOf('globe'), 'surface');
|
||||||
|
assert.equal(roleOf('imageryLayer', 'lit'), 'look');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the capability and frame-step lists are the types’ own', () => {
|
test('the capability and frame-step lists are the types’ own', () => {
|
||||||
|
|||||||
Vendored
+5
-2
@@ -40,10 +40,13 @@ export interface ContractRole {
|
|||||||
/** What a renderer does, by role: every member of {@link PORTS} in one. */
|
/** What a renderer does, by role: every member of {@link PORTS} in one. */
|
||||||
export declare const ROLES: readonly ContractRole[];
|
export declare const ROLES: readonly ContractRole[];
|
||||||
|
|
||||||
/** The role of `port`'s `member` (dotted), or undefined. */
|
/**
|
||||||
|
* The role of `port`'s `member` (dotted), or of the port itself without one;
|
||||||
|
* undefined for a member the port does not have.
|
||||||
|
*/
|
||||||
export declare function roleOf(
|
export declare function roleOf(
|
||||||
port: string,
|
port: string,
|
||||||
member: string,
|
member?: string,
|
||||||
): ContractRole['id'] | undefined;
|
): ContractRole['id'] | undefined;
|
||||||
|
|
||||||
/** Every quality setting a renderer may support. */
|
/** Every quality setting a renderer may support. */
|
||||||
|
|||||||
@@ -350,7 +350,12 @@ export const ROLES = deepFreeze([
|
|||||||
title: 'Look',
|
title: 'Look',
|
||||||
summary:
|
summary:
|
||||||
'How the world is lit and finished: sky and atmosphere, surface shading, styles and screen effects.',
|
'How the world is lit and finished: sky and atmosphere, surface shading, styles and screen effects.',
|
||||||
members: ['effects', 'globe.sky', 'globe.setSurfaceShading'],
|
members: [
|
||||||
|
'effects',
|
||||||
|
'globe.sky',
|
||||||
|
'globe.setSurfaceShading',
|
||||||
|
'imageryLayer.lit',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'host',
|
id: 'host',
|
||||||
@@ -366,11 +371,12 @@ export const ROLES = deepFreeze([
|
|||||||
* The role a member belongs to: the most specific {@link ROLES} entry naming
|
* The role a member belongs to: the most specific {@link ROLES} entry naming
|
||||||
* its port or one of its dotted prefixes.
|
* its port or one of its dotted prefixes.
|
||||||
* @param {string} port
|
* @param {string} port
|
||||||
* @param {string} member dotted, as in {@link PORTS}
|
* @param {string} [member] dotted, as in {@link PORTS}; empty for the port's own role
|
||||||
* @returns {string|undefined} the role's id
|
* @returns {string|undefined} the role's id; undefined for a member the port does not have
|
||||||
*/
|
*/
|
||||||
export function roleOf(port, member) {
|
export function roleOf(port, member = '') {
|
||||||
const parts = member.split('.');
|
if (member && !(PORTS[port] && member in PORTS[port])) return undefined;
|
||||||
|
const parts = member ? member.split('.') : [];
|
||||||
for (let n = parts.length; n >= 0; n--) {
|
for (let n = parts.length; n >= 0; n--) {
|
||||||
const key = [port, ...parts.slice(0, n)].join('.');
|
const key = [port, ...parts.slice(0, n)].join('.');
|
||||||
const role = ROLES.find((r) => r.members.includes(key));
|
const role = ROLES.find((r) => r.members.includes(key));
|
||||||
|
|||||||
Reference in new issue
Block a user