* Update (12.09.2017): I have improved the trait so that it can be used with objects other than Eloquent Models.
Some days ago I came across a task where I needed to implement managable state for an Eloquent model. This is a common task, actually there is a mathematical model called "Finite-state Machine". The concept is that the state machine (SM) "can be in exactly one of the finite number of states at any given time". Also changing from one state to another (called transition) depends on fulfilling the conditions defined by its configuration.
Practically this means you define each state that the SM can be in and the possible transitions. To define a transition you set the states on which the transition can be applied (initial conditions) and the only state in which the SM should be after the transition.
That's the theory, let's get to the work.
-- "fa" is a number ranging from 0 to 1 | |
-- 1 = 100% faded out | |
-- 0 = 0% faded out | |
-- 0.5 = 50% faded out, etc. | |
function fade_scr(fa) | |
fa=max(min(1,fa),0) | |
local fn=8 | |
local pn=15 | |
local fc=1/fn |
To use first you need to create two branches, master
and sim
using the in-game editor. Then just run node sync.js
from your local machine. When you're on your local master
branch it will push to master
in game, any other branch (including detached states) will push to sim
. Note that it will push unstaged changes, so be careful when switching to branches with modified code.
There is support included for compressing your JS files on the server side via UglifyJS. Some users reported some speedups by compressing their code, however I did not notice any significant gains. Furthermore, UglifyJS does not yet support ES6 features, so it's disabled by default.
var global = self; | |
var Reflect = { | |
global: global | |
}; | |
!function a(b, c, d) { | |
function e(g, h) { | |
if (!c[g]) { | |
if (!b[g]) { |
I prefer this
var distance = metersToNauticalMiles(
utils.getDistance(
utils.toPoint(coordinates.get(0)),
utils.toPoint(coordinates.get(1))
)
);
Spurred by recent events (https://news.ycombinator.com/item?id=8244700), this is a quick set of jotted-down thoughts about the state of "Semantic" Versioning, and why we should be fighting the good fight against it.
For a long time in the history of software, version numbers indicated the relative progress and change in a given piece of software. A major release (1.x.x) was major, a minor release (x.1.x) was minor, and a patch release was just a small patch. You could evaluate a given piece of software by name + version, and get a feeling for how far away version 2.0.1 was from version 2.8.0.
But Semantic Versioning (henceforth, SemVer), as specified at http://semver.org/, changes this to prioritize a mechanistic understanding of a codebase over a human one. Any "breaking" change to the software must be accompanied with a new major version number. It's alright for robots, but bad for us.
SemVer tries to compress a huge amount of information — the nature of the change, the percentage of users that wil
/** | |
* A TextureAtlasFont extends Impact's Font class to allow looking up a font's bitmap from the TexturePacker JSON array | |
* | |
* Author: @jessefreeman | |
* | |
* Version 0.1 - 2013/02/19 | |
* | |
* Usage: | |
* DemoTextureAtlasFont = ig.Game.extend({ | |
* textureImage: new ig.Image('media/font.png'), |
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" /> | |
<meta charset="utf-8" /> | |
<script src="perlin.js"></script> | |
<script>//<!-- | |
window.addEventListener("load", function (ev) { | |
var canvas = document.getElementById("canvas"); | |
var c2d = canvas.getContext("2d"); |
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561 | |
/* | |
* How to delete items from an Array in JavaScript, an exhaustive guide | |
*/ | |
// DON'T use the delete operator, it leaves a hole in the array: | |
var arr = [4, 5, 6]; | |
delete arr[1]; // arr now: [4, undefined, 6] |