97 lines
2.9 KiB
JavaScript
97 lines
2.9 KiB
JavaScript
const { cleanLayers } = require("../psapi")
|
|
|
|
const SessionState = {
|
|
Active : "active",
|
|
Inactive: "inactive",
|
|
|
|
}
|
|
const GarbageCollectionState = {
|
|
Accept : "accept", // accept all generated images
|
|
Discard: "discard",//discard all generated images
|
|
DiscardSelected: "discard_selected",
|
|
AcceptSelected: "accept_selected"//accept_selected only chosen images
|
|
|
|
}
|
|
|
|
class GenerationSession{
|
|
constructor(){
|
|
//this should be unique session id and it also should act as the total number of sessions been created in the project
|
|
this.id = 0
|
|
this.state = SessionState['Inactive']
|
|
this.mode = "txt2img"
|
|
this.selectionInfo = null
|
|
this.isFirstGeneration = true // only before the first generation is requested should this be true
|
|
}
|
|
isActive(){
|
|
return this.state === SessionState['Active']
|
|
}
|
|
isInactive(){
|
|
return this.state === SessionState['Inactive']
|
|
}
|
|
activate(){
|
|
this.state = SessionState['Active']
|
|
}
|
|
deactivate(){
|
|
this.state = SessionState['Inactive']
|
|
}
|
|
startSession(){
|
|
this.id += 1//increment the session id for each session we start
|
|
this.state = SessionState['Active']
|
|
this.isFirstGeneration = false // only before the first generation is requested should this be true
|
|
console.log("current session id: ", this.id)
|
|
|
|
}
|
|
async endSession(garbage_collection_state){
|
|
try{
|
|
this.state = SessionState['Inactive']// end the session by deactivate it
|
|
|
|
endGenerationSession()//end session
|
|
if(garbage_collection_state === GarbageCollectionState['Accept']){
|
|
|
|
await acceptAll()
|
|
}else if(garbage_collection_state === GarbageCollectionState['Discard']){
|
|
//this should be discardAll()
|
|
|
|
await discardAll()
|
|
}else if(garbage_collection_state === GarbageCollectionState['DiscardSelected'])
|
|
{
|
|
//this should be discardAllExcept(selectedLayers)
|
|
await discardSelected()//this will discard what is not been highlighted
|
|
|
|
}
|
|
else if(garbage_collection_state === GarbageCollectionState['AcceptSelected'])
|
|
{
|
|
//this should be discardAllExcept(selectedLayers)
|
|
await discard()//this will discard what is not been highlighted
|
|
|
|
}
|
|
|
|
|
|
this.isFirstGeneration = true // only before the first generation is requested should this be true
|
|
}catch(e){
|
|
console.warn(e)
|
|
}
|
|
|
|
|
|
}
|
|
isSameMode(selected_mode){
|
|
if (this.mode === selected_mode){
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
loadLastSession(){
|
|
//load the last session from the server
|
|
|
|
}
|
|
saveCurrentSession(){
|
|
//all session info will be saved in a json file in the project folder
|
|
}
|
|
}
|
|
|
|
|
|
module.exports ={
|
|
GenerationSession,
|
|
GarbageCollectionState,
|
|
SessionState
|
|
} |