1
0
Fork 0

feat: sketch out config, label interfaces

This commit is contained in:
ssube 2020-08-11 19:14:42 -05:00
parent 622617f765
commit efb294e1cc
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
8 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md)
## cautious-journey package
## Functions
| Function | Description |
| --- | --- |
| [resolveLabels(options)](./cautious-journey.resolvelabels.md) | |

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [resolveLabels](./cautious-journey.resolvelabels.md)
## resolveLabels() function
<b>Signature:</b>
```typescript
export declare function resolveLabels(options: ResolveInput): ResolveResult;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | ResolveInput | |
<b>Returns:</b>
ResolveResult

12
docs/api/index.md Normal file
View File

@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md)
## API Reference
## Packages
| Package | Description |
| --- | --- |
| [cautious-journey](./cautious-journey.md) | |

34
src/config.ts Normal file
View File

@ -0,0 +1,34 @@
import { FlagLabel, StateLabel } from './labels';
/**
* Config data for the app, loaded from CLI or DOM.
*/
export interface ConfigData {
/**
* Color palette for labels without their own.
*/
colors: Array<string>;
/**
* Individual flag labels.
*/
flags: Array<FlagLabel>;
/**
* Grouped state labels.
*/
states: Array<StateLabel>;
}
/**
* Load the config from files or the hosting webpage.
*
* @todo
*/
export function initConfig(): ConfigData {
return {
colors: [],
flags: [],
states: [],
};
}

38
src/index.html Normal file
View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Mummies Took My Brunch</title>
<link rel="icon" href="images/mummy.png" />
<link rel="stylesheet" type="text/css" href="styles/main.css" media="screen" />
<link rel="stylesheet" type="text/css" href="styles/themes.css" media="screen" />
</head>
<body class="theme-desert viewport">
<div id="app-container"></div>
<script type="module">
import { main } from './main.js';
main([
'--config-name', 'mtmb-config',
'--config-path', 'data',
'--game', 'phaser-game-controller',
]).then((status) => {
console.log('exited', status);
});
</script>
<script type="application/yaml" id="data-mtmb-config">
game:
dimensions:
x: 1024
y: 768
parent: game-viewport
title: Mummies Took My Brunch
logger:
level: info
name: mtmb
resources:
resources:
- key: base
path: base.yml
</script>
</body>
</html>

1
src/index.ts Normal file
View File

@ -0,0 +1 @@
export { resolveLabels } from './resolve';

73
src/labels.ts Normal file
View File

@ -0,0 +1,73 @@
/**
* A reference to another label.
*/
export interface LabelRef {
name: string;
}
/**
* A set of labels to add and/or remove.
*/
export interface LabelSet {
adds: Array<LabelRef>;
removes: Array<LabelRef>;
}
/**
* Common fields for all labels.
*/
export interface BaseLabel {
/**
* Label name.
*/
name: string;
/**
* Display color.
*/
color?: string;
/**
*
*/
desc?: string;
priority: number;
requires: Array<unknown>;
}
/**
* Individual labels: the equivalent of a checkbox.
*/
export interface FlagLabel extends BaseLabel, LabelSet {
/* empty */
}
/**
* The transition between two state values.
*/
export interface StateChange extends LabelSet {
/**
* Required labels for this state change to occur.
*/
matches: Array<LabelRef>;
}
/**
* One of many values for a particular state.
*/
export interface StateValue extends BaseLabel {
/**
* State changes that could occur to this value.
*/
becomes: Array<StateChange>;
}
/**
* Grouped labels: the equivalent of a radio group.
*/
export interface StateLabel extends BaseLabel, LabelSet {
/**
* Values for this state.
*/
values: Array<StateValue>;
}

68
src/resolve.ts Normal file
View File

@ -0,0 +1,68 @@
import { ConfigData } from './config';
/**
* How a label changed.
*/
export enum ChangeEffect {
EXISTING = 'existing',
CREATED = 'created',
REMOVED = 'removed',
}
/**
* Details of a label change.
*/
export interface ChangeRecord {
cause: string;
effect: ChangeEffect;
label: string;
}
/**
* Collected inputs for a resolver run.
*/
export interface ResolveInput {
config: ConfigData;
issue: string;
labels: Array<string>;
}
/**
* Collected results from a resolver run.
*/
export interface ResolveResult {
changes: Array<ChangeRecord>;
errors: Array<unknown>;
labels: Array<string>;
}
export function resolveLabels(options: ResolveInput): ResolveResult {
const activeLabels = new Set(options.labels);
const sortedFlags = options.config.flags.sort((a, b) => a.priority - b.priority);
for (const flag of sortedFlags) {
const { name } = flag;
if (activeLabels.has(name)) {
// TODO: check removes
// TODO: check requires
}
}
const sortedStates = options.config.states.sort((a, b) => a.priority - b.priority);
for (const state of sortedStates) {
for (const value of state.values) {
const name = `${state.name}/${value.name}`;
if (activeLabels.has(name)) {
// TODO: check removes
// TODO: check requires
// TODO: check becomes
}
}
}
return {
changes: [],
errors: [],
labels: Array.from(activeLabels),
};
}