Skip to content

Commit

Permalink
Partial code documentation in native language
Browse files Browse the repository at this point in the history
Project pretty functional no critical errors to take care of, just code stuff. Keep in mind this is an international project so most of the code is in english but dev comments are in our native language. (Romanian)
  • Loading branch information
HadockKali committed Mar 4, 2021
1 parent 56aa3ec commit 1510db6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
28 changes: 18 additions & 10 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let $playfield = document.querySelector(".playfield"),
};

let mobile = isMobile().any;
//fuck citar
// main kbd = desktop keyboard lista de posibilitati combinatii
let Password = {
current: [],

Expand All @@ -28,7 +28,7 @@ let Password = {
solved() {
return Password.current.every((cell) => cell.solved);
},

// modul generare combinatii
generate() {
let keys = Password.type
? Array.through(Game.difficulty.length, 1)
Expand All @@ -52,10 +52,10 @@ let Game = {
timer: null,

countup: null,

// de aici se poate ajusta dificultatea in functie de timp si lungime string
difficulty: {
time: 5, //5 def
length: 8, //8 def
time: 5, //5 default
length: 8, //8 default

set: {
time(value) {
Expand Down Expand Up @@ -145,13 +145,16 @@ let Game = {

Game.status = "ongoing";
},
// Triggers pentru eventuri

//fs lose
lose() {
$playfield.classList.add("failed");

Game.status = "lost";
},

//fs succeed
succeed() {
let reward = (Game.difficulty.length / Game.difficulty.time) * 20;

Expand All @@ -160,6 +163,7 @@ let Game = {
Game.resolve();
},

//fs start
start() {
Game.score.reset();

Expand All @@ -170,6 +174,7 @@ let Game = {
$score.classList.add("visible");
},

//fs pause
pause() {
Game.timer.pause();

Expand All @@ -178,14 +183,17 @@ let Game = {
Game.status = "paused";
},

//fs unpause
unpause() {
Game.timer.unpause();

$playfield.classList.remove("paused");

Game.status = "ongoing";
},

/* Formula pentru key-uri gresite:
* penalty == (<time_in_ms> / 10) == (<time_in_s> * 100)
*/
foul() {
let penalty = Game.difficulty.time * 100;

Expand All @@ -202,7 +210,7 @@ let Game = {

save() {},
};

// actiuni/event-uri
let ActionHandler = {
_pressed: [],

Expand All @@ -217,7 +225,7 @@ let ActionHandler = {

action[Game.status]();
},

// mobile things TODO: de schimbat swipe down in instantele chrome mobile forteaza 2 actiuni, una dintre acestea este refresh.
swipeup() {
let action = {
initial: Game.start,
Expand All @@ -229,7 +237,7 @@ let ActionHandler = {

action[Game.status]();
},

// FIXME: de rectificat (vezi TODO de mai sus)
swipedown() {
if (Game.status == "ongoing") Game.pause();
},
Expand Down Expand Up @@ -375,7 +383,7 @@ let handler = new InteractionHandler();

handler.register("keydown", { key: "space" }, ActionHandler.contextual);
handler.register("keydown", { key: "mod" }, Game.settings);

// in caz de apasari accidentale anti-foul module
handler.register("keydown", { key: "shift" }, function () {
/* noop */
});
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<main>

<div class="title">passwd</div>
<!--<div class="tagline">a game about <div class="break small"></div>key presses and reaction time</div> ///FIXME fix fitting problem using custom fitter in css (new one old one is deprecated)-->
<!--<div class="tagline">a game about <div class="break small"></div>key presses and reaction time</div> ///FIXME fix fitting problem using custom fitter in css (new one, old one is deprecated,P.S. nu am gasit altul in afara de fitty)-->

</main>

Expand Down
1 change: 1 addition & 0 deletions libs/InteractionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ class InteractionHandler {
return response;
}
}
//responsabil pentru transmutarea actiunilor desktop->mobile
23 changes: 15 additions & 8 deletions libs/countup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CountUp {
suffix: "",
};

instance.finalEndVal = null;
instance.finalEndVal = null; //easing
instance.easing = true;
instance.countDown = false;
instance.error = "";
Expand All @@ -40,7 +40,7 @@ class CountUp {
var progress = timestamp - instance.startTime;

instance.remaining = instance.duration - progress;

//if easing vezi #30
if (instance.easing) {
if (instance.countDown) {
instance.frameVal =
Expand All @@ -60,6 +60,7 @@ class CountUp {
);
}
} else {
//ATENTIE! nu merge mai mult decat endVal pt ca progresu' poate depasii timer in ultimu' frame
if (instance.countDown) {
instance.frameVal =
instance.startVal -
Expand All @@ -84,22 +85,24 @@ class CountUp {
? instance.endVal
: instance.frameVal;
}

//punct decimal
instance.frameVal =
Math.round(instance.frameVal * instance.decimalMult) /
instance.decimalMult;

//formatare si afisare valoare
instance.printValue(instance.frameVal);

//continua?
if (progress < instance.duration) {
instance.rAF = requestAnimationFrame(instance.count);
} else if (instance.finalEndVal !== null) {
//easing #30
instance.update(instance.finalEndVal);
} else if (instance.callback) {
instance.callback();
}
};

//format simplu si functii easing
instance.formatNumber = function (num) {
var neg = num < 0 ? "-" : "";

Expand All @@ -108,7 +111,7 @@ class CountUp {
let result = Math.abs(num)
.toFixed(instance.options.decimalPlaces)
.toString();

//result += '';
let x = result.split(".");

let x1 = x[0];
Expand All @@ -126,7 +129,7 @@ class CountUp {

x1 = x3;
}

//instanta opt. de substitutie 'numerals'
if (instance.options.numerals && instance.options.numerals.length) {
x1 = x1.replace(/[0-9]/g, function (w) {
return instance.options.numerals[+w];
Expand Down Expand Up @@ -182,6 +185,7 @@ class CountUp {
}
}

//determina unde incepe smart easing si daca numara crescator sau descrescator
determineDirectionAndSmartEasing() {
var end = this.finalEndVal ? this.finalEndVal : this.endVal;

Expand Down Expand Up @@ -209,6 +213,7 @@ class CountUp {
}
}

//incepe animatia
start(callback) {
if (this.error) return;

Expand All @@ -223,6 +228,7 @@ class CountUp {
}
}

//mai multa animatie :P (self explanatory)
pauseResume() {
if (!this.paused) {
cancelAnimationFrame(this.rAF);
Expand All @@ -238,7 +244,7 @@ class CountUp {

this.paused = !this.paused;
}

//se resetaza catre startVal ca animatia sa poata fi reluata
reset() {
cancelAnimationFrame(this.rAF);

Expand All @@ -249,6 +255,7 @@ class CountUp {
this.printValue(this.startVal);
}

//updateaza endVal si incepe animatia
update(newEndVal) {
cancelAnimationFrame(this.rAF);

Expand Down
2 changes: 1 addition & 1 deletion libs/isMobile.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ function isMobile(a) {
f
);
}
//TODO: Ineficient, check browser modifiers OS code similar to AdGuard browser obfuscator
// Fitty detection, putin modificat, acest modul regleaza modul de joc in functie de device-ul de pe care este accesat site-ul
1 change: 1 addition & 0 deletions libs/tinygesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,4 @@ try {
})
);
} catch (err) {}
//TODO: def actiuni tap,longpress etc...
1 change: 1 addition & 0 deletions libs/tock.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//Tock este implementat din libraria publica accesibila aici: https://github.com/mrchimp/tock [Tock este un "ceas" cu functie de tip countdown/timer]
let delta = function (source = 0) {
return Date.now() - source;
};
Expand Down
2 changes: 1 addition & 1 deletion supplementary.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Array.through = function (length = 0, from = 0, step = 1) {
(item, index) => from + index * step
);
};

// String.prototype.belongsTo = function (array) { return array.includes(this.valueOf()) };
Object.prototype.belongsTo = function (array) {
return array.includes(this.valueOf());
};
Expand Down

0 comments on commit 1510db6

Please sign in to comment.