#!/usr/bin/python3

import random
import os

import pygame
from pygame.sprite import Sprite
from load import Load
from natsort import natsorted

class Sailor_Venus(Sprite):
    def __init__(self, game):
        """initializes the memory sailor venus"""
        super().__init__()
        
        #screen set up:
        self.screen = game.screen
        self.screen_rect = self.screen.get_rect()

        #variable flags
        self.stage = 1
        self.grab_ass = False

        #loads
        self.temp = game.load.processor_temp

        #loads idle1 images into list
        self.venus_idle1 = []
        self.venus_idle1.append(pygame.image.load('sailor_venus/sailor_venus_idle4-1.png'))
        self.venus_idle1.append(pygame.image.load('sailor_venus/sailor_venus_idle4-2.png'))
        self.venus_idle1.append(pygame.image.load('sailor_venus/sailor_venus_idle4-3.png'))

        self.current_idle1 = 0

        self.venus_idle2 = []
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-1.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-1.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-1.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-1.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-2.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-3.png'))
        self.venus_idle2.append(pygame.image.load('sailor_venus/sailor_venus_idle2-4.png'))
        self.current_idle2 = 0

        self.venus_idle3 = []
        self.venus_idle3.append(pygame.image.load('sailor_venus/sailor_venus_idle3-1.png'))
        self.venus_idle3.append(pygame.image.load('sailor_venus/sailor_venus_idle3-2.png'))
        self.venus_idle3.append(pygame.image.load('sailor_venus/sailor_venus_idle3-3.png'))
        self.venus_idle3.append(pygame.image.load('sailor_venus/sailor_venus_idle3-4.png'))
        self.venus_idle3.append(pygame.image.load('sailor_venus/sailor_venus_idle3-5.png'))
        self.current_idle3 = 0

        self.venus_idle4 = []
        self.venus_idle4.append(pygame.image.load('sailor_venus/sailor_venus_idle1-1.png'))
        self.current_idle4 = 0

        #sets image and rect
        self.image = self.venus_idle1[self.current_idle1]
        self.rect = self.image.get_rect()

        #places image and rect in correct location
        #self.rect.midright = self.screen_rect.midright
        #self.rect.y = game.sailor_moon.rect.y
        self.rect.bottom = self.screen_rect.bottom
        self.rect.x = 0

    def first_idle(self):
        if self.current_idle1 >= len(self.venus_idle1):
            self.current_idle1 = 0
            self.grab_ass = False
        
        self.image = self.venus_idle1[self.current_idle1]
        self.current_idle1 += 1

    def update(self, game):
        if game.memory <= 35:
            if self.grab_ass == False:
                random_number = random.randrange(25)
                if random_number == 5:
                    self.grab_ass = True
            if self.grab_ass == False:
                self.image = self.venus_idle1[0]
            elif self.grab_ass == True:
                self.first_idle()


        elif game.memory > 35 and game.memory < 70:
            if self.current_idle2 >= len(self.venus_idle2):
                self.current_idle2 = 0
        
            self.image = self.venus_idle2[self.current_idle2]
            self.current_idle2 += 1

        elif game.memory >= 70:
            if self.current_idle3 >= len(self.venus_idle3):
                self.current_idle3 = 0
        
            self.image = self.venus_idle3[self.current_idle3]
            self.current_idle3 += 1


class Venus_Ahegao(Sprite):
    def __init__(self, game):
        """initializes the ahegao face"""
        super().__init__()
        
        self.screen = game.screen
        self.screen_rect = game.screen_rect

        #loads the ahegao images and makes rect
        self.image = pygame.image.load('sailor_venus/ahegao1-1.png')
        self.ahegao_1 = pygame.image.load('sailor_venus/ahegao1-1.png')
        self.ahegao_2 = pygame.image.load('sailor_venus/ahegao1-2.png')
        self.ahegao_3 = pygame.image.load('sailor_venus/ahegao1-3.png')
        self.ahegao_4 = pygame.image.load('sailor_venus/ahegao1-4.png')
        self.ahegao_5 = pygame.image.load('sailor_venus/ahegao1-5.png')
        self.rect = self.ahegao_1.get_rect()

        #position rect
        self.rect.midbottom = game.sailor_venus.rect.midtop
        self.rect.y = self.screen_rect.y

    def update(self, game):
        if game.memory > 80:
            self.image = self.ahegao_5
        elif game.memory > 60:
            self.image = self.ahegao_4
        elif game.memory > 40:
            self.image = self.ahegao_3
        elif game.memory > 20:
            self.image = self.ahegao_2
        else:
            self.image = self.ahegao_1

class Venus_Cakes(Sprite):
    def __init__(self, game):
        """initializes the sailor moon walking"""
        super().__init__()
        
        #screen set up:
        self.screen = game.screen
        self.screen_rect = self.screen.get_rect()

        #images
        self.major_cakes = []
        self.major_cakes.append(pygame.image.load('sailor_venus/major_cakes1-1.png'))
        self.major_cakes.append(pygame.image.load('sailor_venus/major_cakes1-2.png'))
        self.major_cakes.append(pygame.image.load('sailor_venus/major_cakes1-3.png'))
        self.major_cakes.append(pygame.image.load('sailor_venus/major_cakes1-4.png'))

        self.current_major_cakes = 0

        #creates sailor moon and positions her
        self.image = self.major_cakes[self.current_major_cakes]
        self.rect = self.image.get_rect()
        self.rect.bottomright = self.screen_rect.bottomright

    def update(self):
        if self.current_major_cakes >= len(self.major_cakes):
            self.current_major_cakes = 0

        self.image = self.major_cakes[self.current_major_cakes]
        self.current_major_cakes += 1

class Venus_Gauge(Sprite):
    def __init__(self, game):
        """initilizes the Gauge"""
        super().__init__()

        #screen set up:
        self.screen = game.screen
        self.screen_rect = self.screen.get_rect()

        self.gauge_names = []
        self.gauge_images = []
        all_gauge_names = os.listdir('sailor_moon/gauge/')
        for files in all_gauge_names:
            if 'up' not in files:       
                self.gauge_names.append(files)
        self.gauge_names = natsorted(self.gauge_names)
        for files in self.gauge_names:
                self.gauge_images.append(pygame.image.load(f'sailor_moon/gauge/{files}'))           

        #images
        self.image = pygame.image.load('sailor_moon/gauge/gauge0.png')
        self.rect = self.image.get_rect()
        self.rect.topleft = self.screen_rect.topleft
    
    def update(self, game):
        self.load = game.load
        self.memory = int(self.load.memory)
        self.image = self.gauge_images[self.memory]

class Coming_Soon(Sprite):
    def __init__(self, game):
        super().__init__()

        self.screen_rect = game.screen_rect

        self.coming_soon_idle = []
        self.coming_soon_idle.append(pygame.image.load('sailor_venus/coming_soon1-1.png'))
        self.coming_soon_idle.append(pygame.image.load('sailor_venus/coming_soon1-2.png'))
        self.coming_soon_idle.append(pygame.image.load('sailor_venus/coming_soon1-2.png'))
        self.current_coming_idle = 0

        self.image = self.coming_soon_idle[self.current_coming_idle]
        self.rect = self.image.get_rect()

        self.rect.center = game.sailor_venus.rect.center

    def update(self, game):
        if self.current_coming_idle >= len(self.coming_soon_idle):
            self.current_coming_idle = 0
        
        self.image = self.coming_soon_idle[self.current_coming_idle]
        self.current_coming_idle += 1
