Files
adaptive-music/tests/browser/setup.html
T
Jason 357c904d1b
Validate and generate manual release / package (push) Waiting to run
Adaptive Music v0.8.1 combat automation fixes
2026-12-05 13:37:05 -05:00

32 lines
3.4 KiB
HTML

<!doctype html><meta charset="utf-8"><title>Adaptive Music setup fixture</title>
<link rel="stylesheet" href="/styles/adaptive-music.css">
<style>body{font:16px system-ui;background:#222;color:#eee;margin:2rem auto;max-width:640px}input,select,button{font:inherit;padding:.4rem;box-sizing:border-box}button{cursor:pointer}a{color:#9bd}</style>
<section id="adaptive-music-setup"><main id="app" class="window-content"></main></section>
<script type="module">
import {createSetupClass,createListenerClass} from '/src/foundry/setup.mjs';
import {startConfigurationInterfaces} from '/src/foundry/configuration.mjs';
let flag={},catalog=[];const settings={ownedPlaylistIds:'native',musicDefaults:{},enabled:false,advancedDevelopment:false};
const collection=items=>{const map=new Map(items.map(x=>[x.id,x]));map[Symbol.iterator]=function*(){yield*map.values()};return map};
const scene={id:'scene',name:'Moonlit forest',documentName:'Scene',active:true,getFlag:()=>flag,setFlag:async(ns,k,v)=>{flag=v;window.saved=flag}};
const game={user:{isGM:true},settings:{get:(ns,k)=>settings[k],set:async(ns,k,v)=>{settings[k]=v}},playlists:collection([{id:'native',name:'Foundry fallback'}]),scenes:collection([scene]),combats:[]};
let trackState='playing',position=12,repeat='off';window.controlActions=[];
const connection={status:{state:'disconnected',catalog:0,audioContext:'closed'},open:async p=>{if(p.token!=='fixture-token')throw {code:'ws-upgrade-failed',stage:'API authentication',detail:p.token};catalog=[{provider:'ma',id:'ambient',kind:'playlist',name:'Forest at night'},{provider:'ma',id:'combat',kind:'playlist',name:'Battle drums'}];connection.status={state:'connected',catalog:2,audioContext:'running',hasPrivateDraft:true,peers:2}},refresh:async()=>{},resume:async()=>{},disconnect:async()=>{},playback:async()=>({source:'Music Assistant',state:trackState,title:'Forest at night',position,duration:90,repeat}),
control:async(action,value)=>{window.controlActions.push(action);if(action==='seek')position=value;else if(action==='repeat')repeat=value;else trackState={pause:'paused',resume:'playing',stop:'idle'}[action];},setVolume:value=>{connection.status.volume=value;}};
const Setup=createSetupClass({game,connection,getChoices:async()=>[{provider:'native',id:'native',name:'Foundry fallback'},...catalog],start(){},stop(){},setOverrides(){},onError(){},Base:class{}});
document.querySelector('#app').append(await new Setup()._renderHTML());window.ready=true;
window.nativeConfiguration=async()=>{
const callbacks=new Map();
const Hooks={on:(event,callback)=>callbacks.set(event,callback),off:event=>callbacks.delete(event)};
const directory=document.createElement('aside'),sheet=document.createElement('section');
directory.id='fixture-playlists';sheet.id='fixture-scene';document.body.append(directory,sheet);
const interfaces=startConfigurationInterfaces({game,Hooks,getChoices:()=>catalog,onError(error){throw error;}});
await callbacks.get('renderPlaylistDirectory')({},directory);
window.refreshNativeConfiguration=async()=>{
await interfaces.refreshDirectory({element:directory});
await callbacks.get('renderSceneConfig')({document:scene},sheet);
};
window.closeNativeConfiguration=()=>{interfaces.dispose();directory.remove();sheet.remove();};
};
window.listener=async()=>{const Listener=createListenerClass({game,audio:{stop(){}},resumeListener:()=>{window.activated=true},Base:class{}});document.querySelector('#app').replaceChildren(await new Listener()._renderHTML())};
</script>