npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-gamefic

v2.0.0

Published

React components for Gamefic

Downloads

81

Readme

react-gamefic

React components for Gamefic.

Requirements

This project requires Node, Ruby, and the Gamefic SDK. The SDK is available as a RubyGem:

$ gem install gamefic-sdk

Using React and Gamefic

Run the following commands to create a new Gamefic project that targets the React platform:

$ gamefic init my-game
$ cd my-game
$ rake web:generate
$ rake web:build

The web:generate task creates the React application in the web directory. The web:build task compiles the application in the web/build directory.

The Basics

The generated app is designed to be as mininal as possible while still providing the base functionality of a playable game. The only required component library is react-gamefic, although it also uses react-modal to power the menu options. Most styles and UI elements should be easy to modify, extend, or replace altogether.

The Console Component

The Console is the top-level game container. It accepts a driver prop and provides a context for other components.

The driver prop accepts a Driver object as defined in the gamefic-driver package.

The Terminal component provides a common component for rendering scenes.

The Modals component provides modal dialogs for saving and restoring games.

Scenes

The Terminal takes a typedScenes prop that provides components for rendering different types of scenes.

  • Activity - The top-level component for Activity scenes.
  • MultipleChoice - The top-level component for Multiple Choice scenes.
  • YesOrNo - A specialized MultipleChoice scene.
  • Pause - The top-level component for Pause scenes.
  • Conclusion - The top-level component for Conclusion scenes.

All the scene components are exported into the project for ease of customization.

It's also possible to configure a namedScenes prop to use specialized components for user-defined scenes. One possible use for a named scene component is a minigame that the player must complete before proceeding with the story.

Scene Components

  • CommandForm - A form with a text input for accepting typed commands.
  • CommandButton - A button that triggers a command.
  • CommandLink - A button styled as a link that triggers a command.
  • Turn - The display for a single turn's output.
  • History - A collection of previous Turns.
  • HtmlText - A display container for messages.
  • OptionList - A list of command links, such as the options in a Multiple Choice scene.

Modals

The Modals component provides modal dialogs for saving and restoring game snapshots. There is also a Modal component based on react-modal that can be used to create custom modals with the same default style.

Built-in Styles

The react-gamefic package includes several styles that can be imported into projects. To import the terminal style, for example:

import 'react-gamefic/styles/terminal'; // Import the built-in style first
import './style.css';                   // Import your own style second to add your customizations

The following styles are available:

  • normal: A minimal foundation for responsiveness and readability. The other built-in styles import normal first.
  • ebook: A simple black-on-white text style.
  • terminal: A green-on-black style designed to emulate command-line terminals.

The app's stylesheet is limited to four classes: .component, .terminal, .modal, and .overlay (a helper element for modals). Styles can be customized by modifying or replacing web/src/style.css. Even the stylesheet imported from react-gamefic is optional.

Testing the Component Library Locally

If you're working on the react-gamefic library itself and need to link to a local copy of react-gamefic, you might run into invalid hook errors. One solution is to add the following aliases to the test app's webpack config, as mentioned in this Stack Overflow discussion:

resolve: {
  alias: {
    'react': path.resolve('./node_modules/react'),
    'react-dom': path.resolve('./node_modules/react-dom')
  }
}

More Info

Refer to the official website or the Gamefic SDK repo for more information about developing with Gamefic.