class DistributedDayTimeManager(DistributedWeatherMGR):
    notify = directNotify.newCategory('DistributedDayTimeManager')
    
    def __init__(self, cr):
        DistributedWeatherMGR.__init__(self, cr)
        self.cr = cr
        self.hood = base.cr.playGame.hood
        self.interval = 2
        self.hour2sky = {
            0: 'night',
            1: 'night',
            2: 'night',
            3: 'night',
            4: 'night',
            5: 'night',
            6: 'mml',
            7: 'mml',
            8: 'day',
            9: 'day',
            10: 'day',
            11: 'day',
            12: 'day',
            13: 'day',
            14: 'day',
            15: 'day',
            16: 'day',
            17: 'mml',
            18: 'mml',
            19: 'mml',
            20: 'night',
            21: 'night',
            22: 'night',
            23: 'night'
        }

    def generate(self):
        DistributedWeatherMGR.generate(self)
        
    def announceGenerate(self):
        DistributedWeatherMGR.announceGenerate(self)

    def setSky(self, sky):
        self.hood.skyTransition(str(sky))
    
    def update(self, currentHour):
        self.currSeq = LerpColorScaleInterval(render, self.interval, DayTimeGlobals.COLORS[
            0 if currentHour == 23 else currentHour + 1], DayTimeGlobals.COLORS[currentHour])
        
        self.currSeq.start()
        
        # update the sky
        self.setSky(self.hour2sky[currentHour])

    def delete(self):
        self.currSeq.finish()
        DistributedWeatherMGR.delete(self)
        render.setColorScale(Vec4(1, 1, 1, 1))
Esempio n. 2
0
class DistributedWeatherCycle(DistributedObject):
    notify = DirectNotifyGlobal.directNotify.newCategory(
        'DistributedWeatherCycle')

    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.fsm = ClassicFSM(self.__class__.__name__, [
            State('off', self.enterOff, self.exitOff, ['morning']),
            State('morning', self.enterMorning, self.exitMorning,
                  ['afternoon']),
            State('afternoon', self.enterAfternoon, self.exitAfternoon,
                  ['evening']),
            State('evening', self.enterEvening, self.exitEvening,
                  ['midnight']),
            State('midnight', self.enterMidnight, self.exitMidnight,
                  ['morning'])
        ], 'off', 'off')
        self.fsm.enterInitialState()
        self.__interval = None

    def setState(self, state):
        self.fsm.request(state)

    def getState(self):
        return self.fsm.getCurrentState()._State__name

    def setDuration(self, duration):
        self.duration = duration

    def getDuration(self):
        return self.duration

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def enterMorning(self):
        self.__interval = LerpColorScaleInterval(
            render,
            self.getDuration(),
            WeatherGlobals.cycleColors[0],
            startColorScale=render.getColorScale())
        self.__interval.start()

    def exitMorning(self):
        if not self.__interval:
            return
        self.__interval.finish()
        self.__interval = None

    def enterAfternoon(self):
        self.__interval = LerpColorScaleInterval(
            render,
            self.getDuration(),
            WeatherGlobals.cycleColors[1],
            startColorScale=render.getColorScale())
        self.__interval.start()

    def exitAfternoon(self):
        if not self.__interval:
            return
        self.__interval.finish()
        self.__interval = None

    def enterEvening(self):
        self.__interval = LerpColorScaleInterval(
            render,
            self.getDuration(),
            WeatherGlobals.cycleColors[2],
            startColorScale=render.getColorScale())
        self.__interval.start()

    def exitEvening(self):
        if not self.__interval:
            return
        self.__interval.finish()
        self.__interval = None

    def enterMidnight(self):
        self.__interval = LerpColorScaleInterval(
            render,
            self.getDuration(),
            WeatherGlobals.cycleColors[3],
            startColorScale=render.getColorScale())
        self.__interval.start()

    def exitMidnight(self):
        if not self.__interval:
            return
        self.__interval.finish()
        self.__interval = None