Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved example. Fixed invalid callback error.
- Loading branch information
Showing
5 changed files
with
166 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
function init(self) | ||
local monetized = webmonetization.is_monetized() | ||
if monetized then | ||
print("The user has an active payment stream") | ||
end | ||
|
||
webmonetization.set_listener(function(self, event, details) | ||
if event == webmonetization.EVENT_PENDING then | ||
print("The user is trying to make a first payment") | ||
elseif event == webmonetization.EVENT_START then | ||
print("The user has started paying") | ||
elseif event == webmonetization.EVENT_PROGRESS then | ||
print("The user is still paying") | ||
elseif event == webmonetization.EVENT_STOP then | ||
print("The user has stopped paying") | ||
else | ||
print("Unknown event", event) | ||
end | ||
pprint(details) | ||
end) | ||
msg.post(".", "acquire_input_focus") | ||
msg.post("#", "load_example") | ||
end | ||
|
||
|
||
function on_message(self, message_id, message, sender) | ||
print(message_id) | ||
if message_id == hash("load_example") then | ||
msg.post("#collectionproxy", "async_load") | ||
elseif message_id == hash("unload_example") then | ||
msg.post("#collectionproxy", "unload") | ||
elseif message_id == hash("proxy_loaded") then | ||
msg.post(sender, "enable") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: "webmonetization" | ||
scale_along_z: 0 | ||
embedded_instances { | ||
id: "go" | ||
data: "components {\n" | ||
" id: \"webmonetization\"\n" | ||
" component: \"/example/webmonetization.script\"\n" | ||
" position {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" }\n" | ||
" rotation {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" w: 1.0\n" | ||
" }\n" | ||
"}\n" | ||
"embedded_components {\n" | ||
" id: \"label\"\n" | ||
" type: \"label\"\n" | ||
" data: \"size {\\n" | ||
" x: 128.0\\n" | ||
" y: 32.0\\n" | ||
" z: 0.0\\n" | ||
" w: 0.0\\n" | ||
"}\\n" | ||
"scale {\\n" | ||
" x: 1.0\\n" | ||
" y: 1.0\\n" | ||
" z: 1.0\\n" | ||
" w: 0.0\\n" | ||
"}\\n" | ||
"color {\\n" | ||
" x: 1.0\\n" | ||
" y: 1.0\\n" | ||
" z: 1.0\\n" | ||
" w: 1.0\\n" | ||
"}\\n" | ||
"outline {\\n" | ||
" x: 0.0\\n" | ||
" y: 0.0\\n" | ||
" z: 0.0\\n" | ||
" w: 1.0\\n" | ||
"}\\n" | ||
"shadow {\\n" | ||
" x: 0.0\\n" | ||
" y: 0.0\\n" | ||
" z: 0.0\\n" | ||
" w: 1.0\\n" | ||
"}\\n" | ||
"leading: 1.0\\n" | ||
"tracking: 0.0\\n" | ||
"pivot: PIVOT_CENTER\\n" | ||
"blend_mode: BLEND_MODE_ALPHA\\n" | ||
"line_break: false\\n" | ||
"text: \\\"WEB MONETIZATION\\\"\\n" | ||
"font: \\\"/builtins/fonts/system_font.font\\\"\\n" | ||
"material: \\\"/builtins/fonts/label.material\\\"\\n" | ||
"\"\n" | ||
" position {\n" | ||
" x: 320.0\n" | ||
" y: 568.0\n" | ||
" z: 0.0\n" | ||
" }\n" | ||
" rotation {\n" | ||
" x: 0.0\n" | ||
" y: 0.0\n" | ||
" z: 0.0\n" | ||
" w: 1.0\n" | ||
" }\n" | ||
"}\n" | ||
"" | ||
position { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
} | ||
rotation { | ||
x: 0.0 | ||
y: 0.0 | ||
z: 0.0 | ||
w: 1.0 | ||
} | ||
scale3 { | ||
x: 1.0 | ||
y: 1.0 | ||
z: 1.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local function log(message) | ||
print(message) | ||
label.set_text("#label", message) | ||
end | ||
|
||
function init(self) | ||
msg.post(".", "acquire_input_focus") | ||
|
||
if webmonetization then | ||
local monetized = webmonetization.is_monetized() | ||
if monetized then | ||
log("The user has an active payment stream") | ||
end | ||
|
||
webmonetization.set_listener(function(self, event, details) | ||
if event == webmonetization.EVENT_PENDING then | ||
log("The user is trying to make a first payment") | ||
elseif event == webmonetization.EVENT_START then | ||
log("The user has started paying") | ||
elseif event == webmonetization.EVENT_PROGRESS then | ||
log("The user is still paying") | ||
elseif event == webmonetization.EVENT_STOP then | ||
log("The user has stopped paying") | ||
else | ||
log("Unknown event", event) | ||
end | ||
pprint(details) | ||
end) | ||
else | ||
log("Not supported") | ||
end | ||
end | ||
|
||
function on_input(self, action_id, action) | ||
if action_id == hash("touch") and action.pressed then | ||
msg.post("example:/loader", "unload_example") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters