Skip to content

Instantly share code, notes, and snippets.

@Akjosch
Akjosch / backup_event.tw
Last active May 21, 2020 11:02
Random event engine for SugarCube/TweeGo
:: Backup Event [event]
/*
PRIORITY: Number.MIN_SAFE_INTEGER
*/
<div class="error-view"><span class="error">No valid events found. Write some?</span></div>
@Akjosch
Akjosch / dice.roll.js
Last active November 12, 2021 13:50
Simple dice roller function for SugarCube
/**
* Roll a dice.
*
* Supported variants:
*
* * a plain number; no rolling done, just returns that number
* * a percentage chance as string ("15%", "99%"); returns 1 with the given percent chance, else 0
* * a (number)d(size) notation ("3d6", "1d20", "7d123"); rolls that many-sided die and returns the sum
* if the number is omitted, 1 is assumed ("d8" is the same as "1d8")
* if the size is ommited, 6 is assumed ("5d" is the same as "5d6")
@Akjosch
Akjosch / enhancedmacros.js
Created May 6, 2020 13:41
Slightly enhanced link and button macros for SugarCube 2
/* Added options to add a pop-up, a custom class a custom ID for styling */
Macro.add(['ibutton', 'ilink'], {
isAsync : true,
tags : ["comment"],
handler() {
if (this.args.length === 0) {
return this.error(`no ${this.name === 'ibutton' ? 'button' : 'link'} text specified`);
}
const $link = jQuery(document.createElement(this.name === 'ibutton' ? 'button' : 'a'));
@Akjosch
Akjosch / example.md
Last active May 1, 2020 11:41
SugarCube <<when>> macro, delaying execution of the code block until a promise is resolved

Example usage:

<<set _promiseGen = function() {
    return new InspectablePromise(function(resolve, reject, progress) {
        setTimeout(function() { resolve(random(1, 100)); }, 2000);
    });
}>>
<<when _promise = _promiseGen()>>
 The value returned from the promise is &lt;&lt;= _promise.value&gt;&gt;.
@Akjosch
Akjosch / Background.gd
Last active February 2, 2020 09:50
Godot dragging 2d objects
extends TextureRect
const images = [preload("res://bgs/background1.jpg"),
preload("res://bgs/background2.jpg")]
func _ready():
randomize()
set_texture(images[round(rand_range(0,1))])
@Akjosch
Akjosch / AKJ_SmartPath.js
Created November 22, 2019 15:58
Efficient A* routing replacement for the SMARTMOVE plugin for RPG Maker MV - with no range limit
//=============================================================================
// Smart Pathfinding
// by Shaz (originally)
// Last Updated: 2019-11-22 by Akjosch
//=============================================================================
/*:
* @plugindesc Allows events or players to do smart Pathfinding
* @author Shaz (originally)
*
@Akjosch
Akjosch / dijkstra+binaryheap.js
Last active November 21, 2019 10:22
Simple generic implementation of Dijkstra's algorithm for SugarCube - will work with almost no changes in any modern browser though
/* More complex, performance-improved version using a binary heap for the "open nodes" set */
/* Binary heap class source by Marijn Haverbeke, https://eloquentjavascript.net/1st_edition/appendix2.html, modified */
/**
* Use Dijkstra's algorithm to find the lowest-cost route between start and target nodes
* given a graph implementation which provides us with a suitable way to query
* the neighbors of a node as well as the cost of traversing from one (source) to
* a connected next (target) node.
*
* Note that this implementation relies on the individual nodes being equal under
@Akjosch
Akjosch / stat.babel.js
Last active November 16, 2019 12:48
Mod-carrying Stat value for SugarCube
"use strict";
/* Compatibility version for older browsers, created with Babel */
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototy
@Akjosch
Akjosch / event_setup.js
Created October 29, 2019 14:55
Setting up events from event-tagged passages in SugarCube, simple version
class GameEvent {
/**
* @param {string} target
* @param {string} trigger
* @param {string} weight
* @param {string} priority
*/
constructor(target, trigger, weight, priority) {
this.target = String(target);
this.trigger = trigger;
@Akjosch
Akjosch / inventory1.tw
Last active October 26, 2019 03:48
Simple inventory display
:: Inventory 1 [nobr]
/* constant data - item pool mostly (goes into StoryInit) */
<<set setup.items = {
}>>
<<set setup.createItem = function(id, data) {
id = String(id);
data = data || {};
data.id = id;