Giter Site home page Giter Site logo

picocyoa's Introduction

PicoCYOA

Pico Choose Your Own Adventure is a pico framework for creating interactive fiction written in pure html and Javascript.

Features:

  • Simple to write - use pure html elements
  • No compilation - all you need is a text editor
  • No bulky framework - only requires a SINGLE js import

Highlights

Below is the simplest possible story with two possible paths:

  <head> <link rel="stylesheet" href="styles.css"> </head>
  <body>
    <script src="PICOCYOA.js"></script>
      <story-container id="mystory">
        <story-title><h1>Simplest possible story</h1></story-title> <hr/>

        <story-segment id="startSegment" show>
          <segment-content> <p>Choose from options below to progress story:</p> </segment-content>
          <ul>
            <segment-choice target="badEnding"><li>leads to bad ending</li></segment-choice>
            <segment-choice target="goodEnding"><li>leads to good ending</li></segment-choice>
          </ul>
        </story-segment>

        <story-segment id="badEnding">
          <segment-content> <p>Rip GG</p> </segment-content>
        </story-segment>

        <story-segment id="goodEnding">
          <segment-content> <p>nice work</p> </segment-content>
        </story-segment>
      </story-container>
  </body>

Stories are defined using custom html elements placed inside the html body tag. Each segment has a unique id and story sections are chained together using the segment-choice elements.

Example Stories

A full version of the example that will work in browser is included in the repo: Simplest Story.

Also included is the example file Full Story contains a working example of all features including: conditional rendering.

Conditional rendering

PicoCYOA affords conditional section rendering of segment choices via utilising pure JavaScript. Using the condition property you can show paths only if certain conditions are met, e.g. if the reader has explored certain paths.

While you can utilize any JavaScript you wish, the repo includes a library for basic functions. The included script basicfunctions.js provides a library of Javascript functions for managing state like scores. Please not that the use of this library is not required for choice based navigation.

The following example demonstrates how to easily track a score using the provided scoreAdder function:

<story-segment id="middleSegment">                                      
          <segment-title>middle Segment</segment-title>                         
          <segment-subtitle>we are in the middle of the story</segment-subtitle>                       
          <segment-content>                                                     
            <p>You can mixin with existing html elements and use javascript to manage state.</p>
            <form action="">                                                    
              <input type="button" value="Click me a few times" onclick="scoreAdder(3);"/>
            </form>                                                             
          </segment-content>                                                    
                                                                                
          <ul>                                                                  
            <segment-choice target="badEnding"><li>leads to bad ending</li></segment-choice>
            <segment-choice target="goodEnding"><li>leads to good ending</li></segment-choice>
            <segment-choice target="excellentEnding" condition="{() => currentScore >= 10 }"><li>leads to best ending</li></segment-choice>
          </ul>                                                                 
</story-segment>                                                        

Tools for Managing the Story Writing

The included Grapher provides the ability to open a story and view the graph of connections between the story segments. This can be useful to visualise the potential paths in the story. Further the graph shows when you have declared a segment but forgotten to write it! Here you can see the result of running on the example story advanceParty.html included in the repo:

Example graph

Get Started

  1. Download the repo
  2. Open the file Full Story from your local hard disk in your web browser
  3. Explore the story and get a feel for the features
  4. Make a copy of Simplest Story within the repo, and rename to your story of choice
  5. Open your new file in your browser
  6. Start Editing your new file using your favourite editor. Use Full Story as a reference to discover how to use features
  7. Use the documentation below for detailed explanation of features

Documentation

full element overview plz

  • logging to help debugging
  • JS in conditions
  • better css (version without css?, or at least one that allows easier mixin.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.