Skip to content

Commit 5e16591

Browse files
[IMP] awesome_clicker: Web Framework Master Chapter 1 Finish Part 1-10
1 parent 0e4179c commit 5e16591

File tree

11 files changed

+183
-2
lines changed

11 files changed

+183
-2
lines changed

awesome_clicker/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
# -*- coding: utf-8 -*-
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { humanNumber } from "@web/core/utils/numbers";
2+
import { Component} from "@odoo/owl";
3+
import { useClicker } from "../clicker_hook/clicker_hook";
4+
5+
export class ClickValue extends Component {
6+
static template = "awesome_clicker.click_value";
7+
static components = { };
8+
9+
setup()
10+
{
11+
this.clicker = useClicker();
12+
console.log(this.clicker.clicks);
13+
}
14+
get humanClicks(){
15+
return humanNumber(this.clicker.clicks, {decimals: 1,})
16+
}
17+
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_clicker.click_value">
4+
<span t-esc="humanClicks" t-att-data-tooltip="clicker.clicks"/>
5+
</t>
6+
</templates>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useService } from "@web/core/utils/hooks";
2+
import { useState } from "@odoo/owl";
3+
4+
export function useClicker() {
5+
return useState(useService("awesome_clicker.clicker_service"));
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Reactive } from "@web/core/utils/reactive";
2+
import {EventBus} from "@odoo/owl";
3+
4+
5+
export class ClickerModel extends Reactive{
6+
constructor()
7+
{
8+
super();
9+
this.clicks = 0;
10+
this.level = 0;
11+
this.clickBots = 0;
12+
this.levelupEvent = new EventBus();
13+
}
14+
15+
tick(){
16+
this.addClicks(this.clickBots * 10);
17+
}
18+
19+
addClicks(val)
20+
{
21+
if(this.clicks >= 100 && this.level == 0)
22+
{
23+
this.level = 1;
24+
this.levelupEvent.trigger("MILESTONE1K");
25+
}
26+
this.clicks+= val;
27+
}
28+
29+
buyClickerBot()
30+
{
31+
const botPrice = 100;
32+
if (this.clicks < botPrice)
33+
{
34+
return false;
35+
}
36+
this.clicks -= botPrice;
37+
this.clickBots ++;
38+
39+
}
40+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { registry } from "@web/core/registry";
2+
import { useService } from "@web/core/utils/hooks";
3+
import { reactive } from "@odoo/owl";
4+
import { ClickerModel } from "../clicker_model/clicker_model";
5+
6+
const clicker_service = {
7+
dependencies: ["effect"],
8+
start(env, services)
9+
{
10+
const model = new ClickerModel();
11+
12+
setInterval(() =>
13+
{
14+
model.tick();
15+
},
16+
10000);
17+
18+
document.addEventListener("click",() => model.addClicks(1),true);
19+
model.levelupEvent.addEventListener("MILESTONE1K",()=>{
20+
services.effect.add({type: "rainbow_man",message:"You just leveled up your clicker level"});
21+
})
22+
23+
return model;
24+
25+
},
26+
27+
};
28+
29+
registry.category("services").add("awesome_clicker.clicker_service",clicker_service)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Component, onWillStart, useState, useExternalListener} from "@odoo/owl";
2+
import { registry } from "@web/core/registry";
3+
import { useService } from "@web/core/utils/hooks";
4+
import { useClicker } from "../clicker_hook/clicker_hook";
5+
import { ClickValue } from "../click_value/click_value";
6+
7+
class ClickerSystrayItem extends Component {
8+
static template = "awesome_clicker.clicker_systray_item";
9+
static components = {ClickValue };
10+
11+
setup()
12+
{
13+
this.action = useService("action");
14+
}
15+
onOpen()
16+
{
17+
this.action.doAction({
18+
type: "ir.actions.client",
19+
tag: "awesome_clicker.client_action",
20+
target: "new",
21+
name: "Clicker"
22+
})
23+
}
24+
25+
26+
}
27+
export const sysItem = {
28+
Component: ClickerSystrayItem
29+
}
30+
registry.category("systray").add("awesome_clicker.clickerSystrayItem",sysItem, {sequence:10000})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_clicker.clicker_systray_item">
4+
<div>
5+
<span>Clicks: <ClickValue/></span>
6+
<button class="btn btn-secondary" t-on-click="onOpen">
7+
Open
8+
</button>
9+
</div>
10+
</t>
11+
</templates>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { registry } from "@web/core/registry";
3+
import { useService } from "@web/core/utils/hooks";
4+
import { ClickValue } from "../click_value/click_value";
5+
6+
class ClientAction extends Component {
7+
static template = "awesome_clicker.client_action";
8+
static components = { ClickValue};
9+
10+
setup()
11+
{
12+
this.clicker = useService("awesome_clicker.clicker_service");
13+
}
14+
15+
onClick()
16+
{
17+
this.clicker.addClicks(9);
18+
}
19+
20+
buyBot()
21+
{
22+
this.clicker.buyClickerBot();
23+
}
24+
}
25+
registry.category("actions").add("awesome_clicker.client_action",ClientAction)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_clicker.client_action">
4+
<div>
5+
Clicks : <ClickValue/>
6+
<button class="btn btn-secondary" t-on-click="onClick">
7+
<i class="fa fa-plus fa-lg"/>
8+
</button>
9+
</div>
10+
11+
<div t-if="clicker.level >= 1">
12+
<h2>BOTS : </h2>
13+
<div><t t-esc="clicker.clickBots"/>x ClickBots (10clicks/10 second)</div>
14+
<button class="btn btn-primary" t-att-disabled="clicker.clicks lt 100" t-on-click="buyBot"> Buy ClickBot (100 clicks)</button>
15+
</div>
16+
</t>
17+
</templates>

0 commit comments

Comments
 (0)