Skip to content

Commit d204b76

Browse files
committed
Merge branch 'master' of github.com:siggame/Viseur
2 parents e100561 + 7ecc219 commit d204b76

53 files changed

Lines changed: 4233 additions & 7 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
// Utils - utility functions used across classes
22
var eases = require("eases");
33

4+
var entityMap = {
5+
"&": "&",
6+
"<": "&lt;",
7+
">": "&gt;",
8+
"\"": "&quot;",
9+
"'": "&#39;",
10+
"/": "&#x2F;",
11+
};
12+
413
module.exports = {
514
capitalizeFirstLetter: function(string) {
615
return string.charAt(0).toUpperCase() + string.slice(1);
@@ -83,4 +92,15 @@ module.exports = {
8392

8493
return regexp.test(str);
8594
},
95+
96+
/**
97+
* Escapes a string to be displayed in HTML, but not AS HTML.
98+
* @param {String} str - the string to escape
99+
* @returns {String} str now escaped
100+
*/
101+
escapeHTML: function(str) {
102+
return String(str).replace(/[&<>"'\/]/g, function(s) {
103+
return entityMap[s];
104+
});
105+
},
86106
};

games/anarchy/building.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// This is a "class" to represent the Building object in the game. If you want to render it in the game do so here.
2+
var Classe = require("classe");
3+
var PIXI = require("pixi.js");
4+
var Color = require("color");
5+
var ease = require("core/utils").ease;
6+
7+
var GameObject = require("./gameObject");
8+
9+
//<<-- Creer-Merge: requires -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
10+
// any additional requires you want can be required here safely between Creer runs
11+
//<<-- /Creer-Merge: requires -->>
12+
13+
/**
14+
* @typedef {Object} BuildingState - A state representing a Building
15+
* @property {boolean} bribed - When true this building has already been bribed this turn and cannot be bribed again this turn.
16+
* @property {BuildingState} buildingEast - The Building directly to the east of this building, or null if not present.
17+
* @property {BuildingState} buildingNorth - The Building directly to the north of this building, or null if not present.
18+
* @property {BuildingState} buildingSouth - The Building directly to the south of this building, or null if not present.
19+
* @property {BuildingState} buildingWest - The Building directly to the west of this building, or null if not present.
20+
* @property {number} fire - How much fire is currently burning the building, and thus how much damage it will take at the end of its owner's turn. 0 means no fire.
21+
* @property {string} gameObjectName - String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.
22+
* @property {number} health - How much health this building currently has. When this reaches 0 the Building has been burned down.
23+
* @property {string} id - A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.
24+
* @property {boolean} isHeadquarters - True if this is the Headquarters of the owning player, false otherwise. Burning this down wins the game for the other Player.
25+
* @property {Array.<string>} logs - Any strings logged will be stored here. Intended for debugging.
26+
* @property {PlayerState} owner - The player that owns this building. If it burns down (health reaches 0) that player gets an additional bribe(s).
27+
* @property {number} x - The location of the Building along the x-axis.
28+
* @property {number} y - The location of the Building along the y-axis.
29+
*/
30+
31+
/**
32+
* @class
33+
* @classdesc A basic building. It does nothing besides burn down. Other Buildings inherit from this class.
34+
* @extends GameObject
35+
*/
36+
var Building = Classe(GameObject, {
37+
/**
38+
* Initializes a Building with basic logic as provided by the Creer code generator. This is a good place to initialize sprites
39+
*
40+
* @memberof Building
41+
* @param {BuildingState} initialState - the initial state of this game object
42+
* @param {Game} game - the game this Building is in
43+
*/
44+
init: function(initialState, game) {
45+
GameObject.init.apply(this, arguments);
46+
47+
//<<-- Creer-Merge: init -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
48+
// initialization logic goes here
49+
//<<-- /Creer-Merge: init -->>
50+
},
51+
52+
/**
53+
* Static name of the classe.
54+
*
55+
* @static
56+
*/
57+
name: "Building",
58+
59+
/**
60+
* The current state of this Building. Undefined when there is no current state.
61+
*
62+
* @type {BuildingState|null})}
63+
*/
64+
current: null,
65+
66+
/**
67+
* The next state of this Building. Undefined when there is no next state.
68+
*
69+
* @type {BuildingState|null})}
70+
*/
71+
next: null,
72+
73+
// The following values should get overridden when delta states are merged, but we set them here as a reference for you to see what variables this class has.
74+
75+
/**
76+
* Set this to `true` if this GameObject should be rendered.
77+
*
78+
* @static
79+
*/
80+
//<<-- Creer-Merge: shouldRender -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
81+
shouldRender: false,
82+
//<<-- /Creer-Merge: shouldRender -->>
83+
84+
/**
85+
* Called approx 60 times a second to update and render the Building. Leave empty if it should not be rendered
86+
*
87+
* @param {Number} dt - a floating point number [0, 1) which represents how far into the next turn that current turn we are rendering is at
88+
* @param {BuildingState} current - the current (most) game state, will be this.next if this.current is null
89+
* @param {BuildingState} next - the next (most) game state, will be this.current if this.next is null
90+
* @param {DeltaReason} reason - the reason for the current delta
91+
* @param {DeltaReason} nextReason - the reason for the next delta
92+
*/
93+
render: function(dt, current, next, reason, nextReason) {
94+
GameObject.render.apply(this, arguments);
95+
96+
//<<-- Creer-Merge: render -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
97+
// render where the Building is
98+
//<<-- /Creer-Merge: render -->>
99+
},
100+
101+
/**
102+
* Invoked when the right click menu needs to be shown.
103+
*
104+
* @private
105+
* @returns {Array} array of context menu items, which can be {text, icon, callback} for items, or "---" for a seperator
106+
*/
107+
_getContextMenu: function() {
108+
var self = this;
109+
var menu = [];
110+
111+
//<<-- Creer-Merge: _getContextMenu -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
112+
// add context items to the menu here
113+
//<<-- /Creer-Merge: _getContextMenu -->>
114+
115+
return menu;
116+
},
117+
118+
119+
// Joueur functions - functions invoked for human playable client
120+
121+
// /Joueur functions
122+
123+
/**
124+
* Invoked when the state updates.
125+
*
126+
* @private
127+
* @param {BuildingState} current - the current (most) game state, will be this.next if this.current is null
128+
* @param {BuildingState} next - the next (most) game state, will be this.current if this.next is null
129+
* @param {DeltaReason} reason - the reason for the current delta
130+
* @param {DeltaReason} nextReason - the reason for the next delta
131+
*/
132+
_stateUpdated: function(current, next, reason, nextReason) {
133+
GameObject._stateUpdated.apply(this, arguments);
134+
135+
//<<-- Creer-Merge: _stateUpdated -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
136+
// update the Building based on its current and next states
137+
//<<-- /Creer-Merge: _stateUpdated -->>
138+
},
139+
140+
//<<-- Creer-Merge: functions -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
141+
// any additional functions you want to add to this class can be perserved here
142+
//<<-- /Creer-Merge: functions -->>
143+
144+
});
145+
146+
module.exports = Building;

games/anarchy/fireDepartment.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// This is a "class" to represent the FireDepartment object in the game. If you want to render it in the game do so here.
2+
var Classe = require("classe");
3+
var PIXI = require("pixi.js");
4+
var Color = require("color");
5+
var ease = require("core/utils").ease;
6+
7+
var Building = require("./building");
8+
9+
//<<-- Creer-Merge: requires -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
10+
// any additional requires you want can be required here safely between Creer runs
11+
//<<-- /Creer-Merge: requires -->>
12+
13+
/**
14+
* @typedef {Object} FireDepartmentState - A state representing a FireDepartment
15+
* @property {boolean} bribed - When true this building has already been bribed this turn and cannot be bribed again this turn.
16+
* @property {BuildingState} buildingEast - The Building directly to the east of this building, or null if not present.
17+
* @property {BuildingState} buildingNorth - The Building directly to the north of this building, or null if not present.
18+
* @property {BuildingState} buildingSouth - The Building directly to the south of this building, or null if not present.
19+
* @property {BuildingState} buildingWest - The Building directly to the west of this building, or null if not present.
20+
* @property {number} fire - How much fire is currently burning the building, and thus how much damage it will take at the end of its owner's turn. 0 means no fire.
21+
* @property {number} fireExtinguished - The amount of fire removed from a building when bribed to extinguish a building.
22+
* @property {string} gameObjectName - String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.
23+
* @property {number} health - How much health this building currently has. When this reaches 0 the Building has been burned down.
24+
* @property {string} id - A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.
25+
* @property {boolean} isHeadquarters - True if this is the Headquarters of the owning player, false otherwise. Burning this down wins the game for the other Player.
26+
* @property {Array.<string>} logs - Any strings logged will be stored here. Intended for debugging.
27+
* @property {PlayerState} owner - The player that owns this building. If it burns down (health reaches 0) that player gets an additional bribe(s).
28+
* @property {number} x - The location of the Building along the x-axis.
29+
* @property {number} y - The location of the Building along the y-axis.
30+
*/
31+
32+
/**
33+
* @class
34+
* @classdesc Can put out fires completely.
35+
* @extends Building
36+
*/
37+
var FireDepartment = Classe(Building, {
38+
/**
39+
* Initializes a FireDepartment with basic logic as provided by the Creer code generator. This is a good place to initialize sprites
40+
*
41+
* @memberof FireDepartment
42+
* @param {FireDepartmentState} initialState - the initial state of this game object
43+
* @param {Game} game - the game this FireDepartment is in
44+
*/
45+
init: function(initialState, game) {
46+
Building.init.apply(this, arguments);
47+
48+
//<<-- Creer-Merge: init -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
49+
// initialization logic goes here
50+
//<<-- /Creer-Merge: init -->>
51+
},
52+
53+
/**
54+
* Static name of the classe.
55+
*
56+
* @static
57+
*/
58+
name: "FireDepartment",
59+
60+
/**
61+
* The current state of this FireDepartment. Undefined when there is no current state.
62+
*
63+
* @type {FireDepartmentState|null})}
64+
*/
65+
current: null,
66+
67+
/**
68+
* The next state of this FireDepartment. Undefined when there is no next state.
69+
*
70+
* @type {FireDepartmentState|null})}
71+
*/
72+
next: null,
73+
74+
// The following values should get overridden when delta states are merged, but we set them here as a reference for you to see what variables this class has.
75+
76+
/**
77+
* Set this to `true` if this GameObject should be rendered.
78+
*
79+
* @static
80+
*/
81+
//<<-- Creer-Merge: shouldRender -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
82+
shouldRender: false,
83+
//<<-- /Creer-Merge: shouldRender -->>
84+
85+
/**
86+
* Called approx 60 times a second to update and render the FireDepartment. Leave empty if it should not be rendered
87+
*
88+
* @param {Number} dt - a floating point number [0, 1) which represents how far into the next turn that current turn we are rendering is at
89+
* @param {FireDepartmentState} current - the current (most) game state, will be this.next if this.current is null
90+
* @param {FireDepartmentState} next - the next (most) game state, will be this.current if this.next is null
91+
* @param {DeltaReason} reason - the reason for the current delta
92+
* @param {DeltaReason} nextReason - the reason for the next delta
93+
*/
94+
render: function(dt, current, next, reason, nextReason) {
95+
Building.render.apply(this, arguments);
96+
97+
//<<-- Creer-Merge: render -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
98+
// render where the FireDepartment is
99+
//<<-- /Creer-Merge: render -->>
100+
},
101+
102+
/**
103+
* Invoked when the right click menu needs to be shown.
104+
*
105+
* @private
106+
* @returns {Array} array of context menu items, which can be {text, icon, callback} for items, or "---" for a seperator
107+
*/
108+
_getContextMenu: function() {
109+
var self = this;
110+
var menu = [];
111+
112+
//<<-- Creer-Merge: _getContextMenu -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
113+
// add context items to the menu here
114+
//<<-- /Creer-Merge: _getContextMenu -->>
115+
116+
return menu;
117+
},
118+
119+
120+
// Joueur functions - functions invoked for human playable client
121+
122+
/**
123+
* Bribes this FireDepartment to extinguish the some of the fire in a building.
124+
*
125+
* @param {BuildingState} building - The Building you want to extinguish.
126+
* @param {Function} [callback] - callback that is passed back the return value of boolean once ran on the server
127+
*/
128+
extinguish: function(building, callback) {
129+
this._runOnServer("extinguish", {
130+
building: building,
131+
}, callback);
132+
},
133+
134+
// /Joueur functions
135+
136+
/**
137+
* Invoked when the state updates.
138+
*
139+
* @private
140+
* @param {FireDepartmentState} current - the current (most) game state, will be this.next if this.current is null
141+
* @param {FireDepartmentState} next - the next (most) game state, will be this.current if this.next is null
142+
* @param {DeltaReason} reason - the reason for the current delta
143+
* @param {DeltaReason} nextReason - the reason for the next delta
144+
*/
145+
_stateUpdated: function(current, next, reason, nextReason) {
146+
Building._stateUpdated.apply(this, arguments);
147+
148+
//<<-- Creer-Merge: _stateUpdated -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
149+
// update the FireDepartment based on its current and next states
150+
//<<-- /Creer-Merge: _stateUpdated -->>
151+
},
152+
153+
//<<-- Creer-Merge: functions -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
154+
// any additional functions you want to add to this class can be perserved here
155+
//<<-- /Creer-Merge: functions -->>
156+
157+
});
158+
159+
module.exports = FireDepartment;

0 commit comments

Comments
 (0)