Skip to content

Instantly share code, notes, and snippets.

View cyrusfirheir's full-sized avatar
👾
npm i -g common-sense

Cyrus Firheir cyrusfirheir

👾
npm i -g common-sense
  • India
  • 21:59 (UTC +05:30)
View GitHub Profile
@cyrusfirheir
cyrusfirheir / VN-style-dialogue-system(SugarCube-v2)-part1.md
Last active February 25, 2022 08:40
Storing dialogue in plain text and converting it to html elements on the fly using JavaScript.

Storing dialogue in plain text and converting it to html elements on the fly using JavaScript. (Part 1)

Note!
This system is not a replacement for standard usage, and has been developed only to facilitate faster/easier markup of story/dialogue data. In no way is this advanced enough to handle choices and a bajillion conditionals. At least not yet.

This sort of an approach is best suited when one needs to display text sequentially (like in a Visual Novel) without focusing much on writing html or macros. I decided to do something like this because typing:

<<speech "Speaker Name">>
	Speech text
@cyrusfirheir
cyrusfirheir / headsplit.js
Last active August 20, 2020 05:00
Splits text into parts based on a regexp of headers and returns an array of objects with the header and the content. (description is WIP)
//split text by headers (headerRegex, noOfCaptureGroupsInHeaderToReturn)
if(!String.prototype.headsplit) {
Object.defineProperty(String.prototype, 'headsplit', {
configurable: true,
writable: true,
value: function headsplit(regexp, caps = 1) {
const text = this.trim().split(/\r?\n/);
let retArr = [],
_header = "",
_content = "",
@cyrusfirheir
cyrusfirheir / Live-updates of variables displays on change - overview.md
Last active July 12, 2020 05:57
Pseudo one-way data-binding SugarCube 2 and JS variables with DOM elements.
@cyrusfirheir
cyrusfirheir / timer.js
Last active July 5, 2020 11:32
Timers with Pause/Resume/Reset
window.Timer = function(callback, duration = 500) {
if (!callback) return;
this.callback = callback;
this.duration = duration;
this.remaining = duration;
this.resume();
};
Timer.prototype.resume = function() {
this.start = new Date();
@cyrusfirheir
cyrusfirheir / hold-down.js
Last active July 29, 2020 04:39
jQuery extension which adds a 'click/tap and hold' handler - For SugarCube 2
(function () {
"use strict";
jQuery.fn.extend({
holdDown: function holdDown(duration, handler) {
if (this.length === 0 || arguments.length === 0) return this;
if (arguments.length === 1) {
handler = arguments[0];
duration = 1000;
@cyrusfirheir
cyrusfirheir / branch.js
Created September 2, 2020 12:46
SugarCube 2 - Branch out of the State system to create a snapshot for later use
(function() {
"use strict";
Macro.add("branch", {
handler() {
let id = this.args[0];
let list = this.args.slice(1);
variables()["#macro-branch"] = variables()["#macro-branch"] || {};
variables()["#macro-branch"][id] = variables()["#macro-branch"][id] || {};
@cyrusfirheir
cyrusfirheir / smartquotes.js
Last active August 24, 2021 12:20
Converts dumb quotes (" ') to smart (“ ” ‘ ’) ones.
// Adapted from `smartquotes.js` at https://github.com/kellym/smartquotes.js
// LICENCE: https://github.com/kellym/smartquotes.js/blob/master/LICENSE
if (!String.prototype.smartQuotes) {
Object.defineProperty(String.prototype, 'smartQuotes', {
configurable: true,
writable: true,
value: function smartQuotes() {
return this
.replace(/'''/g, '\u2034')
.replace(/(\W|^)"(\S)/g, '$1\u201c$2')
@cyrusfirheir
cyrusfirheir / dragToScroll.js
Created August 18, 2021 14:40
Drag element to scroll
(function () {
"use strict";
jQuery.fn.extend({
dragToScroll({ horizontal = true, vertical = true } = {}) {
const position = { top: 0, left: 0, x: 0, y: 0 };
const element = this.get(0);
function downHandler({ clientX, clientY }) {
@cyrusfirheir
cyrusfirheir / index.html
Last active September 21, 2022 18:19
Canvas drawing input for img2img and inpainting (Stable Diffusion) generation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>