[CODE RELEASE] FapJack

All about the past, current and future webteases and the art of webteasing in general.
---
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

[CODE RELEASE] FapJack

Post by fapnip »

I'm not likely to release another FapJack game any time soon, so for those of you that would like to create their own FapJack, here's a base game you can import into your own tease, then modify to suite your needs.

JSON (Right-click, save-as -- restore to new, empty tease):
https://milovana.com/webteases/geteossc ... ae797ac48c

Link to example game (Meant to show how to use game engine, not to play):
https://milovana.com/webteases/showteas ... ae797ac48c

The above game is not meant to be a playable game. It's simply an example trying to show how to use as many core features as possible when creating your own, and a base to update from when/if bug-fixes and/or new features are rolled out.

Ask for help, report bugs and make feature requests here.

Notes:
  • You will need some familiarity with JavaScript in order to modify game settings.
  • The code is a bit of a tangled mess, mainly due to unfortunate hacks and design decisions early on that I'm too lazy to refactor.
  • If you make useful changes/bug fixes to any core game pages, please post them here so they can be merged in upstream with the core game.
  • While debugging your tease, open your browser's console and look for errors. FapJack's engine does its best to report things like missing images loader pages, etc. (It's also very verbose when DEBUG mode is enabled, so you can see what it's doing behind the scenes.)
Please carefully read the comments in the Init Script for details (copy of them as of v1.16.0):

Code: Select all

/********************************
 * FapJack v1.16.0
 * by: fapnip@milovana
 * https://milovana.com/forum/viewtopic.php?f=2&t=23858
 ********************************
 * Sorry about the spaghetti.  Tough to keep code clean without imports and a proper IDE.
 *
 * To anyone that ripped this game's code:
 * Feel free to use any of this code in your own tease, but be nice and don't claim it as your own.
 * It may well be a mess, but it's my mess.
 *
 * Always base your FapJack games off fapnip's development example game:
 * https://milovana.com/webteases/showtease.php?id=47408&key=ae797ac48c
 *
 */
/*--magpie-warn
Need help with FapJack?
Ask here!
https://milovana.com/forum/viewtopic.php?f=2&t=23858
*/

/*****************
 * READ ME
 *****************
 *
 * Unless you're heavily modifying this game (my deepest apologies if you attempt that),
 *  >>> you shouldn't change anything in this Init Script. <<<
 *
 * If you do modify this init script, you'll have a more difficult time updating it with new versions.
 *
 * Anything you'd normally add to this init script can be placed in an eval in core-config.
 *
 * Avoid modifying game engine pages (start, play, cum-round-*, penalty-*, settings*, etc.)
 *   If there's a feature you need, and you can't implement it using the existing hooks
 *   (like with round intermission pages) request the feature in Milovana's forms.
 *   You'll have a hell of a time installing future updates if you don't heed this.
 *
 * !!! Read "CORE GAME PAGES", "REQUIRED GAME PAGES" and "INSTALLING UPDATES", below !!!
 *
 * Basic usage:
 *
 *  1.  Edit evals in core-config, setting values in game.setConfig({...}) object, and
 *        reviewing/editing/removing setting configuration option examples.
 *        (See comments in evals for details)
 *  2.  Create pages for your game rounds, based on your game settings.  Use existing pages as guide.
 *  3.  Edit what the dealer(s) can say in core-verbiage
 *
 *  See: core-config page for game settings and configuration
 *  See: core-verbiage and optional [mode]-verbiage-[level/cum-mode] pages for verbiage/language changes
 *
 *  For round images, see: (first page found is used)
 *
 *    [mode]-image-[level/cum-mode]-[hand]        (discrete image loader)
 *    [mode]-image-[level/cum-mode]-[hand]plus    (range image loader ***)
 *    [mode]-image-[level/cum-mode]               (level image loader)
 *    [mode]-image                                (mode image loader)
 *    round-image                                 (fall-back image loader)
 *
 *    *** A range image loader page example would be:
 *
 *    melody-image-1-3plus
 *
 *     This would be used to load images for any level 1 hand at or above index 3 that does not
 *     have a discrete image loader page or a more applicable range loader that would
 *     take precedence.
 *
 *  For (optional) penalty images, see: (first page found is used)
 *
 *    [mode]-[penaltyId (edge/stroke/etc.)]-[level/cum-mode]-[hand]
 *    [mode]-[penaltyId (edge/stroke/etc.)]-[level/cum-mode]-[hand]plus
 *    [mode]-[penaltyId (edge/stroke/etc.)]-[level/cum-mode]
 *    [mode]-[penaltyId (edge/stroke/etc.)]
 *    penalty-[penaltyId (edge/stroke/etc.)]-image
 *    penalty-image
 *
 *  For game over and win images, see: (first page found is used)
 *
 *  - Game Over Image Selection
 *    [mode]-game-over-[level/cum-mode]-[hand]
 *    [mode]-game-over-[level/cum-mode]-[hand]plus
 *    [mode]-game-over-[level/cum-mode]
 *    [mode]-game-over
 *    game-over-image
 *
 *  - Cum Tease Images (Shows when play can cum)
 *    [mode]-cumtease-[level/cum-mode]-[hand]
 *    [mode]-cumtease-[level/cum-mode]-[hand]plus
 *    [mode]-cumtease-[level/cum-mode]
 *    [mode]-cumtease
 *    win-cumtease-image
 *
 *  - Win Game Images (Displayed on win page)
 *    [mode]-win-[level/cum-mode]-[hand]
 *    [mode]-win-[level/cum-mode]-[hand]plus
 *    [mode]-win-[level/cum-mode]
 *    [mode]-win
 *    win-image
 *
 *  Cum round entry image:
 *
 *  - For each cum round mode, you'll need a page to welcome player to the cum round:
 *    [mode]-cum-round-[cum-mode]
 *
 *  Multiple game modes selection image:
 *
 *  - If you have multiple game modes defined, you'll need to change the image in:
 *    game-mode-select-image
 *
 *  Multiple cum round mode selection image:
 *
 *  - If you have multiple cum round modes defined for a given game mode, you'll need:
 *    [mode]-cum-round-select
 *
 *  Round intermission pages:
 *
 *    To interrupt a round, and display another page before the given hand starts,
 *    create a page with the name:
 *    [mode]-inter-[level/cum-mode]-[hand]
 *
 *    To interrupt a round, and display another page after the given hand ends,
 *    create a page with the name:
 *    [mode]-interp-[level/cum-mode]-[hand]
 *
 *    The page will be called before or after the given hand.
 *    Once you're done with your intermission, in an eval, execute:
 *
 *    returnToCaller();
 * 
 * 
 *  Game loss mode pages (instruct player when they lose):
 * 
 *    There are 4 core game loss mode page examples that when present and enabled
 *    will enable that game loss mode as a selectable option for the player:
 *    (You will need to modify the content of the example pages to match for tease.)
 * 
 *    game-lost-ruin - Default. Will be forced to ruin if they lose.
 *    game-lost-deny - Will be denied if they don't win the final round.  Will be forced to ruin if they cum early.
 *    game-lost-cei  - Will be told to cum if they haven't yet, then eat it. (Only if a cei kink is enabled.) 
 *    game-lost-rand - Will randomize the above on loss. (Don't modify this page.)
 * 
 *    To disable or delete the above pages to disable the setting option(s) for the player.
 * 
 *    To override the core loss mode page per game mode, level/cum-mode and hand,
 *    create page(s) with following patterns, with the first found being used:
 * 
 *    [mode]-game-lost-[loss-mode]-[level/cum-mode]-[hand]
 *    [mode]-game-lost-[loss-mode]-[level/cum-mode]-[hand]plus
 *    [mode]-game-lost-[loss-mode]-[level/cum-mode]
 *    [mode]-game-lost-[loss-mode]
 *    game-lost-[loss-mode]
 *     
 *
 *  Verbiage Pages (Changing what the dealer says):
 *
 *  - To modify what the dealer says globally, modify the evals in:
 *
 *    core-verbiage
 *
 *  - To modify what the dealers says per level, create a page:
 *
 *    [mode]-verbiage-[level/cum-mode]
 *
 *    Add an eval action to that page that overrides one or more verbiage keys, like:
 *
 *    game.setVerbiage({
 *      edge: [ // Tell player to edge
 *        "Get right to the edge, but don't cum!",
 *        "Go on, " + "edge for me!".bold().color('hotpink'),
 *        "Get as close as you can!",
 *        "Keep stroking until you edge!",
 *        "Get right to the edge for me.  Don't go over!",
 *        "Stroke until you almost explode, but don't!",
 *        "Do what you need to do to reach that edge!",
 *      ],
 *    });
 *
 *    (See: game.setVerbiage(...) evals in core-verbiage for more examples.)
 * 
 *  Styling Text:
 * 
 *    You can add style (size, color, bold, italic, etc.) to verbiage strings using:
 * 
 *    "My String".color([html color code]) // See: https://www.w3schools.com/colors/colors_names.asp
 *                                             and https://www.w3schools.com/colors/colors_hexadecimal.asp
 *                                             and https://htmlcolorcodes.com/color-picker/
 *    "My String".size([decimal size, 1 = 100%, 1.5 = 150%])
 *    "My String".spacing([decimal size, like 0.2, or 'normal'])
 *    "My String".italic()
 *    "My String".bold()
 *    "My String".underline()
 *    "My String".br() // Add line break
 *    "My String".p() + "My Next Paragraph" // Start new paragraph
 * 
 *    You can combine styles:
 * 
 *    "My String".bold().italic().size(1.2).color('hotpink')
 * 
 *  Changing/Adding metronome sounds
 * 
 *    Metronome sounds are in --audio-x pages.  Follow the existing files as a template.
 *
 *  Getting info on game state:
 *
 *    game.getLevel() will return the current level
 *    game.getRoundIndex() will return the current hand of the current level
 *    game.isCumRound() will return true if the player has reached the "cum round"
 *    (There are a ton more.  Ask for assistance in Milovana's forums.)
 *
 *  Creating custom penalties:
 *
 *    See examples in core-config-example
 *
 *  Overriding penalty probability, etc.:
 *
 *    See examples in core-config-example
 *
 */

/***************************************************
 * CORE GAME PAGES
 * *************************************************
 * Do not modify any of these pages! ***
 * If you need to add something, ask
 * in a feature request.
 *
 * *** NOTE: If an action in a given page is prefixed
 *     by an eval containing: --auto-magpie-merge: ...
 *     then you can modify ONLY the action that follows
 *     the --auto-magpie-merge: eval.
 *     (auto-magpie-merge eval prefixes must be in
 *      both source and target.
 *      DO NOT ADD/CHANGE --auto-magpie-merge: EVALs!!!
 *      DO NOT DELETE THE ACTION following the EVAL!
 *      DO NOT ADD AN ACTION!
 *      ONLY MODIFY THE EXISTING ACTION!)
 *
 * *************************************************
 */
/*--auto-magpie-code:FapJack_base */
/*--auto-magpie-core:
start
--audio-*
alternate-game-page-example
core-config-example
core-verbiage-example
cum-round
cum-round-pause
cum-round-select
game-difficulty-select
game-lost
game-lost-check
game-lost-rand
game-mode-select
notification-round
penalty*
play
play-shuffle-notice
play-start
rest
rest-end
settings*
win
win-check
win-check2
win-tease
welcome
*/

/*****************************************
 * REQUIRED GAME PAGES
 * ***************************************
 * These pages are required for game to
 * function, but you'll likely need to
 * modify them to fit your needs.
 * ***************************************
 */
/*--auto-magpie-required:
core-config
core-verbiage
game-difficulty-select-image
game-mode-select-image
instructions
welcome-image
common-ending
game-lost-cei
game-lost-ruin
game-lost-deny
*/

/*********************
 * INSTALLING UPDATES
 *********************
 *
 * To merge FapJack updates into an existing FapJack:
 *
 * 1.  Backup your existing tease. (Very important!)
 * 2.  Open FapJack Base in Eos Magpie:
 *     https://codepen.io/fapnip/full/GRjwPXP?id=47408&key=ae797ac48c
 * 3.  As the "target" tease, enter your tease's URL
 * 4.  Review pre-selected items.  (If you've modified this init script,
 *                                  auto-update may not work.)
 * 5.  Click the big blue download button.
 * 6.  Import the downloaded JSON over your tease.
 * 7.  If there were changes to core-config-example or core-verbiage-example, check to see if
 *      you need to implement any of those changes in your core-config or core-verbiage pages.
 *      Review CHANGE LOG to see if there's anything else you may need to do.
 *      (Don't modify *-example pages.  They're there for reference only.)
 * 8.  Test your tease.  If broken, restore from backup and try again.
 *
 */

/*****************
 * CHANGE LOG
 *****************
 * 
 * 1.16.0
 *    - Move stroking options to settings-stroking page
 *    - Add Game Difficulty option to control stroke speed, etc.
 *    - Add aliasOf setting property to allow linking to same setting from multple places
 *    - Alias new "Game Difficulty" setting from stroking options as "Intensity"
 * 
 * 1.15.6
 *    - Update to SimpleBeats 0.8.3 to try to avoid beat playing on init
 * 
 * 1.15.5
 *    - Update "-audio-1" beat sound to one that works on more devices
 *      (Update your -audio-1 page if you used the old "beat-pop-*" sounds there.)
 * 
 * 1.15.4
 *    - Update timer polyfill
 * 
 * 1.15.3
 *    - Destroy Sound instances before loading new audio page.
 * 
 * 1.15.2
 *   - Update setTimeout and SimpleBeats
 * 
 * 1.15.1
 *   - Tweak some beat settings
 * 
 * 1.15.0
 *   - Update mergeObect string field merger to allow more flexible method calling
 *   - To help with metronome issues on older devices:
 *   -   Update setTimeout polyfill to v1.1
 *   -   Use new, simplified, SimpleBeats instead of Beats for dynamic metronome
 *   -   Remove TitleAnimator that Beats used, but FapJack didn't need
 *   - (Changes are in Init Script and start page)
 * 
 * 1.14.9
 *   - Fix volume adjustment (Init Script and settings-beat-volume)
 * 
 * 1.14.8
 *   - Add onGameReset hook
 *   - Add onSaveState hook
 *   - Add onGameRestore hook
 *   - Add public setGameState setter
 *   - Add public getGameState getter
 * 
 * 1.14.7
 *   - Don't use remapped level for penalty option generators
 * 
 * 1.14.6
 *   - Fix potential infinite loop in resetToCore
 * 
 * 1.12.17 - 1.14.5
 *   - Too many changes to list, too lazy to add
 * 
 * 1.12.17
 *   - Set defaults for some settings in Init Script
 * 
 * 1.12.15
 *   - Track moan play state
 * 
 * 1.12.14
 *   - Add playMoans feature, and ability to call it from verbiage
 * 
 * 1.12.13
 *   - Fix incorrect inRoundNoFapTime
 * 
 * 1.12.12
 *   - Allow parent setting's reset to realod reset audio profile
 * 
 * 1.12.11
 *   - update audio profile example
 * 
 * 1.12.10
 *   - Allow Reset to work on audio profiles setting page
 * 
 * 1.12.9
 *   - Allow defined audio profile pages and profile page array to differ in length.
 * 
 * 1.12.8
 *   - Add audio profiles
 * 
 * 1.12.7
 *   - Fix penalty occurrence merging
 * 
 * 1.12.6
 *   - Fix hang introduced in 1.12.5
 * 
 * 1.12.5
 *   - Fix some bugs in settings
 *   - Allow integer options in radio buttons
 * 
 * 1.12.4
 *   - Add String.prototyle.style([style], [class])
 * 
 * 1.12.3
 *   - Add String.color([html color]), .size(1.2), .spacing(1.2), 
 *     .bold(), .italic(), .underline(), .br(), .p()
 *     for text styling in verbiage strings.
 * 
 * 1.12.2
 *   - Allow reloading randomized round image pages
 * 
 * 1.12.1
 *   - Fix issue with penalty id resolution
 *
 * 1.12.0
 *   - Unified/simplified image loaders
 *
 * 1.11.5
 *   - Added  winCheckBpm and winCheckRefresh settings
 *   - Modify win-check to refresh cum tease
 *   - Added [mode]-cumtease-[cum-mode] image page for cum tease.
 *
 * 1.11.4
 *   - Move buttons to verbiage
 *   - Change select page timers
 *   - Move sounds to start so they preload when Eos loads tease
 *   - Add welcome-image
 *
 * 1.11.3
 *   - Fix issue with resetting a blocked setting
 *
 * 1.11.2
 *   - Update instructions
 *   - Fix bug in game.getRadioObject
 *   - Add block method to settings
 *   - Add example settings blocker (see kinkAnal override in core-config-example)
 *
 * 1.11.1
 *   - Add rouletteBpm game setting to allow overriding sound for bpm.
 *
 * 1.11.0
 *   - Refactor "mergeObject(randomString(t.verbiageKey), game)" to "game.text('verbiageKey')"
 *
 * 1.10.14
 *   - Fix issue with re-locking game
 *
 * 1.10.13
 *   - When ulp (unlocked) setting is reset, try to rest to locked game config
 *   - Fixed bug in random mode select skipper
 *
 * 1.10.12
 *   - Generate titles and show buttons in difficulty/game/cumround-select
 *     using common methods instead of in-line.
 *
 * 1.10.11
 *   - Add 'alternateGamePage' options to game modes
 *
 * 1.10.10
 *   - Add post-hand intermission pages: [mode]-interp-[level/cum-mode]-[hand]
 *
 * 1.10.9
 *   - Properly clear random selector button
 *
 * 1.10.8
 *   - Add random selector button to mode select pages
 *   - Fix a couple bugs
 *
 * 1.10.7
 *   - Fix bugs
 *
 * 1.10.6
 *   - Add skip/timer settings
 *
 * 1.10.5
 *   - Add missing game.getRadioObject method
 *
 * 1.10.4
 *   - Add setting radio button selections and examples
 *
 * 1.10.3
 *   - Make setSettingOption index position relative to setting's page
 *
 * 1.10.2
 *   - Automatically generate settings reset message so it doesn't have to be defined.
 *   - Add example of how to add a new settings menu page.
 *
 * 1.10.1
 *   - Fix a couple bugs introduced in 1.10.0
 *   - Add simple "penalty-custom-example", and use example.
 *
 * 1.10.0
 *   - Dynamically build settings pages
 *   - Allow easy addition of custom setting options
 *   - Allow modification of existing setting option lables/icons/placement
 *   - Add showSetting game option object for hiding/showing setting options
 *   - Merge existing penalty occurrence definitions instead of replace
 *
 * 1.9.30
 *   - Fix bug in penalty occurrence probability overrides
 *
 * 1.9.29
 *   - Fix some bugs.
 *   - Fix penalty limit override examples
 *
 * 1.9.28
 *   - Update auto-magpie instructions
 *   - Add penalty limit override examples in core-config-example
 *   - Add custom penalty override examples in core-config-example
 *
 * 1.9.27
 *   - Add hooks for setting penalty limits (faps, bpms, etc.)
 *   - Implement game difficulty selection
 *      (update your game-difficulty-select-image)
 *   - Add difficultyAutoSelect, difficultySelect1, difficultySelect2 verbiage
 *      (update your core-verbiage!)
 *   - Add difficulties game config option.
 *      (update your core-config!)
 *
 * 1.9.26
 *   - Add Eos Magpie auto-update
 *
 * 1.9.25
 *   - Change update instructions
 *
 * 1.9.24
 *   - Allow rest to skip all penalties instead of just edge
 *
 * 1.9.23
 *   - Fix image load time timer offset
 *
 * 1.9.22
 *   - Update instructions in Init Script
 *
 * 1.9.21
 *   - Fix core verbiage not being consistently re-loaded between levels
 *
 * 1.9.20
 *   - Fix the way config file loads are detected
 *
 * 1.9.19
 *   - Rename cumToWinTimeMin to winToCumTimeMin, since that's what it's used for
 *
 * 1.9.18
 *   - Add cumToWinTimeMin game setting
 *
 * 1.9.17
 *   - Fix cum round beat issue
 *
 * 1.9.16
 *   - !! You must update your 'play' page !!
 *   - Properly save intermission state
 *   - Restart cum round from beginning on game restore
 *   - Simplify play page, move code to game.checkStatus
 *   - Fix potential crash in play loop
 *
 * 1.9.15
 *   - Add Intermission pages:
 *      [mode]-inter-[level/cum-mode]-[hand]
 *
 * 1.9.14
 *   - Update image page use documentation
 *
 * 1.9.13
 *   - Yet more dev mode fixes
 *   - Update comments
 *
 * 1.9.12
 *   - More dev mode fixes
 *
 * 1.9.11
 *   - In winToCum rounds, don't count time images take to load against time left
 *
 * 1.9.10
 *   - Fix mode arrays not being reset in development mode
 *
 * 1.9.9
 *   - Restore accidentally removed 'hasChangedSettings' function
 *
 * 1.9.8
 *   - Let user know when we start to attempt the long process of decrypting locked features
 *
 * 1.9.6
 *    - Add penalty occurrence overrides
 *
 * 1.9.5
 *    - Add done button to instructions so you don't have to click through the
 *       entire thing if you don't want to.
 *
 * 1.9.4
 *   - Automate fall-back for game over and win images in order of preference:
 *      [mode]-game-over-[level/cum-mode]
 *      [mode]-game-over
 *      game-over-image
 *      [mode]-win-[level/cum-mode]
 *      [mode]-win
 *      win-image
 *
 * 1.9.3
 *   - Automate fall-back to image loaders in order of preference:
 *      [mode]-image-[level]-[hand]                        (discrete image loader)
 *      [mode]-image-[level]-[1 through current-hand]plus  (*** range image loader)
 *      [mode]-image-[level]                               (level image loader)
 *
 *      *** A range image loader page example would be:
 *          melody-image-1-3plus
 *          This would load images for any level 1 hand at or above index 3 that does not
 *          have a discrete image loader page or a more applicable range loader that would
 *          take precedence.
 *
 * 1.9.2
 *   - Fix an issue with the verbiage randomizer.
 *
 * 1.9.1
 *   - Added game.setHandConfigOverride({...}) and game.setHandVerbiageOverride({...}) methods
 *      to be used in [mode]-image-[level]-[hand] pages, allowing overriding game settings
 *      on a per hand basis.  Example:
 *      game.setHandConfigOverride({dealerName: 'Different Name'});
 *      To override dealer name for a single hand.
 *
 * 1.9.0
 *   - Move game configuration variables to "core-config" page
 *   - Move verbiage configuration to "core-verbiage" and "[mode]-verbiage-[level/cum-mode]" pages
 *
 * 1.8.1
 *   - Added cumToWinTimer game option to enable use of remaining winToCum round time
 *      as time limit to cum.
 *
 * 1.8.0
 *   - Reset config to core before loading level config.
 *   - Added optional roundLimits option to mode configuration,
 *       allowing some levels to be shorter than others.
 *   - Validate configuration and image pages before attempting to load them.
 *
 * 1.7.4
 *   - Better adjustment to blackjack win notification class
 *
 * 1.7.3
 *   - Fix an issue with object randomizer
 *
 * 1.7.2
 *   - Adjust class of blackjack win notifications to work on mobile devices
 *
 * 1.7.1
 *   - Move some game getter/setters/vars below the game setting area.
 *
 * 1.7
 *   - Adjust penalty probabilities
 *
 * 1.6
 *   - Optimize object randomizer
 *
 * 1.5 and below
 *   - Too many changes to list
 *
 */

Thanks to Morexis for many great ideas and countless hours testing/debugging this first attempt at an Eos core game engine.
Last edited by fapnip on Mon Sep 06, 2021 6:18 pm, edited 3 times in total.
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

Thank you for releasing the code! The core game is amazing and I'm glad to be able to make my own versions of it. I just released what's essentially just a reskinned version with Mia Khalifa. It was super simple to do thanks to your code base.

There was one thing that I wish I could have done but maybe you know a better way. I made a "short" and a "full" version like in your example code, but I'd like them to share images and cum rounds.

Is there a way to override the image prefix for a game type? For example: I used "mia" as the game mode name in the full version and "miashort" as the game mode name for the short version. I'd like to specify that "miashort" use images with prefix "mia" instead of "miashort" and perhaps overload a round number too so that I can either pick from one of the three rounds of images I created or randomize which round the short version picks from.

As for the cum rounds, it's a pretty similar situation. I just duplicated all the images and renamed them to show "miashort" instead of just "mia", but if there's a simple way to do this without that duplication please let me know!

Either way, thanks again for letting me stand on the shoulders of giants with this one. Lots of great work went into this and it's hugely appreciated. So, I figured I'd ask the expert before reinventing the wheel! Let me know what you think.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

ksmithucla wrote: Thu Jul 22, 2021 2:36 am Is there a way to override the image prefix for a game type? For example: I used "mia" as the game mode name in the full version and "miashort" as the game mode name for the short version. I'd like to specify that "miashort" use images with prefix "mia" instead of "miashort"
the modePath setting will do this.

For example, if your game modes something like are:

Code: Select all

gameModes:{
  melody: {
    title: 'Example one',
      levels: 3,
      perLevel: 5,
      ...
  },
  melody2: {
    title: 'Example one',
      levels: 3,
      perLevel: 5,
      ...,
      modePath: 'melody',
  },
}
The 'melody2' game mode will should load pages defined for the 'melody' game mode.
ksmithucla wrote: Thu Jul 22, 2021 2:36 amand perhaps overload a round number too so that I can either pick from one of the three rounds of images I created or randomize which round the short version picks from.
Not sure I fully understand what you're asking for here.
ksmithucla wrote: Thu Jul 22, 2021 2:36 amAs for the cum rounds, it's a pretty similar situation.
IIRC, that's what the 'cumRoundAlt' property is for in the cum round's 'gameSettings' object. For example:

Code: Select all

gameModes:{
  melody: {
    title: 'Example one',
      levels: 3,
      perLevel: 5,
      ...,
      cumRoundModes: {
        'cum1': {
        title: 'One',
        rounds: 3,
        gameSettings: {
          winToCumTime: 45, // Must win within 45 seconds
          ...
        }
        ...
      },
      'cum2': {
        title: 'Two',
        round: 3,
        gameSettings: {
          winToCumTime: 60, // Must win within 60 seconds
          cumRoundAlt: 'cum1', // Use images from cum1 
        },
      },
    },
  },
  ...
}
Let me know if it doesn't work as it should. Not sure if I've tested that recently.
ksmithucla wrote: Thu Jul 22, 2021 2:36 amEither way, thanks again for letting me stand on the shoulders of giants with this one. Lots of great work went into this and it's hugely appreciated. So, I figured I'd ask the expert before reinventing the wheel! Let me know what you think.
You're welcome! :blush: Thanks for making a FapJack!
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

modePath worked like a charm, thanks!

As for "overload a round number", let me try describing it differently. Now that I'm using one "modePath" of "mia" (or in your example "melody"), I want the "Short" game mode to pick one "round" of images from the "Full" game mode. So if there are 3 rounds in the full game (1-3) I'd like the "Short" mode to pick a random number between 1 and 3 and use images from that round for its single round. So, if 3 is picked randomly, I want it to use mia-image-3-1 instead of mia-image-1-1 for its first hand and for it to continue to use the prefix mia-image-3- for the rest of the round. Does that make sense? I know it's a bit of a strange request, but if it's possible I'd like there to be variation in the short round if it's only one round!

And similar to modePath, cumRoundAlt worked great! Once modePath was set up correctly, cumRoundAlt pulled from the same image set so I no longer have to duplicate the whole cum round image sets.

Once again, you're far too kind for first making such a useful codebase and now also supporting it for people like me. It's very much appreciated!
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

ksmithucla wrote: Thu Jul 22, 2021 6:52 pm So, if 3 is picked randomly, I want it to use mia-image-3-1 instead of mia-image-1-1 for its first hand and for it to continue to use the prefix mia-image-3- for the rest of the round.
You could probably do something like this (completely untested, remapLevel hasn't been debugged in a long time):

Code: Select all

...
gameModes:{
  melody: {
    title: 'Example one',
    levels: 3,
    perLevel: 5,
      ...
  },
  melody2: {
    title: 'Example one',
    levels: 1,
    perLevel: 5,
      ...,
    modePath: 'melody',
    remapLevel: function(realLevel, currentHand) {
      // realLevel contains the actual level, but since we only have one level, we're going to ignore it
      if (!window._mylevelRemapper) {
        // Probably first call to this fn.  randomize a level between 1 and 3
        window._mylevelRemapper = randomInt(1, 3)
      }
      return window._mylevelRemapper
    },
  },
}
...
One thing to note however, the randomized remap isn't stored to the player's tease storage like the rest of the game, so if the player tries to resume the game, they'll likely end up on a different remapped level.

Edit: did a quick test, and it looks like there was a bug where penalties would incorrectly use the remapped level. Should be fixed in v1.14.7 (Only change is in the init script)
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

Well it seems remapLevel works just as you described! And also as you described, it will be random on each load even if resuming... I thought I might have a solution by making an invisible "setting" to capture this value, but I must be doing something wrong.

I used setSettingOption like in your example code to create an invisible setting with the default value of 0:

Code: Select all

// Add hidden "randomly selected round" option
game.setSettingOption(
  // Setting name is '$randomRoundSelection' (custom settings must start with '$')
  '$randomRoundSelection', 
  // Setting definition:
  {
    type: storageTypes.GAME, // Use this, unless you've created your own
    label: 'Stored Random Round Selection', // What to display in menu
    textKey: 'RandomRoundSelection', 
    page: 'none',
    storageKey: '$storedRandomRound',
    key: '$rRS', // short key for storage
    defaultValue: 0, // Default value
  },
  1
)
Then, I access it in the definition of the game mode "miashort" where I run the remapLevel function:

Code: Select all

  remapLevel: function(realLevel, currentHand) {
    console.warn('Random Round Selection was: ' + game.$randomRoundSelection)
    if (game.$randomRoundSelection == 0) {
      game.$randomRoundSelection = randomInt(1, 3)
      console.warn('Random Round Selection now set to: ' + game.$randomRoundSelection)
    }
    return game.$randomRoundSelection
  },
Am I accessing that setting correctly? Or do I need to use getSettingOption with the key? Or maybe something else like I didn't define the setting right? Or maybe I'm just barking up the wrong tree :lol: let me know what you think!
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

ksmithucla wrote: Fri Jul 23, 2021 12:07 am let me know what you think!
A game setting won't work for this, since it needs to be reset when the game ends and is reset. Needs to be tracked/saved with the rest of the game state.

I've added some hooks/getters/setters that you can use in v1.14.8 (Changes are only in Init Script)

Getter/setters:
game.getGameState(key)
game.setGameState(key, value)

(Always prefix any custom game state keys you're setting with '$' to avoid conflicts with existing keys, and keep the names extremely short. Like '$lr' short.) Also, keep any values tiny as well. We only get 1KB total for tease storage, and that includes all JSON encoding.

Optional Hooks:
onGameReset // Called when game state is reset (end of game)
onSaveState // Called before game saves its state
onGameRestore // Called when saved game is restored


Untested Example (requires v1.14.8):

Code: Select all

game.setConfig({
  ...
  onGameReset: function(skipStorage) {
    // if skipStorage is true, don't do any teaseStorage write operations!
    // (we don't do need to do any tease storage operations, since we're using setGameState)
    game.setGameState('$lr', null) // Clear our level remap value 
  },
  ...
  gameModes: {
    melody: {
      title: 'Example one',
      levels: 3,
      perLevel: 5,
      ...
    },
    melody2: {
      title: 'Example one',
      levels: 1,
      perLevel: 5,
      ...,
      modePath: 'melody',
      remapLevel: function(realLevel, currentHand) {
        var $lr = game.getGameState('$lr')
        if (!$lr) {
          $lr = randomInt(1, 3)
          game.setGameState('$lr', $lr) // will get cleared when game resets, should get restored on resume
        }
        return $lr
      },
    },
  },
  ...
})

ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

Ok you're way too helpful :lol: thank you for building this in! I used your example and it worked exactly as intended. Good notes on the storage limits, I'll keep that in mind with state variable names going forward.

I can't believe how easy it is to update the core code too. You're an actual wizard. Thank you so much for all your help!
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

1.14.9 fixes an issue with the beat volume setting.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

v1.15.0 attempts to improve metronome performance for older/slower devices.
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

With thanks to Carnal1 for helping debug, v1.15.5 should help with the missing/skipping metronome sounds some players were experiencing.
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

Ok I committed a cardinal sin, I modified the "welcome" page... I made a short warmup as a choice off of the welcome page that just goes to the warmup page I created and returns to the welcome page after. Do you recommend going about this a different way so I don't have trouble updating the core code in the future?
fapnip
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Mon Apr 06, 2020 1:54 pm

Re: [CODE RELEASE] FapJack

Post by fapnip »

ksmithucla wrote: Fri Sep 03, 2021 11:54 pm Do you recommend going about this a different way so I don't have trouble updating the core code in the future?
You could just create a [mode]-inter-1-1 page that would automatically be displayed before the round starts.

In the example tease, a page that would display before "Full Game" (melody) example mode starts would be "melody-inter-1-1".

There's an example intermission page in the example tease named "melody2-inter-1-3", but the main thing is that you just do a:

Code: Select all

returnToCaller();
inside an eval when you're done with your intermission.
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

Awesome, I figured out a way to make intermissions work with the various modes while still using remapLevel(). Thanks for the suggestion! Now I should be back on the updates train
ksmithucla
Explorer
Explorer
Posts: 21
Joined: Wed Dec 21, 2011 8:05 am

Re: [CODE RELEASE] FapJack

Post by ksmithucla »

For some reason I'm hearing a random metronome noise when I load either fapjack I've made in FireFox, do you know what might cause that? It looks like the core code matches up when I checked the latest version. It's happening with both the one I just released and the Mia one.
Post Reply