scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
154 lines • 3.14 kB
JavaScript
import { AbsPhotos } from "scriptable-abstract";
import { MockImage } from "../media/image";
class MockPhotos extends AbsPhotos {
constructor() {
super({
library: {
photos: [],
screenshots: []
}
});
}
/**
* @inheritdoc
*/
async fromLibrary() {
if (this.state.library.photos.length === 0) {
throw new Error("No photos in library");
}
return this.state.library.photos[0];
}
/**
* @inheritdoc
*/
async fromCamera() {
const image = new MockImage();
this.setState((state) => ({
library: {
...state.library,
photos: [image, ...state.library.photos]
}
}));
return image;
}
/**
* @inheritdoc
*/
async latestPhoto() {
if (this.state.library.photos.length === 0) {
throw new Error("No photos in library");
}
return this.state.library.photos[0];
}
/**
* @inheritdoc
*/
async latestPhotos(count) {
return this.state.library.photos.slice(0, count);
}
/**
* @inheritdoc
*/
async latestScreenshot() {
if (this.state.library.screenshots.length === 0) {
throw new Error("No screenshots in library");
}
return this.state.library.screenshots[0];
}
/**
* @inheritdoc
*/
async latestScreenshots(count) {
return this.state.library.screenshots.slice(0, count);
}
/**
* @inheritdoc
*/
removeLatestPhoto() {
if (this.state.library.photos.length === 0) {
throw new Error("No photos in library");
}
this.setState((state) => ({
library: {
...state.library,
photos: state.library.photos.slice(1)
}
}));
}
/**
* @inheritdoc
*/
removeLatestPhotos(count) {
this.setState((state) => ({
library: {
...state.library,
photos: state.library.photos.slice(count)
}
}));
}
/**
* @inheritdoc
*/
removeLatestScreenshot() {
if (this.state.library.screenshots.length === 0) {
throw new Error("No screenshots in library");
}
this.setState((state) => ({
library: {
...state.library,
screenshots: state.library.screenshots.slice(1)
}
}));
}
/**
* @inheritdoc
*/
removeLatestScreenshots(count) {
this.setState((state) => ({
library: {
...state.library,
screenshots: state.library.screenshots.slice(count)
}
}));
}
/**
* @inheritdoc
*/
save(image) {
this.setState((state) => ({
library: {
...state.library,
photos: [image, ...state.library.photos]
}
}));
}
/**
* @additional
* Add a screenshot to the library
* @param image The screenshot image to add
*/
addScreenshot(image) {
this.setState((state) => ({
library: {
...state.library,
screenshots: [image, ...state.library.screenshots]
}
}));
}
/**
* @additional
* Clear all photos and screenshots from the library
*/
clear() {
this.setState({
library: {
photos: [],
screenshots: []
}
});
}
}
export {
MockPhotos
};
//# sourceMappingURL=photos.js.map