Skip to content

Instantly share code, notes, and snippets.

@Akjosch
Akjosch / MapInputProcessor.java
Created October 7, 2015 19:39
Example mouse-driven map input processor for libgdx
package mygame;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
/**
* A simple input processor which supports dragging the view by clicking and holding the left mouse button,
@Akjosch
Akjosch / articles.min.js
Last active October 24, 2019 10:21
UMD+SugarCube-wrapped, minified Articles library from https://github.com/chadkirby/Articles
/* copy & paste into JavaScript portion of your code, or use with require.js */
/* when directly copied into a SugarCube environment, adds itself as setup.Articles */
(function(e,a){"function"===typeof define&&define.amd?define([],a):"object"===typeof exports?module.exports=a():"object"===typeof setup?setup.Articles=a():e.Articles=a()})("undefined"!==typeof self?self:this,function(){var e=[].slice;var a={0:{8:{_:"an"},9:{_:"an"},"-":{1:{1:{_:"an"}},4:{" ":{_:"a"},_:"an"},6:{"-":{_:"an"}},8:{_:"an"}}},1:{1:{0:{_:"a"},1:{_:"a"},2:{_:"a"},3:{_:"a"},4:{_:"a"},5:{_:"a"},6:{_:"a"},7:{_:"a"},8:{_:"a"},9:{_:"a"},_:"an",".":{4:{_:"a"}}},8:{0:{0:{_:"an"},1:{_:"an"},2:{_:"an"},
3:{_:"an"},4:{_:"an"},5:{_:"an"},6:{_:"an"},7:{_:"an"},8:{_:"an"},9:{_:"an"},_:"a"},1:{"-":{_:"a"}," ":{_:"a"}},2:{"-":{_:"a"}," ":{_:"a"}},3:{"-":{_:"a"}," ":{_:"a"}},4:{"-":{_:"a"}," ":{_:"a"}},5:{"-":{_:"a"}," ":{_:"a"}},6:{"-":{_:"a"}," ":{_:"a"}},7:{"-":{_:"a"}," ":{_:"a"}},8:{"-":{_:"a"}," ":{_:"a"}},9:{"-":{_:"a"}," ":{_:"a"}},_:"an"}},8:{
@Akjosch
Akjosch / tippy.js
Created September 12, 2018 07:13
UMD+SugarCube version of tippy.js
(function(t,e){'object'==typeof exports&&'undefined'!=typeof module?module.exports=e():'function'==typeof define&&define.amd?define(e):'object'==typeof setup?setup.tippy=e():t.tippy=e()}('undefined'!=typeof self?self:this,function(){'use strict';function t(t){return'[object Object]'==={}.toString.call(t)}function a(t){return[].slice.call(t)}function o(e){if(e instanceof Element||t(e))return[e];if(e instanceof NodeList)return a(e);if(Array.isArray(e))return e;try{return a(document.querySelectorAll(e))}catch(t){return[]}}function r(t){t.refObj=!0,t.attributes=t.attributes||{},t.setAttribute=function(e,a){t.attributes[e]=a},t.getAttribute=function(e){return t.attributes[e]},t.removeAttribute=function(e){delete t.attributes[e]},t.hasAttribute=function(e){return e in t.attributes},t.addEventListener=function(){},t.removeEventListener=function(){},t.classList={classNames:{},add:function(e){return t.classList.classNames[e]=!0},remove:function(e){return delete t.classList.classNames[e],!0},contains:function(e){return
@Akjosch
Akjosch / Sprite.js
Last active November 6, 2019 04:43
Example class for SugarCube
/**
* @param {string} tex
* @param {number[]} rect
*/
var Sprite = function Sprite(tex, rect) {
var sp = this;
sp.tex = String(tex);
if (Array.isArray(rect)) {
if (rect.length != 4) {
throw new Error("new Sprite(): rect parameter needs to be exactly four numbers long - [x, y, width, height]");
@Akjosch
Akjosch / dialogue.tw
Last active July 9, 2021 09:56
Simple one-passage VN-like message box for Twine/SugarCube 2
:: Dialogue
/* dialogue variables - typically something you pass to the initial widget instead of setting them globally */
<<set _dialog = [
{ actor: "A female", text: "Hi!", enter: "<<set $in_dialog = true>>" },
{ text: "Fancy seeing you here ..."},
{ text: "So, do you like my new shoes?", exit: "<<set $in_dialog = false>><<goto 'Next Passage'>>" }
]>>
<<set _dialogIdx = -1>>
@Akjosch
Akjosch / dialogue2.tw
Last active November 5, 2019 10:30
Another SugarCube one-passage dialogue example
/* The dialogue setup - typically at the start of the passage */
<<set _dialogue = {
"": {
text: "<div>Before you stands a wizard, clad in heavy robes, scarves, and a pointed hat. He gives a cheerful but heavily muffled greeting. <q>Ownt fon?</q> the wizard inquires as he holds out a handful of rings which radiate magical energy.</div><div>Take one?</div>",
choices: [
{ text: "One with a shiny jewel on top!", next: "death" },
{ text: "A band with runes glowing around it!", next: "runes" },
{ text: "Mom told me not to accept strange items from people I don't know&hellip;", next: "death"},
{ text: "Go away.", next: "death", filter: "$day != 7" }
]},
@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;
@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 / 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 / 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