Skip to content

Commit

Permalink
v1.5.4
Browse files Browse the repository at this point in the history
No longer need to special case $player with $global: true
Stdlib: adds Number#round_to_nearest
^i{} initializer now implemented wrapped as immediate function
Adds RezDie#open_roll
Calling event handlers converts false into RezEvent.noop()
Adds events to RezGame for scene/end, scene/pause, and scene/resume
All Rez CSS classes now have a "rez-" prefix
Adds missing accessors
  • Loading branch information
mmower committed Jan 6, 2025
1 parent b8a6078 commit 848ac9d
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 21 deletions.
5 changes: 0 additions & 5 deletions assets/templates/runtime.js.eex
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,4 @@
evt.returnValue = "";
});
}

const player = $("player", false);
if(player) {
window.$player = player;
}
})();
5 changes: 3 additions & 2 deletions assets/templates/runtime/rez_0_basic_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ class RezBasicObject {
if(value.constructor == RezDie) {
this.setAttribute(attrName, value.roll(), false);
} else {
const initializer = value["initializer"];
this.setAttribute(attrName, eval(initializer), false);
const initializerDef = value["initializer"];
const initializerSrc = `(function() {${initializerDef}}).call(this)`;
this.setAttribute(attrName, eval(initializerSrc), false);
}
}

Expand Down
11 changes: 11 additions & 0 deletions assets/templates/runtime/rez_die.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ class RezDie {
roll() {
return Math.rand_int_between(1, this.sides);
}

open_roll() {
let roll, total = 0;

do {
roll = this.roll();
total += roll;
} while(roll == this.sides);

return total;
}
}

window.Rez.RezDie = RezDie;
Expand Down
4 changes: 2 additions & 2 deletions assets/templates/runtime/rez_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class RezEventProcessor {
}

const card = $(cardId);
return card.runEvent("input", { evt: evt });
return card.runEvent("input", { evt: evt }) || RezEvent.noop();
}

handleBrowserSubmitEvent(evt) {
Expand All @@ -410,7 +410,7 @@ class RezEventProcessor {
const cardId = cardDiv.dataset.card;
const card = $(cardId);

return card.runEvent(formName, { form: evt.target });
return card.runEvent(formName, { form: evt.target }) || RezEvent.noop();
}
}

Expand Down
4 changes: 4 additions & 0 deletions assets/templates/runtime/rez_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class RezGame extends RezBasicObject {
// current_scene is a Rez attribute defined by @scene

if(this.current_scene) {
this.runEvent("scene_end", {});
this.current_scene.finish();
}

Expand All @@ -441,6 +442,7 @@ class RezGame extends RezBasicObject {
interludeSceneWithId(sceneId, params = {}) {
// current_scene is a Rez attribute defined by @scene

this.runEvent("scene_pause", {});
this.pushScene();

const scene = this.getTypedGameObject(sceneId, "scene", true);
Expand All @@ -466,8 +468,10 @@ class RezGame extends RezBasicObject {
throw new Error("Cannot resume without a scene on the stack!");
} else {
// Let the interlude know we're done
this.runEvent("scene_end", {});
this.current_scene.finish();
this.popScene(params);
this.runEvent("scene_resume", {});

const layout = this.current_scene.getViewLayout();
// Merge any new params into the existing params
Expand Down
18 changes: 13 additions & 5 deletions assets/templates/runtime/rez_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class RezBlock {
return this.#flipped;
}

set flipped(is_flipped) {
this.#flipped = is_flipped;
}

get params() {
return this.#params;
}
Expand Down Expand Up @@ -329,6 +333,10 @@ class RezStackLayout extends RezLayout {
this.#contents = [];
}

get contents() {
return this.#contents;
}

// get sourceName() {
// return this.#sourceName;
// }
Expand Down Expand Up @@ -501,7 +509,7 @@ window.Rez.RezBlockTransformer = RezBlockTransformer;

class RezEventLinkTransformer extends RezEventTransformer {
constructor(receiver) {
super("div.front-face a[data-event]", "click", receiver);
super("div.rez-front-face a[data-event]", "click", receiver);
}
}

Expand All @@ -513,7 +521,7 @@ window.Rez.RezEventLinkTransformer = RezEventLinkTransformer;

class RezButtonTransformer extends RezEventTransformer {
constructor(receiver) {
super("div.front-face button[data-event]:not(.inactive)", "click", receiver);
super("div.rez-front-face button[data-event]:not(.inactive)", "click", receiver);
}
}

Expand All @@ -525,7 +533,7 @@ window.Rez.RezButtonTransformer = RezButtonTransformer;

class RezFormTransformer extends RezEventTransformer {
constructor(receiver) {
super("div.front-face form[rez-live]", "submit", receiver);
super("div.rez-front-face form[rez-live]", "submit", receiver);
}
}

Expand All @@ -537,7 +545,7 @@ window.Rez.RezFormTransformer = RezFormTransformer;

class RezInputTransformer extends RezEventTransformer {
constructor(receiver) {
super("div.front-face input[rez-live]", "input", receiver);
super("div.rez-front-face input[rez-live]", "input", receiver);
}
}

Expand All @@ -549,7 +557,7 @@ window.Rez.RezInputTransformer = RezInputTransformer;

class RezBindingTransformer extends RezTransformer {
constructor(receiver) {
super("div.front-face input[rez-bind], select[rez-bind], textarea[rez-bind]");
super("div.rez-front-face input[rez-bind], select[rez-bind], textarea[rez-bind]");
}

decodeBinding(binding_expr) {
Expand Down
13 changes: 13 additions & 0 deletions assets/templates/stdlib.rez.eex
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,19 @@
}
}

@patch PATCH_NUMBER_ROUND_TO_NEAREST {
$built_in: true
patch: "Number"
method: "round_to_nearest"
impl: function(n) {
if(n === 0) {
return this;
} else {
return Math.round(this / n) * n;
}
}
}

@patch PATCH_NUMBER_CHANCE {
$built_in: true
patch: "Number"
Expand Down
4 changes: 2 additions & 2 deletions docs/language_reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ Rez defines many attribute types, some simple and some more complicated. The mor
|`^{Math.rand_int(1,10)}`

|Dynamic Initializer
|A Javascript expression that is evaluated when the game starts
|`^i{Math.rand_int(1,10)}`
|A Javascript expression that is evaluated when the game starts. It converted into an expression `(function() {return <block>}).call(this)`
|`^i{return Math.rand_int(1,10)}`

|Dynamic Property
|A Javascript function expression that is converted into an object property
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Rez.AST.Card do
html
else
custom_css_class = NodeHelper.get_attr_value(card, "css_class", "")
css_classes = Utils.add_css_class("front-face", custom_css_class)
css_classes = Utils.add_css_class("rez-front-face", custom_css_class)

~s|<div id="card_#{card_id}" data-card="#{card_id}" class="#{css_classes}">#{html}</div>|
end
Expand All @@ -50,7 +50,7 @@ defmodule Rez.AST.Card do
html
else
custom_css_class = NodeHelper.get_attr_value(card, "css_class", "")
css_classes = Utils.add_css_class("flipped-face", custom_css_class)
css_classes = Utils.add_css_class("rez-flipped-face", custom_css_class)

~s|<div data-card="#{card_id}" data-card="#{card_id}" data-flipped=true class="#{css_classes}">#{html}</div>|
end
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/game.ex
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ defmodule Rez.AST.Game do
NodeHelper.get_attr_value(game, "layout"),
fn html ->
custom_css_class = NodeHelper.get_attr_value(game, "css_class", "")
css_classes = add_css_class("game", custom_css_class)
css_classes = add_css_class("rez-game", custom_css_class)

~s|<div id="game" data-game=true class="#{css_classes}">#{html}</div>|
end
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/scene.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Rez.AST.Scene do
NodeHelper.get_attr_value(scene, "layout"),
fn content ->
custom_css_class = NodeHelper.get_attr_value(scene, "css_class", "")
css_classes = Utils.add_css_class("scene", custom_css_class)
css_classes = Utils.add_css_class("rez-scene", custom_css_class)

~s|<div id="scene_#{id}" data-scene="#{id}" class="#{css_classes}">#{content}</div>|
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Rez.MixProject do
use Mix.Project

@version "1.5.3"
@version "1.5.4"

def project do
[
Expand Down

0 comments on commit 848ac9d

Please sign in to comment.