Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore profile functionality + full serialization #661

Open
3 tasks
AlmasB opened this issue Aug 26, 2019 · 1 comment
Open
3 tasks

Restore profile functionality + full serialization #661

AlmasB opened this issue Aug 26, 2019 · 1 comment
Assignees

Comments

@AlmasB
Copy link
Owner

AlmasB commented Aug 26, 2019

This includes generation of profile data, saving and loading. Also needs to consider allowing no-profile games

  • FXGLMenu, use profile name instead of "./" to save/load data. Perhaps we can add a setting "saveDir" and save there?

  • FXGLDefaultMenu should be updated too

  • Input serialization:

override fun save(profile: UserProfile) {
        log.debug("Saving data to profile")

        val bundle = Bundle("input")
        bindings.forEach { bundle.put(it.key.toString(), it.value.toString()) }

        bundle.log()
        profile.putBundle(bundle)
    }

    override fun load(profile: UserProfile) {
        log.debug("Loading data from profile")

        val bundle = profile.getBundle("input")
        bundle.log()

        for (binding in bindings) {

            val action = binding.key

            // if binding is not present in bundle, then we added some new binding thru code
            // it will be saved on next serialization and will be found in bundle
            var triggerName: String? = bundle.get<String>("$action")
            if (triggerName == null)
                continue

            var modifierName = "NONE"

            val plusIndex = triggerName.indexOf("+")
            if (plusIndex != -1) {
                modifierName = triggerName.substring(0, plusIndex)
                triggerName = triggerName.substring(plusIndex + 1)
            }

            // if triggerName was CTRL+A, we end up with:
            // triggerName = A
            // modifierName = CTRL

            try {
                val key = KeyCode.getKeyCode(triggerName)
                rebind(action, key, InputModifier.valueOf(modifierName))
            } catch (ignored: Exception) {
                try {
                    val btn = MouseTrigger.buttonFromString(triggerName)
                    rebind(action, btn, InputModifier.valueOf(modifierName))
                } catch (e: Exception) {
                    log.warning("Undefined trigger name: " + triggerName)
                    throw IllegalArgumentException("Corrupt or incompatible user profile: " + e.message)
                }
            }
        }
    }

Legacy profile code

    //    private fun createProfilesDirTask(): IOTask<*> {
//        log.debug("Creating profiles dir")
//
//        return fs.createDirectoryTask(PROFILES_DIR)
//                .then { fs.writeDataTask(Collections.singletonList("This directory contains user profiles."), PROFILES_DIR + "Readme.txt") }
//                .onFailure {
//                    log.warning("Failed to create profiles dir: $it")
//                    Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), it)
//                }
//    }
//    fun createProfileTask(profileName: String): IOTask<Void> {
//        log.debug("Creating profile: $profileName")
//        return fs.createDirectoryTask("./$PROFILES_DIR$profileName")
//    }
//
//    /**
//     * A task that reads all profile names.
//     */
//    fun readProfileNamesTask(): IOTask<List<String>> {
//        log.debug("Reading profile names")
//        return fs.loadDirectoryNamesTask("./$PROFILES_DIR", recursive = false)
//    }
//
//    /**
//     * Delete profile.
//     *
//     * @param profileName name of profile to delete
//     */
//    fun deleteProfileTask(profileName: String): IOTask<Void> {
//        log.debug("Deleting profile: $profileName")
//        return fs.deleteDirectoryTask("./$PROFILES_DIR$profileName")
//    }

//
//    fun `Delete profile`() {
//        assertTrue(Files.exists(Paths.get("profiles/TestProfileName")))
//
//        saveLoadService.deleteProfileTask("TestProfileName").run()
//
//        assertFalse(Files.exists(Paths.get("profiles/TestProfileName")))
//    }
AlmasB added a commit that referenced this issue Jan 9, 2020
@AlmasB AlmasB self-assigned this Mar 28, 2020
@AlmasB
Copy link
Owner Author

AlmasB commented May 3, 2020

Double check this is needed:

Bundle fxglServicesBundle = new Bundle("FXGLServices");
fxglServicesBundle.put("globalSoundVolume", 0.5);
fxglServicesBundle.put("fullscreen", false);
fxglServicesBundle.put("globalMusicVolume", 0.5);

AlmasB added a commit that referenced this issue May 7, 2020
AlmasB added a commit that referenced this issue May 7, 2020
@AlmasB AlmasB changed the title Restore profile functionality Restore profile functionality + full serialization May 24, 2020
@AlmasB AlmasB added this to the 11.12 milestone Sep 11, 2020
@AlmasB AlmasB removed this from the 11.12 milestone Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant