Skip to content

Instantly share code, notes, and snippets.

@f-space
f-space / ImproveJsonSerialization.js
Created Jul 3, 2020
JSON serializer/deserializer for RPG Maker MV, which have data compatibility with those in the core script.
View ImproveJsonSerialization.js
/*:ja
* @plugindesc JSONシリアライズの挙動を改善します。
* @author F_
*
* @help
* ツクールのセーブ/ロード時などに使用されるJSONシリアライザ/デシリアライザの挙動を改善します。
*
* ツクール標準のシリアライザは実行中に対象のオブジェクトを書き換え、
* 終了時にいくつかの操作によって元に近い状態へと戻します。
* この挙動は多くの場合に問題なく動作しますが、
@f-space
f-space / parser.js
Created Jul 3, 2020
Parser combinators for plugin commands of RPG Maker MV.
View parser.js
const Parser = (() => {
const isOk = result => result.error === undefined;
const succeed = value => (_, i) => ({ value, position: i });
const fail = error => () => ({ error });
const value = (context, parse) => (args, i) => {
if (i < args.length) {
const result = parse(args[i]);
@f-space
f-space / ECS.cs
Last active May 31, 2020
A minimal ECS implementation with Unity-like API for a blog entry.
View ECS.cs
using System;
using System.Collections.Generic;
public readonly struct Entity
{
public readonly int ID;
public Entity(int id) => this.ID = id;
}
@f-space
f-space / IntersectionObserver.js
Last active Jul 18, 2019
IntersectionObserver FFIs for PureScript.
View IntersectionObserver.js
// @ts-check
"use strict";
/** @typedef {(entries: IntersectionObserverEntry[]) => (observer: IntersectionObserver) => () => void} CurriedIntersectionObserverCallback */
/** @type {(callback: CurriedIntersectionObserverCallback) => (options: IntersectionObserverInit) => () => IntersectionObserver} */
exports.intersectionObserver_ = function (callback) {
return function (options) {
return function () {
@f-space
f-space / RoguelikeUI.js
Last active Mar 19, 2019
不思議のダンジョン風のUIをマップ画面に表示するRPGツクールMVプラグイン
View RoguelikeUI.js
/*:
* @plugindesc マップ画面上にステータスを表示する
* @author F_
*
* @param horizontal_margin
* @desc 横方向の余白(px)
* @default 50
*
* @param vertical_margin
* @desc 縦方向の余白(px)
@f-space
f-space / vuex-class-module.ts
Last active Mar 18, 2019
Decorators for class-style vuex modules.
View vuex-class-module.ts
import * as Vuex from 'vuex';
import 'reflect-metadata';
export const TypeSymbol = Symbol('type');
export interface IModule<R = any> {
readonly $state: any;
readonly $getters: any;
readonly $commit: Vuex.Commit;
readonly $dispatch: Vuex.Dispatch;
@f-space
f-space / tsconfig-webpack-plugin.js
Last active Jun 14, 2018
Webpack resolver plugin for tsconfig.json (baseUrl, paths, rootDirs).
View tsconfig-webpack-plugin.js
const fs = require('fs');
const { posix, win32 } = require('path');
const path = (process.platform !== 'win32') ? posix : {
resolve() { return replaceSep(win32.resolve.apply(this, arguments)); },
relative() { return replaceSep(win32.relative.apply(this, arguments)); },
normalize() { return replaceSep(win32.normalize.apply(this, arguments)); },
join() { return replaceSep(win32.join.apply(this, arguments)); },
dirname() { return replaceSep(win32.dirname.apply(this, arguments)); },
};
@f-space
f-space / mixin.ts
Created Dec 18, 2017
TypeScript 'mixin' function for vue-class-component.
View mixin.ts
import { Vue } from 'vue/types/vue';
import { ComponentOptions } from 'vue/types/options';
type VueCtor<V extends Vue> = { new(...args: any[]): V };
type VueClass<V extends Vue> = VueCtor<V> & typeof Vue;
type MixinType<V extends Vue> = ComponentOptions<V> | VueClass<V>;
function mixin<
T extends VueClass<Vue>,
M1 extends Vue>(
@f-space
f-space / blit.js
Created Oct 23, 2017
WebGLによるImageのコピー
View blit.js
const VS_SRC = `
attribute vec4 position;
attribute vec2 texcoord;
varying vec2 vTexcoord;
void main(void){
gl_Position = position;
vTexcoord = texcoord;
}
`;
View Actor.cs
using UnityEngine;
public class Actor : MonoBehaviour
{
// Rigidbodyと大きさを受け取り、画面内に収まるように位置と速度を調節する
protected void EnsureInScreen(Rigidbody2D rigidbody, Vector2 size)
{
// いくつもの前提の下に動作することに注意
// 前提1:メインカメラはZ軸正方向を向いている
// 前提2:画像の中心位置とオブジェクトの位置が一致している