def _test():
    appglobals = AppGlobals()
    appglobals.update(
        langsettings=LangSettings('./test_langsettings.json'),
        quizsettings=QuizSettings('./test_quizsettings.json'),
    )
    appglobals.data.update(
        devmode=True,
        mode='timeattack',
    )
    root = ScreenManager()
    root.add_widget(scenes.quiz_timeattack.instantiate(appglobals=appglobals))
    runTouchApp(root)
def _test():
    # 無作為にQuizの成績を作る
    random_random = random.random
    random_randrange = random.randrange
    random_sample = random.sample
    LANGS = 'Japanese Chinese Korean English'.split()
    LEN_LANGS_PLUS1 = len(LANGS) + 1
    records = Records(filepath='./test_records.json')
    today = datetime.date.today().isoformat()
    for i in range(50):
        n_answered = random_randrange(10, 20)
        records.add(mode='endless',
                    result={
                        'date':
                        today,
                        'n_cleared':
                        random_randrange(0, n_answered),
                        'n_answered':
                        n_answered,
                        'langs':
                        random_sample(LANGS,
                                      random_randrange(1, LEN_LANGS_PLUS1)),
                    })
    for i in range(50):
        time = random_random() * 300
        n_answered = random_randrange(10, 20)
        n_cleared = random_randrange(0, n_answered)
        records.add(mode='timeattack',
                    result={
                        'date':
                        today,
                        'points':
                        round(time * n_cleared / n_answered, 2),
                        'n_cleared':
                        n_cleared,
                        'n_answered':
                        n_answered,
                        'time':
                        time,
                        'langs':
                        random_sample(LANGS,
                                      random_randrange(1, LEN_LANGS_PLUS1)),
                    })
    #
    appglobals = AppGlobals()
    appglobals.records = records
    root = ScreenManager()
    root.add_widget(scenes.records.instantiate(appglobals=appglobals))
    runTouchApp(root)
def _test():
    obj = AppGlobals()
    print(obj.data)
    funcs = obj.funcs
    print(funcs)
    funcs.play_sound('arg', key='value')
    funcs.switch_scene('arg', key='value')
Beispiel #4
0
 def build(self):
     appglobals = AppGlobals()
     appglobals.data.mode = 'endless'
     self.root = root = ScreenManager()
     root.add_widget(Screen())
     root.add_widget(scenes.countdown.instantiate(appglobals=appglobals))
     return root
Beispiel #5
0
def _test():
    appglobals = AppGlobals()
    appglobals.update(
        records=Records(filepath='./test_records.json'),
    )
    appglobals.data.update(
        devmode=False,
        mode='timeattack',
        result=attrdict(
            points=12.34,
            n_cleared=20,
            n_answered=37,
            time=123,
            langs=['python'],
        ),
    )
    root = ScreenManager()
    root.add_widget(
        scenes.result.instantiate(appglobals=appglobals)
    )
    runTouchApp(root)
Beispiel #6
0
def _test():
    root = ScreenManager()
    root.add_widget(scenes.menu.instantiate(appglobals=AppGlobals()))
    runTouchApp(root)
Beispiel #7
0
class MostxApp(App):

    appglobals = ObjectProperty(AppGlobals())

    def build_config(self, config):
        config.setdefaults('game', {'devmode': False, })

    def build_settings(self, settings):
        JSON_DATA = """[
            { "type": "title",
              "title": "Game Config" },

            { "type": "bool",
              "title": "Dev Mode",
              "section": "game",
              "key": "devmode" }
        ]"""
        settings.add_json_panel('Mostx', self.config, data=JSON_DATA)

    def on_config_change(self, config, section, key, value):
        if config is not self.config:
            return
        if (section, key, ) == ('game', 'devmode', ):
            self.appglobals.data.devmode = config.get('game', 'devmode') != '0'

    def build(self):
        self.root = root = MostxScreenManager()
        appglobals = self.appglobals
        appglobals.funcs.update(
            switch_scene=root.switch_screen,
            play_sound=_create_function_play_sound(),
        )
        user_data_dir = PurePath(self.user_data_dir)
        appglobals.update(
            records=Records(user_data_dir / 'records.json'),
            langsettings=LangSettings(user_data_dir / 'langsettings.json'),
            quizsettings=QuizSettings(user_data_dir / 'quizsettings.json'),
        )
        appglobals.data.devmode = self.config.get('game', 'devmode') != '0'
        root.add_widget(Screen(name='blank'))
        self._setup_all_scenes()
        return root

    def _setup_all_scenes(self):
        scene_dir = Path(__file__).parent / 'scenes'
        scene_names = tuple(
            item.stem for item in scene_dir.iterdir()
            if (not item.stem.startswith('__')) and (
                item.is_dir() or (item.suffix == '.py')
            )
        )
        print(scene_names)
        add_widget = self.root.add_widget
        appglobals = self.appglobals
        for name in scene_names:
            module = importlib.import_module('scenes.' + name)
            add_widget(module.instantiate(name=name, appglobals=appglobals))

    def on_start(self):
        self.appglobals.funcs.switch_scene('title')

    def on_stop(self):
        appglobals = self.appglobals
        appglobals.records.save()
        appglobals.langsettings.save()
Beispiel #8
0
def _test():
    appglobals = AppGlobals()
    appglobals.langsettings = LangSettings(filepath='./test_langsettings.json')
    root = ScreenManager()
    root.add_widget(scenes.langsettings.instantiate(appglobals=appglobals))
    runTouchApp(root)