boardgame.io
Version:
library for turn-based games
1,938 lines (1,694 loc) • 148 kB
JavaScript
'use strict';
var turnOrder = require('./turn-order-d6c2e620.js');
var flatted = require('flatted');
var ai = require('./ai-1fb7bf89.js');
function noop() { }
const identity = x => x;
function assign(tar, src) {
// @ts-ignore
for (const k in src)
tar[k] = src[k];
return tar;
}
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function subscribe(store, callback) {
const unsub = store.subscribe(callback);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
}
function create_slot(definition, ctx, fn) {
if (definition) {
const slot_ctx = get_slot_context(definition, ctx, fn);
return definition[0](slot_ctx);
}
}
function get_slot_context(definition, ctx, fn) {
return definition[1]
? assign({}, assign(ctx.$$scope.ctx, definition[1](fn ? fn(ctx) : {})))
: ctx.$$scope.ctx;
}
function get_slot_changes(definition, ctx, changed, fn) {
return definition[1]
? assign({}, assign(ctx.$$scope.changed || {}, definition[1](fn ? fn(changed) : {})))
: ctx.$$scope.changed || {};
}
function exclude_internal_props(props) {
const result = {};
for (const k in props)
if (k[0] !== '$')
result[k] = props[k];
return result;
}
const is_client = typeof window !== 'undefined';
let now = is_client
? () => window.performance.now()
: () => Date.now();
let raf = is_client ? cb => requestAnimationFrame(cb) : noop;
const tasks = new Set();
let running = false;
function run_tasks() {
tasks.forEach(task => {
if (!task[0](now())) {
tasks.delete(task);
task[1]();
}
});
running = tasks.size > 0;
if (running)
raf(run_tasks);
}
function loop(fn) {
let task;
if (!running) {
running = true;
raf(run_tasks);
}
return {
promise: new Promise(fulfil => {
tasks.add(task = [fn, fulfil]);
}),
abort() {
tasks.delete(task);
}
};
}
function append(target, node) {
target.appendChild(node);
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
node.parentNode.removeChild(node);
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element(name) {
return document.createElement(name);
}
function svg_element(name) {
return document.createElementNS('http://www.w3.org/2000/svg', name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(' ');
}
function empty() {
return text('');
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function stop_propagation(fn) {
return function (event) {
event.stopPropagation();
// @ts-ignore
return fn.call(this, event);
};
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else
node.setAttribute(attribute, value);
}
function to_number(value) {
return value === '' ? undefined : +value;
}
function children(element) {
return Array.from(element.childNodes);
}
function set_data(text, data) {
data = '' + data;
if (text.data !== data)
text.data = data;
}
function set_input_value(input, value) {
if (value != null || input.value) {
input.value = value;
}
}
function select_option(select, value) {
for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i];
if (option.__value === value) {
option.selected = true;
return;
}
}
}
function select_value(select) {
const selected_option = select.querySelector(':checked') || select.options[0];
return selected_option && selected_option.__value;
}
function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
}
function custom_event(type, detail) {
const e = document.createEvent('CustomEvent');
e.initCustomEvent(type, false, false, detail);
return e;
}
let stylesheet;
let active = 0;
let current_rules = {};
// https://github.com/darkskyapp/string-hash/blob/master/index.js
function hash(str) {
let hash = 5381;
let i = str.length;
while (i--)
hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
return hash >>> 0;
}
function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
const step = 16.666 / duration;
let keyframes = '{\n';
for (let p = 0; p <= 1; p += step) {
const t = a + (b - a) * ease(p);
keyframes += p * 100 + `%{${fn(t, 1 - t)}}\n`;
}
const rule = keyframes + `100% {${fn(b, 1 - b)}}\n}`;
const name = `__svelte_${hash(rule)}_${uid}`;
if (!current_rules[name]) {
if (!stylesheet) {
const style = element('style');
document.head.appendChild(style);
stylesheet = style.sheet;
}
current_rules[name] = true;
stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length);
}
const animation = node.style.animation || '';
node.style.animation = `${animation ? `${animation}, ` : ``}${name} ${duration}ms linear ${delay}ms 1 both`;
active += 1;
return name;
}
function delete_rule(node, name) {
node.style.animation = (node.style.animation || '')
.split(', ')
.filter(name
? anim => anim.indexOf(name) < 0 // remove specific animation
: anim => anim.indexOf('__svelte') === -1 // remove all Svelte animations
)
.join(', ');
if (name && !--active)
clear_rules();
}
function clear_rules() {
raf(() => {
if (active)
return;
let i = stylesheet.cssRules.length;
while (i--)
stylesheet.deleteRule(i);
current_rules = {};
});
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error(`Function called outside component initialization`);
return current_component;
}
function afterUpdate(fn) {
get_current_component().$$.after_update.push(fn);
}
function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}
function createEventDispatcher() {
const component = current_component;
return (type, detail) => {
const callbacks = component.$$.callbacks[type];
if (callbacks) {
// TODO are there situations where events could be dispatched
// in a server (non-DOM) environment?
const event = custom_event(type, detail);
callbacks.slice().forEach(fn => {
fn.call(component, event);
});
}
};
}
function setContext(key, context) {
get_current_component().$$.context.set(key, context);
}
function getContext(key) {
return get_current_component().$$.context.get(key);
}
const dirty_components = [];
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
function flush() {
const seen_callbacks = new Set();
do {
// first, call beforeUpdate functions
// and update components
while (dirty_components.length) {
const component = dirty_components.shift();
set_current_component(component);
update(component.$$);
}
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
callback();
// ...so guard against infinite loops
seen_callbacks.add(callback);
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
}
function update($$) {
if ($$.fragment) {
$$.update($$.dirty);
run_all($$.before_update);
$$.fragment.p($$.dirty, $$.ctx);
$$.dirty = null;
$$.after_update.forEach(add_render_callback);
}
}
let promise;
function wait() {
if (!promise) {
promise = Promise.resolve();
promise.then(() => {
promise = null;
});
}
return promise;
}
function dispatch(node, direction, kind) {
node.dispatchEvent(custom_event(`${direction ? 'intro' : 'outro'}${kind}`));
}
const outroing = new Set();
let outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros // parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach)
block.d(1);
callback();
}
});
block.o(local);
}
}
const null_transition = { duration: 0 };
function create_bidirectional_transition(node, fn, params, intro) {
let config = fn(node, params);
let t = intro ? 0 : 1;
let running_program = null;
let pending_program = null;
let animation_name = null;
function clear_animation() {
if (animation_name)
delete_rule(node, animation_name);
}
function init(program, duration) {
const d = program.b - t;
duration *= Math.abs(d);
return {
a: t,
b: program.b,
d,
duration,
start: program.start,
end: program.start + duration,
group: program.group
};
}
function go(b) {
const { delay = 0, duration = 300, easing = identity, tick = noop, css } = config || null_transition;
const program = {
start: now() + delay,
b
};
if (!b) {
// @ts-ignore todo: improve typings
program.group = outros;
outros.r += 1;
}
if (running_program) {
pending_program = program;
}
else {
// if this is an intro, and there's a delay, we need to do
// an initial tick and/or apply CSS animation immediately
if (css) {
clear_animation();
animation_name = create_rule(node, t, b, duration, delay, easing, css);
}
if (b)
tick(0, 1);
running_program = init(program, duration);
add_render_callback(() => dispatch(node, b, 'start'));
loop(now => {
if (pending_program && now > pending_program.start) {
running_program = init(pending_program, duration);
pending_program = null;
dispatch(node, running_program.b, 'start');
if (css) {
clear_animation();
animation_name = create_rule(node, t, running_program.b, running_program.duration, 0, easing, config.css);
}
}
if (running_program) {
if (now >= running_program.end) {
tick(t = running_program.b, 1 - t);
dispatch(node, running_program.b, 'end');
if (!pending_program) {
// we're done
if (running_program.b) {
// intro — we can tidy up immediately
clear_animation();
}
else {
// outro — needs to be coordinated
if (!--running_program.group.r)
run_all(running_program.group.c);
}
}
running_program = null;
}
else if (now >= running_program.start) {
const p = now - running_program.start;
t = running_program.a + running_program.d * easing(p / running_program.duration);
tick(t, 1 - t);
}
}
return !!(running_program || pending_program);
});
}
}
return {
run(b) {
if (is_function(config)) {
wait().then(() => {
// @ts-ignore
config = config();
go(b);
});
}
else {
go(b);
}
},
end() {
clear_animation();
running_program = pending_program = null;
}
};
}
const globals = (typeof window !== 'undefined' ? window : global);
function get_spread_update(levels, updates) {
const update = {};
const to_null_out = {};
const accounted_for = { $$scope: 1 };
let i = levels.length;
while (i--) {
const o = levels[i];
const n = updates[i];
if (n) {
for (const key in o) {
if (!(key in n))
to_null_out[key] = 1;
}
for (const key in n) {
if (!accounted_for[key]) {
update[key] = n[key];
accounted_for[key] = 1;
}
}
levels[i] = n;
}
else {
for (const key in o) {
accounted_for[key] = 1;
}
}
}
for (const key in to_null_out) {
if (!(key in update))
update[key] = undefined;
}
return update;
}
function get_spread_object(spread_props) {
return typeof spread_props === 'object' && spread_props !== null ? spread_props : {};
}
function mount_component(component, target, anchor) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment.m(target, anchor);
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = on_mount.map(run).filter(is_function);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
if (component.$$.fragment) {
run_all(component.$$.on_destroy);
component.$$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
component.$$.on_destroy = component.$$.fragment = null;
component.$$.ctx = {};
}
}
function make_dirty(component, key) {
if (!component.$$.dirty) {
dirty_components.push(component);
schedule_update();
component.$$.dirty = blank_object();
}
component.$$.dirty[key] = true;
}
function init(component, options, instance, create_fragment, not_equal, prop_names) {
const parent_component = current_component;
set_current_component(component);
const props = options.props || {};
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props: prop_names,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : []),
// everything else
callbacks: blank_object(),
dirty: null
};
let ready = false;
$$.ctx = instance
? instance(component, props, (key, ret, value = ret) => {
if ($$.ctx && not_equal($$.ctx[key], $$.ctx[key] = value)) {
if ($$.bound[key])
$$.bound[key](value);
if (ready)
make_dirty(component, key);
}
return ret;
})
: props;
$$.update();
ready = true;
run_all($$.before_update);
$$.fragment = create_fragment($$.ctx);
if (options.target) {
if (options.hydrate) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment.l(children(options.target));
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor);
flush();
}
set_current_component(parent_component);
}
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set() {
// overridden by instance, if it has props
}
}
const subscriber_queue = [];
/**
* Create a `Writable` store that allows both updating and reading by subscription.
* @param {*=}value initial value
* @param {StartStopNotifier=}start start and stop notifications for subscriptions
*/
function writable(value, start = noop) {
let stop;
const subscribers = [];
function set(new_value) {
if (safe_not_equal(value, new_value)) {
value = new_value;
if (stop) { // store is ready
const run_queue = !subscriber_queue.length;
for (let i = 0; i < subscribers.length; i += 1) {
const s = subscribers[i];
s[1]();
subscriber_queue.push(s, value);
}
if (run_queue) {
for (let i = 0; i < subscriber_queue.length; i += 2) {
subscriber_queue[i][0](subscriber_queue[i + 1]);
}
subscriber_queue.length = 0;
}
}
}
}
function update(fn) {
set(fn(value));
}
function subscribe(run, invalidate = noop) {
const subscriber = [run, invalidate];
subscribers.push(subscriber);
if (subscribers.length === 1) {
stop = start(set) || noop;
}
run(value);
return () => {
const index = subscribers.indexOf(subscriber);
if (index !== -1) {
subscribers.splice(index, 1);
}
if (subscribers.length === 0) {
stop();
stop = null;
}
};
}
return { set, update, subscribe };
}
function cubicOut(t) {
const f = t - 1.0;
return f * f * f + 1.0;
}
function fly(node, { delay = 0, duration = 400, easing = cubicOut, x = 0, y = 0, opacity = 0 }) {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const transform = style.transform === 'none' ? '' : style.transform;
const od = target_opacity * (1 - opacity);
return {
delay,
duration,
easing,
css: (t, u) => `
transform: ${transform} translate(${(1 - t) * x}px, ${(1 - t) * y}px);
opacity: ${target_opacity - (od * u)}`
};
}
/* src/client/debug/Menu.svelte generated by Svelte v3.12.1 */
function add_css() {
var style = element("style");
style.id = 'svelte-19bfq8g-style';
style.textContent = ".menu.svelte-19bfq8g{display:flex;margin-top:-10px;flex-direction:row;border:1px solid #ccc;border-radius:5px 5px 0 0;height:25px;line-height:25px;margin-right:-500px;transform-origin:bottom right;transform:rotate(-90deg) translate(0, -500px)}.menu-item.svelte-19bfq8g{line-height:25px;cursor:pointer;background:#fefefe;color:#555;padding-left:15px;padding-right:15px;text-align:center}.menu-item.svelte-19bfq8g:last-child{border-radius:0 5px 0 0}.menu-item.svelte-19bfq8g:first-child{border-radius:5px 0 0 0}.menu-item.active.svelte-19bfq8g{cursor:default;font-weight:bold;background:#ddd;color:#555}.menu-item.svelte-19bfq8g:hover{background:#ddd;color:#555}";
append(document.head, style);
}
function get_each_context(ctx, list, i) {
const child_ctx = Object.create(ctx);
child_ctx.key = list[i][0];
child_ctx.label = list[i][1].label;
return child_ctx;
}
// (55:2) {#each Object.entries(panes).reverse() as [key, {label}
function create_each_block(ctx) {
var div, t0_value = ctx.label + "", t0, t1, dispose;
function click_handler() {
return ctx.click_handler(ctx);
}
return {
c() {
div = element("div");
t0 = text(t0_value);
t1 = space();
attr(div, "class", "menu-item svelte-19bfq8g");
toggle_class(div, "active", ctx.pane == ctx.key);
dispose = listen(div, "click", click_handler);
},
m(target, anchor) {
insert(target, div, anchor);
append(div, t0);
append(div, t1);
},
p(changed, new_ctx) {
ctx = new_ctx;
if ((changed.panes) && t0_value !== (t0_value = ctx.label + "")) {
set_data(t0, t0_value);
}
if ((changed.pane || changed.panes)) {
toggle_class(div, "active", ctx.pane == ctx.key);
}
},
d(detaching) {
if (detaching) {
detach(div);
}
dispose();
}
};
}
function create_fragment(ctx) {
var div;
let each_value = Object.entries(ctx.panes).reverse();
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
}
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(div, "class", "menu svelte-19bfq8g");
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div, null);
}
},
p(changed, ctx) {
if (changed.pane || changed.panes) {
each_value = Object.entries(ctx.panes).reverse();
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(changed, child_ctx);
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
each_blocks[i].m(div, null);
}
}
for (; i < each_blocks.length; i += 1) {
each_blocks[i].d(1);
}
each_blocks.length = each_value.length;
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(div);
}
destroy_each(each_blocks, detaching);
}
};
}
function instance($$self, $$props, $$invalidate) {
let { pane, panes } = $$props;
const dispatch = createEventDispatcher();
const click_handler = ({ key }) => dispatch('change', key);
$$self.$set = $$props => {
if ('pane' in $$props) $$invalidate('pane', pane = $$props.pane);
if ('panes' in $$props) $$invalidate('panes', panes = $$props.panes);
};
return { pane, panes, dispatch, click_handler };
}
class Menu extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-19bfq8g-style")) add_css();
init(this, options, instance, create_fragment, safe_not_equal, ["pane", "panes"]);
}
}
/* src/client/debug/main/Hotkey.svelte generated by Svelte v3.12.1 */
function add_css$1() {
var style = element("style");
style.id = 'svelte-1olzq4i-style';
style.textContent = ".key.svelte-1olzq4i{display:flex;flex-direction:row;align-items:center}.key-box.svelte-1olzq4i{cursor:pointer;min-width:10px;padding-left:5px;padding-right:5px;height:20px;line-height:20px;text-align:center;border:1px solid #ccc;box-shadow:1px 1px 1px #888;background:#eee;color:#444}.key-box.svelte-1olzq4i:hover{background:#ddd}.key.active.svelte-1olzq4i .key-box.svelte-1olzq4i{background:#ddd;border:1px solid #999;box-shadow:none}.label.svelte-1olzq4i{margin-left:10px}";
append(document.head, style);
}
// (77:2) {#if label}
function create_if_block(ctx) {
var div, t;
return {
c() {
div = element("div");
t = text(ctx.label);
attr(div, "class", "label svelte-1olzq4i");
},
m(target, anchor) {
insert(target, div, anchor);
append(div, t);
},
p(changed, ctx) {
if (changed.label) {
set_data(t, ctx.label);
}
},
d(detaching) {
if (detaching) {
detach(div);
}
}
};
}
function create_fragment$1(ctx) {
var div1, div0, t0, t1, dispose;
var if_block = (ctx.label) && create_if_block(ctx);
return {
c() {
div1 = element("div");
div0 = element("div");
t0 = text(ctx.value);
t1 = space();
if (if_block) if_block.c();
attr(div0, "class", "key-box svelte-1olzq4i");
attr(div1, "class", "key svelte-1olzq4i");
toggle_class(div1, "active", ctx.active);
dispose = [
listen(window, "keydown", ctx.Keypress),
listen(div0, "click", ctx.Activate)
];
},
m(target, anchor) {
insert(target, div1, anchor);
append(div1, div0);
append(div0, t0);
append(div1, t1);
if (if_block) if_block.m(div1, null);
},
p(changed, ctx) {
if (changed.value) {
set_data(t0, ctx.value);
}
if (ctx.label) {
if (if_block) {
if_block.p(changed, ctx);
} else {
if_block = create_if_block(ctx);
if_block.c();
if_block.m(div1, null);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
if (changed.active) {
toggle_class(div1, "active", ctx.active);
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(div1);
}
if (if_block) if_block.d();
run_all(dispose);
}
};
}
function instance$1($$self, $$props, $$invalidate) {
let $disableHotkeys;
let { value, onPress = null, label = null, disable = false } = $$props;
const { disableHotkeys } = getContext('hotkeys'); component_subscribe($$self, disableHotkeys, $$value => { $disableHotkeys = $$value; $$invalidate('$disableHotkeys', $disableHotkeys); });
let active = false;
function Deactivate() {
$$invalidate('active', active = false);
}
function Activate() {
$$invalidate('active', active = true);
setTimeout(Deactivate, 200);
if (onPress) {
setTimeout(onPress, 1);
}
}
function Keypress(e) {
if (
!$disableHotkeys && !disable &&
!e.ctrlKey && !e.metaKey &&
e.key == value
) {
e.preventDefault();
Activate();
}
}
$$self.$set = $$props => {
if ('value' in $$props) $$invalidate('value', value = $$props.value);
if ('onPress' in $$props) $$invalidate('onPress', onPress = $$props.onPress);
if ('label' in $$props) $$invalidate('label', label = $$props.label);
if ('disable' in $$props) $$invalidate('disable', disable = $$props.disable);
};
return {
value,
onPress,
label,
disable,
disableHotkeys,
active,
Activate,
Keypress
};
}
class Hotkey extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-1olzq4i-style")) add_css$1();
init(this, options, instance$1, create_fragment$1, safe_not_equal, ["value", "onPress", "label", "disable"]);
}
}
/* src/client/debug/main/InteractiveFunction.svelte generated by Svelte v3.12.1 */
function add_css$2() {
var style = element("style");
style.id = 'svelte-1mppqmp-style';
style.textContent = ".move.svelte-1mppqmp{display:flex;flex-direction:row;cursor:pointer;margin-left:10px;color:#666}.move.svelte-1mppqmp:hover{color:#333}.move.active.svelte-1mppqmp{color:#111;font-weight:bold}.arg-field.svelte-1mppqmp{outline:none;font-family:monospace}";
append(document.head, style);
}
function create_fragment$2(ctx) {
var div, span0, t0, t1, span1, t3, span2, t4, span3, dispose;
return {
c() {
div = element("div");
span0 = element("span");
t0 = text(ctx.name);
t1 = space();
span1 = element("span");
span1.textContent = "(";
t3 = space();
span2 = element("span");
t4 = space();
span3 = element("span");
span3.textContent = ")";
attr(span2, "class", "arg-field svelte-1mppqmp");
attr(span2, "contenteditable", "");
attr(div, "class", "move svelte-1mppqmp");
toggle_class(div, "active", ctx.active);
dispose = [
listen(span2, "blur", ctx.Deactivate),
listen(span2, "keypress", stop_propagation(keypress_handler)),
listen(span2, "keydown", ctx.OnKeyDown),
listen(div, "click", ctx.Activate)
];
},
m(target, anchor) {
insert(target, div, anchor);
append(div, span0);
append(span0, t0);
append(div, t1);
append(div, span1);
append(div, t3);
append(div, span2);
ctx.span2_binding(span2);
append(div, t4);
append(div, span3);
},
p(changed, ctx) {
if (changed.name) {
set_data(t0, ctx.name);
}
if (changed.active) {
toggle_class(div, "active", ctx.active);
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(div);
}
ctx.span2_binding(null);
run_all(dispose);
}
};
}
const keypress_handler = () => {};
function instance$2($$self, $$props, $$invalidate) {
let { Activate, Deactivate, name, active } = $$props;
let span;
const dispatch = createEventDispatcher();
function Submit() {
try {
const value = span.innerText;
let argArray = new Function(`return [${value}]`)();
dispatch('submit', argArray);
} catch (error) {
dispatch('error', error);
}
$$invalidate('span', span.innerText = '', span);
}
function OnKeyDown(e) {
if (e.key == 'Enter') {
e.preventDefault();
Submit();
}
if (e.key == 'Escape') {
e.preventDefault();
Deactivate();
}
}
afterUpdate(() => {
if (active) {
span.focus();
} else {
span.blur();
}
});
function span2_binding($$value) {
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
$$invalidate('span', span = $$value);
});
}
$$self.$set = $$props => {
if ('Activate' in $$props) $$invalidate('Activate', Activate = $$props.Activate);
if ('Deactivate' in $$props) $$invalidate('Deactivate', Deactivate = $$props.Deactivate);
if ('name' in $$props) $$invalidate('name', name = $$props.name);
if ('active' in $$props) $$invalidate('active', active = $$props.active);
};
return {
Activate,
Deactivate,
name,
active,
span,
OnKeyDown,
span2_binding
};
}
class InteractiveFunction extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-1mppqmp-style")) add_css$2();
init(this, options, instance$2, create_fragment$2, safe_not_equal, ["Activate", "Deactivate", "name", "active"]);
}
}
/* src/client/debug/main/Move.svelte generated by Svelte v3.12.1 */
function add_css$3() {
var style = element("style");
style.id = 'svelte-smqssc-style';
style.textContent = ".move-error.svelte-smqssc{color:#a00;font-weight:bold}.wrapper.svelte-smqssc{display:flex;flex-direction:row;align-items:center}";
append(document.head, style);
}
// (65:2) {#if error}
function create_if_block$1(ctx) {
var span, t;
return {
c() {
span = element("span");
t = text(ctx.error);
attr(span, "class", "move-error svelte-smqssc");
},
m(target, anchor) {
insert(target, span, anchor);
append(span, t);
},
p(changed, ctx) {
if (changed.error) {
set_data(t, ctx.error);
}
},
d(detaching) {
if (detaching) {
detach(span);
}
}
};
}
function create_fragment$3(ctx) {
var div1, div0, t0, t1, current;
var hotkey = new Hotkey({
props: { value: ctx.shortcut, onPress: ctx.Activate }
});
var interactivefunction = new InteractiveFunction({
props: {
Activate: ctx.Activate,
Deactivate: ctx.Deactivate,
name: ctx.name,
active: ctx.active
}
});
interactivefunction.$on("submit", ctx.Submit);
interactivefunction.$on("error", ctx.Error);
var if_block = (ctx.error) && create_if_block$1(ctx);
return {
c() {
div1 = element("div");
div0 = element("div");
hotkey.$$.fragment.c();
t0 = space();
interactivefunction.$$.fragment.c();
t1 = space();
if (if_block) if_block.c();
attr(div0, "class", "wrapper svelte-smqssc");
},
m(target, anchor) {
insert(target, div1, anchor);
append(div1, div0);
mount_component(hotkey, div0, null);
append(div0, t0);
mount_component(interactivefunction, div0, null);
append(div1, t1);
if (if_block) if_block.m(div1, null);
current = true;
},
p(changed, ctx) {
var hotkey_changes = {};
if (changed.shortcut) hotkey_changes.value = ctx.shortcut;
hotkey.$set(hotkey_changes);
var interactivefunction_changes = {};
if (changed.name) interactivefunction_changes.name = ctx.name;
if (changed.active) interactivefunction_changes.active = ctx.active;
interactivefunction.$set(interactivefunction_changes);
if (ctx.error) {
if (if_block) {
if_block.p(changed, ctx);
} else {
if_block = create_if_block$1(ctx);
if_block.c();
if_block.m(div1, null);
}
} else if (if_block) {
if_block.d(1);
if_block = null;
}
},
i(local) {
if (current) return;
transition_in(hotkey.$$.fragment, local);
transition_in(interactivefunction.$$.fragment, local);
current = true;
},
o(local) {
transition_out(hotkey.$$.fragment, local);
transition_out(interactivefunction.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) {
detach(div1);
}
destroy_component(hotkey);
destroy_component(interactivefunction);
if (if_block) if_block.d();
}
};
}
function instance$3($$self, $$props, $$invalidate) {
let { shortcut, name, fn } = $$props;
const {disableHotkeys} = getContext('hotkeys');
let error = '';
let active = false;
function Activate() {
disableHotkeys.set(true);
$$invalidate('active', active = true);
}
function Deactivate() {
disableHotkeys.set(false);
$$invalidate('error', error = '');
$$invalidate('active', active = false);
}
function Submit(e) {
$$invalidate('error', error = '');
Deactivate();
fn.apply(this, e.detail);
}
function Error(e) {
$$invalidate('error', error = e.detail);
turnOrder.error(e.detail);
}
$$self.$set = $$props => {
if ('shortcut' in $$props) $$invalidate('shortcut', shortcut = $$props.shortcut);
if ('name' in $$props) $$invalidate('name', name = $$props.name);
if ('fn' in $$props) $$invalidate('fn', fn = $$props.fn);
};
return {
shortcut,
name,
fn,
error,
active,
Activate,
Deactivate,
Submit,
Error
};
}
class Move extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-smqssc-style")) add_css$3();
init(this, options, instance$3, create_fragment$3, safe_not_equal, ["shortcut", "name", "fn"]);
}
}
/* src/client/debug/main/Controls.svelte generated by Svelte v3.12.1 */
function add_css$4() {
var style = element("style");
style.id = 'svelte-1x2w9i0-style';
style.textContent = "li.svelte-1x2w9i0{list-style:none;margin:none;margin-bottom:5px}";
append(document.head, style);
}
function create_fragment$4(ctx) {
var section, li0, t0, li1, t1, li2, t2, li3, current;
var hotkey0 = new Hotkey({
props: {
value: "1",
onPress: ctx.client.reset,
label: "reset"
}
});
var hotkey1 = new Hotkey({
props: {
value: "2",
onPress: ctx.Save,
label: "save"
}
});
var hotkey2 = new Hotkey({
props: {
value: "3",
onPress: ctx.Restore,
label: "restore"
}
});
var hotkey3 = new Hotkey({
props: {
value: ".",
disable: true,
label: "hide"
}
});
return {
c() {
section = element("section");
li0 = element("li");
hotkey0.$$.fragment.c();
t0 = space();
li1 = element("li");
hotkey1.$$.fragment.c();
t1 = space();
li2 = element("li");
hotkey2.$$.fragment.c();
t2 = space();
li3 = element("li");
hotkey3.$$.fragment.c();
attr(li0, "class", "svelte-1x2w9i0");
attr(li1, "class", "svelte-1x2w9i0");
attr(li2, "class", "svelte-1x2w9i0");
attr(li3, "class", "svelte-1x2w9i0");
attr(section, "id", "debug-controls");
attr(section, "class", "controls");
},
m(target, anchor) {
insert(target, section, anchor);
append(section, li0);
mount_component(hotkey0, li0, null);
append(section, t0);
append(section, li1);
mount_component(hotkey1, li1, null);
append(section, t1);
append(section, li2);
mount_component(hotkey2, li2, null);
append(section, t2);
append(section, li3);
mount_component(hotkey3, li3, null);
current = true;
},
p(changed, ctx) {
var hotkey0_changes = {};
if (changed.client) hotkey0_changes.onPress = ctx.client.reset;
hotkey0.$set(hotkey0_changes);
},
i(local) {
if (current) return;
transition_in(hotkey0.$$.fragment, local);
transition_in(hotkey1.$$.fragment, local);
transition_in(hotkey2.$$.fragment, local);
transition_in(hotkey3.$$.fragment, local);
current = true;
},
o(local) {
transition_out(hotkey0.$$.fragment, local);
transition_out(hotkey1.$$.fragment, local);
transition_out(hotkey2.$$.fragment, local);
transition_out(hotkey3.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) {
detach(section);
}
destroy_component(hotkey0);
destroy_component(hotkey1);
destroy_component(hotkey2);
destroy_component(hotkey3);
}
};
}
function instance$4($$self, $$props, $$invalidate) {
let { client } = $$props;
function Save() {
// get state to persist and overwrite deltalog, _undo, and _redo
const state = client.getState();
const json = flatted.stringify({
...state,
_undo: [],
_redo: [],
deltalog: [],
});
window.localStorage.setItem('gamestate', json);
window.localStorage.setItem('initialState', flatted.stringify(client.initialState));
}
function Restore() {
const gamestateJSON = window.localStorage.getItem('gamestate');
const initialStateJSON = window.localStorage.getItem('initialState');
if (gamestateJSON !== null && initialStateJSON !== null) {
const gamestate = flatted.parse(gamestateJSON);
const initialState = flatted.parse(initialStateJSON);
client.store.dispatch(turnOrder.sync({ state: gamestate, initialState }));
}
}
$$self.$set = $$props => {
if ('client' in $$props) $$invalidate('client', client = $$props.client);
};
return { client, Save, Restore };
}
class Controls extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-1x2w9i0-style")) add_css$4();
init(this, options, instance$4, create_fragment$4, safe_not_equal, ["client"]);
}
}
/* src/client/debug/main/PlayerInfo.svelte generated by Svelte v3.12.1 */
function add_css$5() {
var style = element("style");
style.id = 'svelte-6sf87x-style';
style.textContent = ".player-box.svelte-6sf87x{display:flex;flex-direction:row}.player.svelte-6sf87x{cursor:pointer;text-align:center;width:30px;height:30px;line-height:30px;background:#eee;border:3px solid #fefefe;box-sizing:content-box}.player.current.svelte-6sf87x{background:#555;color:#eee;font-weight:bold}.player.active.svelte-6sf87x{border:3px solid #ff7f50}";
append(document.head, style);
}
function get_each_context$1(ctx, list, i) {
const child_ctx = Object.create(ctx);
child_ctx.player = list[i];
return child_ctx;
}
// (49:2) {#each players as player}
function create_each_block$1(ctx) {
var div, t0_value = ctx.player + "", t0, t1, dispose;
function click_handler() {
return ctx.click_handler(ctx);
}
return {
c() {
div = element("div");
t0 = text(t0_value);
t1 = space();
attr(div, "class", "player svelte-6sf87x");
toggle_class(div, "current", ctx.player == ctx.ctx.currentPlayer);
toggle_class(div, "active", ctx.player == ctx.playerID);
dispose = listen(div, "click", click_handler);
},
m(target, anchor) {
insert(target, div, anchor);
append(div, t0);
append(div, t1);
},
p(changed, new_ctx) {
ctx = new_ctx;
if ((changed.players) && t0_value !== (t0_value = ctx.player + "")) {
set_data(t0, t0_value);
}
if ((changed.players || changed.ctx)) {
toggle_class(div, "current", ctx.player == ctx.ctx.currentPlayer);
}
if ((changed.players || changed.playerID)) {
toggle_class(div, "active", ctx.player == ctx.playerID);
}
},
d(detaching) {
if (detaching) {
detach(div);
}
dispose();
}
};
}
function create_fragment$5(ctx) {
var div;
let each_value = ctx.players;
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
}
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(div, "class", "player-box svelte-6sf87x");
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div, null);
}
},
p(changed, ctx) {
if (changed.players || changed.ctx || changed.playerID) {
each_value = ctx.players;
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$1(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(changed, child_ctx);
} else {
each_blocks[i] = create_each_block$1(child_ctx);
each_blocks[i].c();
each_blocks[i].m(div, null);
}
}
for (; i < each_blocks.length; i += 1) {
each_blocks[i].d(1);
}
each_blocks.length = each_value.length;
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(div);
}
destroy_each(each_blocks, detaching);
}
};
}
function instance$5($$self, $$props, $$invalidate) {
let { ctx, playerID } = $$props;
const dispatch = createEventDispatcher();
function OnClick(player) {
if (player == playerID) {
dispatch("change", { playerID: null });
} else {
dispatch("change", { playerID: player });
}
}
let players;
const click_handler = ({ player }) => OnClick(player);
$$self.$set = $$props => {
if ('ctx' in $$props) $$invalidate('ctx', ctx = $$props.ctx);
if ('playerID' in $$props) $$invalidate('playerID', playerID = $$props.playerID);
};
$$self.$$.update = ($$dirty = { ctx: 1 }) => {
if ($$dirty.ctx) { $$invalidate('players', players = ctx ? [...Array(ctx.numPlayers).keys()].map(i => i.toString()) : []); }
};
return {
ctx,
playerID,
OnClick,
players,
click_handler
};
}
class PlayerInfo extends SvelteComponent {
constructor(options) {
super();
if (!document.getElementById("svelte-6sf87x-style")) add_css$5();
init(this, options, instance$5, create_fragment$5, safe_not_equal, ["ctx", "playerID"]);
}
}
/*
* Copyright 2018 The boardgame.io Authors
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
function AssignShortcuts(moveNames, eventNames, blacklist) {
var shortcuts = {};
var events = {};
for (var name in moveNames) {
events[name] = name;
}
for (var _name in eventNames) {
events[_name] = _name;
}
var taken = {};
for (var i = 0; i < blacklist.length; i++) {
var c = blacklist[i];
taken[c] = true;
} // Try assigning the first char of each move as the shortcut.
var t = taken;
var canUseFirstChar = true;
for (var _name2 in events) {
var shortcut = _name2[0];
if (t[shortcut]) {
canUseFirstChar = false;
break;
}
t[shortcut] = true;
shortcuts[_name2] = shortcut;
}
if (canUseFirstChar) {
return shortcuts;
} // If those aren't unique, use a-z.
t = taken;
var next = 97;
shortcuts = {};
for (var _name3 in events) {
var _shortcut = String.fromCharCode(next);
while (t[_shortcut]) {
next++;
_shortcut = String.fromCharCode(next);
}
t[_shortcut] = true;
shortcuts[_name3] = _shortcut;
}
return shortcuts;
}
/* src/client/debug/main/Main.svelte generated by Svelte v3.12.1 */
function add_css$6() {
var style = element("style");
style.id = 'svelte-1vg2l2b-style';
style.textContent = ".json.svelte-1vg2l2b{font-family:monospace;color:#888}label.svelte-1vg2l2b{font-weight:bold;font-size:1.1em;display:inline}h3.svelte-1vg2l2b{text-transform:uppercase}li.svelte-1vg2l2b{list-style:none;margin:none;margin-bottom:5px}.events.svelte-1vg2l2b{display:flex;flex-direction:column}.events.svelte-1vg2l2b button.svelte-1vg2l2b{width:100px}.events.svelte-1vg2l2b button.svelte-1vg2l2b:not(:last-child){margin-bottom:10px}";
append(document.head, style);
}
function get_each_context$2(ctx, list, i) {
const child_ctx = Object.create(ctx);
child_ctx.name = list[i][0];
child_ctx.fn = list[i][1];
return child_ctx;
}
// (85:2) {#each Object.entries(client.moves) as [name, fn]}
function create_each_block$2(ctx) {
var li, t, current;
var move = new Move({
props: {
shortcut: ctx.shortcuts[ctx.name],
fn: ctx.fn,
name: ctx.name
}
});
return {
c() {
li = element("li");
move.$$.fragment.c();
t = space();
attr(li, "class", "svelte-1vg2l2b");
},
m(target, anchor) {
insert(target, li, anchor);
mount_component(move, li, null);
append(li, t);
current = true;
},
p(changed, ctx) {
var move_changes = {};
if (changed.client) move_changes.shortcut = ctx.shortcuts[ctx.name];
if (changed.client) move_changes.fn = ctx.fn;
if (changed.client) move_changes.name = ctx.name;
move.$set(move_changes);
},
i(local) {
if (current) return;
transition_in(move.$$.fragment, local);
current = true;
},
o(local) {
transition_out(move.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) {
detach(li);
}
destroy_component(move);
}
};
}
// (96:2) {#if client.events.endTurn}
function create_if_block_2(ctx) {
var button, dispose;
return {
c() {
button = element("button");
button.textContent = "End Turn";
attr(button, "class", "svelte-1vg2l2b");
dispose = listen(button, "click", ctx.click_handler);
},
m(target, anchor) {
insert(target, button, anchor);
},
d(detaching) {
if (detaching) {
detach(button);
}
dispose();
}
};
}
// (99:2) {#if ctx.phase && client.events.endPhase}
function create_if_block_1(ctx) {
var button, dispose;
return {
c() {
button = element("button");
button.textContent = "End Phase";
attr(button, "class", "svelte-1vg2l2b");
dispose = listen(button, "click", ctx.click_handler_1);
},
m(target, anchor) {
insert(target, button, anchor);
},
d(detaching) {
if (detaching) {
detach(button);
}
dispose();
}
};
}
// (102:2) {#if ctx.activePlayers && client.events.endStage}
function create_if_block$2(ctx) {
var button, dispose;
return {
c() {
button = element("button");
button.textContent = "End Stage";
attr(button, "class", "svelte-1vg2l2b");
dispose = listen(button, "click", ctx.click_handler_2);
},
m(target, anchor) {
insert(target, button, anchor);
},
d(detaching) {
if (detaching) {
detach(button);
}
dispose();
}
};
}
function create_fragment$6(ctx) {
var section0, h30, t1, t2, section1, h31, t4, t5, section2, h32, t7, t8, section3, h33, t10, div, t11, t12, t13, section4, label0, t15, pre0, t16_value = JSON.stringify(ctx.G, null, 2) + "", t16, t17, section5, label1, t19, pre1, t20_value = JSON.stringify(SanitizeCtx(ctx.ctx), null, 2) + "", t20, current;
var controls = new Controls({ props: { client: ctx.client } });
var playerinfo = new PlayerInfo({
props: {
ctx: ctx.ctx,
playerID: ctx.playerID
}
});
playerinfo.$on("change", ctx.change_handler);
let each_value = Object.entries(ctx.client.moves);
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
}
const out = i => transition_out(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
var if_block0 = (ctx.client.events.endTurn) && create_if_block_2(ctx);
var if_block1 = (ctx.ctx.phase && ctx.client.events.endPhase) && create_if_block_1(c