Changed random character select from long list to just favourites
This commit is contained in:
+12
-2
@@ -117,10 +117,20 @@ class CharacterSelectNode:
|
||||
|
||||
def select_random_character(self):
|
||||
# Fetching the exclusion settings
|
||||
excluded_characters = ConfigReader.get_setting("sn0w.ExcludedRandomCharacters", [])
|
||||
exclude_characters = ConfigReader.get_setting("sn0w.ExcludedRandomCharacters", False)
|
||||
if (exclude_characters == False):
|
||||
random_character_name = random.choice(list(filtered_characters.keys()))
|
||||
char_item = filtered_characters[random_character_name]
|
||||
self.logger.log("Random Character: " + str(char_item["name"]), "INFORMATIONAL")
|
||||
return char_item
|
||||
|
||||
favourite_characters = ConfigReader.get_setting("sn0w.FavouriteCharacters", [])
|
||||
if (favourite_characters == []):
|
||||
self.logger.log("No valid characters found based on the specified criteria.", "WARNING")
|
||||
return ""
|
||||
|
||||
# Filter the characters by excluding the ones in the exclusion list
|
||||
filtered_characters = {name: char for name, char in self.final_character_dict.items() if self.sanitize_name(name) in excluded_characters}
|
||||
filtered_characters = {name: char for name, char in self.final_character_dict.items() if name in favourite_characters}
|
||||
|
||||
# Choosing a random character from the filtered list
|
||||
if filtered_characters:
|
||||
|
||||
@@ -1,68 +1,20 @@
|
||||
import { SettingUtils } from './sn0w.js';
|
||||
import { app } from "../../../scripts/app.js";
|
||||
|
||||
const Id = "sn0w.ExcludedRandomCharacters";
|
||||
const jsonUrls = ['/extensions/ComfyUI-Sn0w-Scripts/settings/characters.json', '/extensions/ComfyUI-Sn0w-Scripts/settings/custom_characters.json'];
|
||||
|
||||
// Function to fetch, sort, and load options from multiple JSON files
|
||||
const loadOptionsFromJson = async (urls) => {
|
||||
const allData = [];
|
||||
|
||||
// Fetch data from each URL and combine it into one array
|
||||
for (const url of urls) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
console.warn('Network response was not ok for URL: ' + url);
|
||||
continue;
|
||||
}
|
||||
const data = await response.json();
|
||||
allData.push(...data);
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch or parse JSON from URL: ' + url, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (allData.length === 0) {
|
||||
console.error('No data fetched from any URLs');
|
||||
return [];
|
||||
}
|
||||
|
||||
// Sort the combined data alphabetically by the name property
|
||||
const sortedData = allData.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
// Map the sorted data to the required format
|
||||
return sortedData.map(item => ({
|
||||
label: item.name,
|
||||
value: item.name.replace(/[^a-z0-9]/gi, '_').toLowerCase() // Sanitize the value
|
||||
}));
|
||||
const id = "sn0w.ExcludedRandomCharacters";
|
||||
const settingDefinition = {
|
||||
id,
|
||||
name: "[Sn0w] Random Characters from Favourites Only",
|
||||
defaultValue: false,
|
||||
type: "boolean"
|
||||
};
|
||||
|
||||
// Function to register the setting
|
||||
const registerSetting = (settingDefinition) => {
|
||||
const extension = {
|
||||
name: settingDefinition.id,
|
||||
init() {
|
||||
app.ui.settings.addSetting(settingDefinition);
|
||||
}
|
||||
};
|
||||
app.registerExtension(extension);
|
||||
let setting;
|
||||
|
||||
const extension = {
|
||||
name: id,
|
||||
init() {
|
||||
setting = app.ui.settings.addSetting(settingDefinition);
|
||||
},
|
||||
};
|
||||
|
||||
// Load options and register the setting
|
||||
loadOptionsFromJson(jsonUrls).then(options => {
|
||||
const SettingDefinition = {
|
||||
id: Id,
|
||||
name: "[Sn0w] Exclude/Include Random Characters",
|
||||
type: SettingUtils.createCheckboxSetting,
|
||||
defaultValue: [],
|
||||
attrs: {
|
||||
options: options,
|
||||
tooltip: ""
|
||||
}
|
||||
};
|
||||
|
||||
registerSetting(SettingDefinition);
|
||||
}).catch(error => {
|
||||
console.error('Error registering setting:', error);
|
||||
});
|
||||
app.registerExtension(extension);
|
||||
|
||||
Reference in New Issue
Block a user