All Projects → Flaque → Merchant.js

Flaque / Merchant.js

Licence: mit
💰 A Javascript framework for creating idle games

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Merchant.js

Abc
A better Deno framework to create web application.
Stars: ✭ 514 (-6.72%)
Mutual labels:  framework
Arwes
Futuristic Sci-Fi UI Web Framework
Stars: ✭ 5,031 (+813.07%)
Mutual labels:  framework
Vuesax
New Framework Components for Vue.js 2
Stars: ✭ 5,293 (+860.62%)
Mutual labels:  framework
Dotvvm
Open source MVVM framework for Web Apps
Stars: ✭ 523 (-5.08%)
Mutual labels:  framework
Deep Framework
Full-stack JavaScript Framework for Cloud-Native Web Applications (perfect for Serverless use cases)
Stars: ✭ 533 (-3.27%)
Mutual labels:  framework
Waf
Win Application Framework (WAF) is a lightweight Framework that helps you to create well structured XAML Applications.
Stars: ✭ 539 (-2.18%)
Mutual labels:  framework
Operative Framework
operative framework is a OSINT investigation framework, you can interact with multiple targets, execute multiple modules, create links with target, export rapport to PDF file, add note to target or results, interact with RESTFul API, write your own modules.
Stars: ✭ 511 (-7.26%)
Mutual labels:  framework
Porter
💄 Scalable and durable all-purpose data import library for publishing APIs and SDKs.
Stars: ✭ 547 (-0.73%)
Mutual labels:  framework
Spring Data R2dbc
Provide support to increase developer productivity in Java when using Reactive Relational Database Connectivity. Uses familiar Spring concepts such as a DatabaseClient for core API usage and lightweight repository style data access.
Stars: ✭ 534 (-3.09%)
Mutual labels:  framework
Servicestack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
Stars: ✭ 4,976 (+803.09%)
Mutual labels:  framework
Torchlayers
Shape and dimension inference (Keras-like) for PyTorch layers and neural networks
Stars: ✭ 527 (-4.36%)
Mutual labels:  framework
Designcode Swiftui
📱 An app fully written in SwiftUI showcasing beautiful design and animations.
Stars: ✭ 529 (-3.99%)
Mutual labels:  framework
Spring Data Commons
Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
Stars: ✭ 542 (-1.63%)
Mutual labels:  framework
Xqemu
Open-source emulator to play original Xbox games on Windows, macOS, and Linux
Stars: ✭ 518 (-5.99%)
Mutual labels:  games
Ngx Admin
Customizable admin dashboard template based on Angular 10+
Stars: ✭ 23,286 (+4126.13%)
Mutual labels:  framework
Korolev
Single Page Applications running on the server side.
Stars: ✭ 510 (-7.44%)
Mutual labels:  framework
Capstone
Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings.
Stars: ✭ 5,374 (+875.32%)
Mutual labels:  framework
Carina
Carina automation framework: Web, Mobile, API, DB
Stars: ✭ 549 (-0.36%)
Mutual labels:  framework
Framework
The Laravel Framework.
Stars: ✭ 25,679 (+4560.44%)
Mutual labels:  framework
Gear
A lightweight, composable and high performance web service framework for Go.
Stars: ✭ 544 (-1.27%)
Mutual labels:  framework

💰 Merchant.js 💰

Merchant is a system for creating programs that manage changing numbers over time. It's especially useful for creating idle games (sometimes called incremental games), but could potentially be used in other games or programs.

If you're not sure what an idle game is, click here to find out. Note: If you're trying to be productive right now, that link may not be for you.

Merchant works well with Redux, but doesn't require it. Functions return copies and don't modify state. Since Merchant is built on immutable, most of it's key concepts are stored as immutable objects.

To be frank, Merchant is really just a collection of patterns with some helpful functions. It's fairly minimalistic but also gives you a good amount of power without sacrificing efficiency.

Docs here.

Live example here. 🐶

Installation

With yarn:

yarn add merchant.js

With npm:

npm install --save merchant.js

Concepts

Currencies

A currency is a string label for some number in the system. You can define these yourself like you normally would:

const GOLD = "GOLD";
const SILVER = "SILVER";
const MAGIC_POWER = "MAGIC_POWER";

Ledgers

A Ledger in Merchant is an immutable Map object where the keys are currencies and the values are numbers.

const { Map } = require("immutable");
const ledger = Map({ GOLD: 5, SILVER: 10 });

Ledger values can be either positive or negative.

const ledger = Map({ GOLD: -5, SILVER: 10 });

Wallet

A Wallet is a special ledger that keeps your main state. It's generally computed by adding several ledgers together.

You can generally think of all other ledgers as "updates" to your wallet.

Items

An item is something that can be bought and can effect the main ledger. They're generally JSON defined in a pouch file:

// pouch.js
import { GOLD, POWER } from "./currencies";

export const MagicSword = {
  type: "MagicSword",
  cost: () => {
    return Map({ [GOLD]: -5 });
  }
  effect: (state) => {
    return Map({ [POWER]: state.currentPowerLevel });
  }
};

An item must have a type attribute. It's useful to give it the same name as the item itself, but not required.

An item can have a cost function that returns a ledger. This is used by the buy function to determine the cost. Note that value should be negative if you want to subtract from your wallet.

An item can have a effect function that's used by the effects function to generate an effects ledger.

Both of these functions can take in the "state" if you would like. If you're using redux, you can treat these like mini reducers. This is pretty useful if you want to make the cost variable over time or a function of how many items you own.

To pass the state in, you can just throw it in the merchant functions:

const newWallet = buy(MagicSword, wallet, state);
const newLedger = effects(pouch, wallet, state);

Also note that there's no "amount" or "count" attribute in here, nor is this a class with a constructor. Items should not be instantiated. They should not store or contain state. They're blueprints, not objects.

The "amount" of the item can be stored in the wallet. So I can have a wallet that looks like this:

const wallet = Map({
  GOLD: 5,
  MagicSword: 2
});

We do this so that calculating a per-tick case without having to run through 10k "cost" functions.

Helpful Merchant Functions

Summing Ledgers Together

With Merchant, you can sum an arbitrary number of ledgers together.

import { sum } from "merchant.js";

// ...

const ledger = sum(ledgerOne, ledgerTwo, ledgerThree);

Scaling Ledgers

If you would like to multiply all currencies by a number, you can use the scale function:

import { scale } from "merchant.js";

const ledger = Map({ GOLD: 2, SILVER: -10 });
const scaledLedger = scale(ledger, 2);

scaledLedger.get(GOLD); // 4
scaledLedger.get(SILVER); // -20

Checking all values are positive

You can check if all currencies in a ledger are positive with the inTheBlack function:

import { inTheBlack } from "merchant.js";

inTheBlack(Map({ GOLD: 2, SILVER: -10 })); // False
inTheBlack(Map({ GOLD: 2, SILVER: 10 })); // True

Getting Unique Currencies

If you would like the currencies defined in an arbitrary collection of ledgers, you can use the currencies function:

import { currencies } from "merchant.js";

currencies(ledgerOne, ledgerTwo, ledgerThree); // ["GOLD", "SILVER", "MAGIC_POWER"]

Buying items

You can charge the wallet with the cost of an item with the buy function:

import { buy } from "merchant.js";

const newWallet = buy(MagicSword, wallet);

Note that you can also pass in your total state too.

import { buy } from "merchant.js";

const newWallet = buy(MagicSword, wallet, state);

Made with ❤️ by @flaqueeau.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].