# Saikyo OS Installer Plymouth Script

# Global variables
global.progress_bar.sprite = 0;
global.progress_bar.bar = 0;
global.progress_bar.width = 0;
global.progress_bar.height = 0;
global.progress_bar.x = 0;
global.progress_bar.y = 0;

# Initialize
fun init () {
    # Set background
    background.color = [0.105, 0.105, 0.105, 1.0];  # Dark #1a1a1a
    
    # Set up progress bar
    global.progress_bar.width = 400;
    global.progress_bar.height = 6;
    global.progress_bar.x = Window.GetWidth() / 2 - global.progress_bar.width / 2;
    global.progress_bar.y = Window.GetHeight() * 0.8;
    
    # Create progress bar parts
    global.progress_bar.sprite = Sprite();
    global.progress_bar.sprite.SetPosition(global.progress_bar.x, global.progress_bar.y, 0);
    
    global.progress_bar.bar = Sprite();
    global.progress_bar.bar.SetPosition(global.progress_bar.x, global.progress_bar.y, 0);
}

# Display message
fun display_message_callback (text) {
    message = Text(text, "Cantarell 12");
    message.color = [1.0, 1.0, 1.0, 1.0];  # White
    message.SetPosition(Window.GetWidth() / 2 - message.GetWidth() / 2, 
                       Window.GetHeight() * 0.7, 1);
}

# Update progress
fun progress_callback (progress) {
    progress_width = global.progress_bar.width * progress;
    
    # Draw progress bar background
    global.progress_bar.sprite.SetImage(global.progress_bar.width, global.progress_bar.height);
    global.progress_bar.sprite.SetPosition(global.progress_bar.x, global.progress_bar.y, 0);
    
    # Draw progress bar fill
    global.progress_bar.bar.SetImage(progress_width, global.progress_bar.height);
    global.progress_bar.bar.SetPosition(global.progress_bar.x, global.progress_bar.y, 1);
}

# Main loop
fun refresh () {
    # Draw "SAIKYO OS" text
    title = Text("SAIKYO OS", "Cantarell 24");
    title.color = [1.0, 1.0, 1.0, 1.0];  # White
    title.SetPosition(Window.GetWidth() / 2 - title.GetWidth() / 2, 
                      Window.GetHeight() * 0.3, 2);
    
    # Draw progress bar
    if (global.progress_bar.sprite) {
        global.progress_bar.sprite.SetOpacity(1.0);
    }
    
    if (global.progress_bar.bar) {
        global.progress_bar.bar.SetOpacity(1.0);
    }
}

# Cleanup
fun quit () {
    # Clean up sprites
    if (global.progress_bar.sprite) {
        global.progress_bar.sprite = NULL;
    }
    if (global.progress_bar.bar) {
        global.progress_bar.bar = NULL;
    }
}
