Skip to content

Commit

Permalink
0.4.14
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Nov 19, 2022
1 parent 8b2756a commit f0de5fb
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 144 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file. Dates are displayed in UTC.

## [Unreleased]
## [0.4.13 - 0.4.14](https://github.com/averrin/alpha-suit/compare/0.4.13...0.4.14)
Added:
* "Folders white list" option for the File Manager. Only these folders will be indexed.
* "On demand" mode for file indexing. Starts the process only on a window opening.

## [0.4.12 - 0.4.13](https://github.com/averrin/alpha-suit/compare/0.4.12...0.4.13)
Fixed:
* File search input is hidden when there is no favs
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@typhonjs-fvtt/svelte-standard": "^0.0.10",
"class-transformer": "^0.5.1",
"consola": "^2.15.3",
"crew-components": "averrin/crew-components",
"crew-components": "../crew-components",
"daisyui": "^2.22.0",
"fast-sort": "^3.2.0",
"filtrex": "^3.0.0",
Expand Down
51 changes: 30 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,48 @@ Hooks.once('init', async () => {
});
});

const gridTool = {
name: "alpha-grid-btn",
title: "Toggle Alpha Grid",
icon: "ic:twotone-widgets",
onClick: () => {
grid.toggle();
},
toggle: true,
isActive: _ => setting("show-grid"),
}

Hooks.on('renderSceneControls', (_) => {
if (game?.user?.isGM) {
if (!document.querySelector(`[data-control='${tools.name}']`)) {
addTools(tools);
if (setting(SETTINGS.DEV_FEATURES) && !tools.tools.includes(gridTool)) {
tools.tools.push(...[
gridTool,
])
}
} else {
tools.tools = []
if (setting(SETTINGS.DEV_FEATURES)) {
tools.tools = [
gridTool
]
}
}
if (tools.tools?.length > 0 && !document.querySelector(`[data-control='${tools.name}']`)) {
addTools(tools);
}
});

Hooks.once('ready', async () => {
helperStores()
initStores();
grid.start();

if (game.user.isGM) {
helperStores()
initStores();
tree.start();
browser.start();
help.start();
settings.start();
files.start();
grid.start();

if (globalThis.game.modules.get("director")?.active) {
hud.add(new DirectorWidget());
Expand All @@ -203,23 +227,8 @@ Hooks.once('ready', async () => {
new NotificationsApp().render(true);
logger.info(`Started! Version: ${game.modules.get("alpha-suit").data.version}`)

if (setting(SETTINGS.DEV_FEATURES)) {
tools.tools.push(...[
{
name: "alpha-grid-btn",
title: "Toggle Alpha Grid",
icon: "ic:twotone-widgets",
onClick: () => {
grid.toggle();
},
toggle: true,
isActive: _ => setting("show-grid"),
},
])
}

const indexMode = setting(SETTINGS.FILES_INDEX_MODE);
if (indexMode != "manual") {
if (indexMode != "manual" && indexMode != "ondemand") {
const delay = indexMode == "auto" ? setting(SETTINGS.FILES_INDEX_DELAY) : 0;
if (delay >= 0) {
if (delay != 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
background: hsl(var(--window-background));
}
}
#alpha-grid {
.window-content {
overflow: visible !important;
}
}
1 change: 1 addition & 0 deletions src/modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const FLAGS = {
}

export const SETTINGS = {
FILES_WHITE_LIST: "files-white-list",
GRID_LAYOUT: "grid-layout",
FILES_FUZZY: "files-fuzzy",
FILES_INDEX_MODE: "files-index-mode",
Expand Down
94 changes: 53 additions & 41 deletions src/modules/file_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function clearSavedIndex() {

export async function startCache() {
const mode = setting(SETTINGS.FILES_INDEX_MODE);
const whiteList = setting(SETTINGS.FILES_WHITE_LIST);
if (mode == "persist") {

if (isPremium()) {
Expand Down Expand Up @@ -76,54 +77,65 @@ export async function startCache() {
let indexLimit = setting(SETTINGS.FILES_INDEX_COUNT);
let firstLevel = [];
let n = 0;
for (const source of sources) {
path = source.startsWith("forge") ? "" : ".";
await picker.browse(source, path).then((res) => {
firstLevel.push(...res.dirs);
});
if (whiteList?.length > 0) {
firstLevel = whiteList
sources = sources.filter(s => whiteList?.find(p => p.startsWith(s)));
} else {
for (const source of sources) {
path = source.startsWith("forge") ? "" : ".";
await picker.browse(source, path).then((res) => {
firstLevel.push(...res.dirs);
});
}
}
for (const source of sources) {
path = source.startsWith("forge") ? "" : ".";
let pathes = [source.startsWith("forge") ? "" : "."];
if (whiteList?.length > 0) {
pathes = whiteList.filter(p => p.startsWith(source)).map(p => p.replace(source + "/", ""));
}
// await breadth({

console.time("indexing " + source);
await depth({
tree: path,
getChildren(node, nodeResult) {
if (get(stopFileIndex)) return [];
return picker.browse(source, node).then((res) => {
if (res.error) return [];
res.files = res.files.map(p => source + "/" + p);
for (const path of pathes) {
await depth({
tree: path,
getChildren(node, _) {
if (get(stopFileIndex)) return [];
if (setting(SETTINGS.FILES_INDEX_ONLY_ASSETS)) {
index.push(...res.files.filter((f) => isImage(f) || isVideo(f) || isSound(f)));
return picker.browse(source, node).then((res) => {
if (res.error) return [];
res.files = res.files.map(p => source + "/" + p);
if (get(stopFileIndex)) return [];
if (setting(SETTINGS.FILES_INDEX_ONLY_ASSETS)) {
index.push(...res.files.filter((f) => isImage(f) || isVideo(f) || isSound(f)));
} else {
index.push(...res.files);
}
fileIndex.set(index);
return res.dirs;
}).catch(_ => []);
},
leave(node) {
if (firstLevel.includes(node)) {
const per = Math.round((n / firstLevel.length) * 100);
indexPercents.set(per)
n++;
}
return new Promise((r) => r(node));
},
filter(node) {
if (get(stopFileIndex)) return false;
if (index.length >= indexLimit) return false;
const isGood = node.split("/").length < depthLimit && !excludedFolders.some((p) => node.match(new RegExp(p)));
if (isGood) {
indexPath.set(`${source}/${node}`);
} else {
index.push(...res.files);
}
fileIndex.set(index);
return res.dirs;
}).catch(_ => []);
},
leave(node) {
if (firstLevel.includes(node)) {
const per = Math.round((n / firstLevel.length) * 100);
indexPercents.set(per)
n++;
}
return new Promise((r) => r(node));
},
filter(node) {
if (get(stopFileIndex)) return false;
if (index.length >= indexLimit) return false;
const isGood = node.split("/").length < depthLimit && !excludedFolders.some((p) => node.match(new RegExp(p)));
if (isGood) {
indexPath.set(`${source}/${node}`);
} else {
}
return isGood;
},
});
// n = 1;
console.timeEnd("Alpha | Indexing " + source);
return isGood;
},
});
// n = 1;
console.timeEnd("Alpha | Indexing " + source);
}
}
logger.info(`Indexed: ${index.length} files. Depth: ${depthLimit}`);
console.timeEnd("indexing");
Expand Down
12 changes: 11 additions & 1 deletion src/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ export function initSettings(app) {
type: Number,
});

game.settings.register(moduleId, SETTINGS.FILES_WHITE_LIST, {
name: 'Folders white list',
hint: "List of folders for indexing. Do not forget specify a storage. For example: 'data/modules/jb2a_patreon/Library' instead of 'modules/jb2a_patreon/Library'",
scope: "world",
config: false,
default: [],
type: Array,
});

game.settings.register(moduleId, SETTINGS.FILES_EXCLUDE_SOURCES, {
name: 'Excluded storages',
hint: "E.g. you can exclude 'Data' to prevent 'modules' folders indexing",
Expand Down Expand Up @@ -384,8 +393,9 @@ export function initSettings(app) {
'auto': "Automatic",
'persist': "Stored index",
'manual': "Manual",
'ondemand': "On demand",
},
default: "auto",
default: "ondemand",
type: String,
});

Expand Down
9 changes: 2 additions & 7 deletions src/modules/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { tick } from "svelte";

import { moduleId, SETTINGS, infoColor } from "./constants.js";
import initHelpers from "crew-components/helpers";
import { userSettingStore } from 'crew-components/stores';
import { userFlagStore } from 'crew-components/stores';
initHelpers(moduleId, infoColor, SETTINGS);
let tagSource = moduleId;

Expand Down Expand Up @@ -263,12 +263,7 @@ function initDropHandler() {
export let gridLayout = writable([]);

export function initStores() {
gridLayout = userSettingStore(SETTINGS.GRID_LAYOUT, {
scope: "world",
config: false,
default: [],
type: Array,
})
gridLayout = userFlagStore(SETTINGS.GRID_LAYOUT, [])

initDropHandler()

Expand Down
5 changes: 5 additions & 0 deletions src/view/FilesUI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
const position = application.position;
const { height } = position.stores;
const indexMode = setting(SETTINGS.FILES_INDEX_MODE);
if (indexMode == "ondemand" && $fileIndex.length == 0) {
tick().then(rebuildIndex);
}
export let elementRoot;
let topic;
let nameFilter = "";
Expand Down
Loading

0 comments on commit f0de5fb

Please sign in to comment.