This commit is contained in:
Will Scullin 2022-05-15 14:12:35 -07:00
parent 55708c2b39
commit 7d40740be3
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
5 changed files with 20 additions and 20 deletions

View File

@ -49,8 +49,8 @@ export const Apple2 = (props: Apple2Props) => {
...props,
};
const apple2 = new Apple2Impl(options);
setApple2(apple2);
apple2.ready.then(() => {
setApple2(apple2);
const io = apple2.getIO();
const cpu = apple2.getCPU();
setIO(io);

View File

@ -26,13 +26,11 @@ export const AudioControl = ({ apple2 }: AudioControlProps) => {
useEffect(() => {
if (apple2) {
apple2.ready.then(() => {
const io = apple2.getIO();
const audio = new Audio(io);
options.addOptions(audio);
setAudio(audio);
setAudioEnabled(audio.isEnabled());
}).catch(console.error);
const io = apple2.getIO();
const audio = new Audio(io);
options.addOptions(audio);
setAudio(audio);
setAudioEnabled(audio.isEnabled());
}
}, [apple2]);
@ -46,6 +44,7 @@ export const AudioControl = ({ apple2 }: AudioControlProps) => {
<ControlButton
onClick={doToggleSound}
title="Toggle Sound"
disabled={!audio}
icon={audioEnabled ? 'volume-up' : 'volume-off'}
/>
);

View File

@ -6,6 +6,7 @@ import { h, JSX } from 'preact';
export interface ControlButtonProps {
icon: string;
title: string;
disabled?: boolean;
onClick: JSX.MouseEventHandler<HTMLButtonElement>;
}
@ -17,8 +18,8 @@ export interface ControlButtonProps {
* @param onClick Click callback
* @returns Control Button component
*/
export const ControlButton = ({ icon, title, onClick }: ControlButtonProps) => (
<button onClick={onClick} title={title}>
export const ControlButton = ({ icon, title, onClick, ...props }: ControlButtonProps) => (
<button onClick={onClick} title={title} {...props} >
<i class={`fas fa-${icon}`}></i>
</button>
);

View File

@ -35,19 +35,17 @@ export const ControlStrip = ({ apple2, e }: ControlStripProps) => {
useEffect(() => {
if (apple2) {
apple2.ready.then(() => {
const io = apple2.getIO();
const vm = apple2.getVideoModes();
const io = apple2.getIO();
const vm = apple2.getVideoModes();
const system = new System(io, e);
options.addOptions(system);
const system = new System(io, e);
options.addOptions(system);
const joystick = new JoyStick(io);
options.addOptions(joystick);
const joystick = new JoyStick(io);
options.addOptions(joystick);
const screen = new Screen(vm);
options.addOptions(screen);
}).catch(console.error);
const screen = new Screen(vm);
options.addOptions(screen);
}
}, [apple2]);

View File

@ -34,12 +34,14 @@ export const PauseControl = ({ apple2 }: PauseControlProps) => {
{running ? (
<ControlButton
onClick={doPause}
disabled={!apple2}
title="Pause"
icon="pause"
/>
) : (
<ControlButton
onClick={doRun}
disabled={!apple2}
title="Run"
icon="play"
/>