forked from profectus/Profectus
Renamed grid data -> state
This commit is contained in:
parent
2eeb96a66f
commit
7c0f93b7ad
4 changed files with 24 additions and 24 deletions
|
@ -62,7 +62,7 @@ export default {
|
||||||
maxRows: 3,
|
maxRows: 3,
|
||||||
rows: 2,
|
rows: 2,
|
||||||
cols: 2,
|
cols: 2,
|
||||||
getStartData(cell: string) {
|
getStartState(cell: string) {
|
||||||
return cell;
|
return cell;
|
||||||
},
|
},
|
||||||
getUnlocked() {
|
getUnlocked() {
|
||||||
|
@ -73,11 +73,11 @@ export default {
|
||||||
return player.points.eq(10);
|
return player.points.eq(10);
|
||||||
},
|
},
|
||||||
getStyle(cell) {
|
getStyle(cell) {
|
||||||
return { backgroundColor: "#" + ((Number((this[cell] as GridCell).data) * 1234) % 999999) };
|
return { backgroundColor: "#" + ((Number((this[cell] as GridCell).state) * 1234) % 999999) };
|
||||||
},
|
},
|
||||||
click(cell) {
|
click(cell) {
|
||||||
// Don't forget onHold
|
// Don't forget onHold
|
||||||
(this[cell] as GridCell).data = ((this[cell] as GridCell).data as number) + 1;
|
(this[cell] as GridCell).state = ((this[cell] as GridCell).state as number) + 1;
|
||||||
},
|
},
|
||||||
getTitle(cell) {
|
getTitle(cell) {
|
||||||
let direction;
|
let direction;
|
||||||
|
@ -95,7 +95,7 @@ export default {
|
||||||
</tooltip>`;
|
</tooltip>`;
|
||||||
},
|
},
|
||||||
getDisplay(cell) {
|
getDisplay(cell) {
|
||||||
return (this[cell] as GridCell).data;
|
return (this[cell] as GridCell).state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,23 +404,23 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
|
||||||
setupFeatures<NonNullable<RawLayer["grids"]>, Grid>(layer.id, layer.grids);
|
setupFeatures<NonNullable<RawLayer["grids"]>, Grid>(layer.id, layer.grids);
|
||||||
for (const id in layer.grids.data) {
|
for (const id in layer.grids.data) {
|
||||||
setDefault(player.layers[layer.id].grids, id, {});
|
setDefault(player.layers[layer.id].grids, id, {});
|
||||||
layer.grids.data[id].getData = function(cell): State {
|
layer.grids.data[id].getState = function(cell): State {
|
||||||
if (playerProxy.layers[this.layer].grids[id][cell] != undefined) {
|
if (playerProxy.layers[this.layer].grids[id][cell] != undefined) {
|
||||||
return playerProxy.layers[this.layer].grids[id][cell];
|
return playerProxy.layers[this.layer].grids[id][cell];
|
||||||
}
|
}
|
||||||
if (isFunction(this.getStartData)) {
|
if (isFunction(this.getStartState)) {
|
||||||
return (this.getStartData as (this: Grid, cell: string | number) => State)(
|
return (this.getStartState as (this: Grid, cell: string | number) => State)(
|
||||||
cell
|
cell
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.getStartData;
|
return this.getStartState;
|
||||||
};
|
};
|
||||||
layer.grids.data[id].setData = function(cell, data) {
|
layer.grids.data[id].setState = function(cell, state) {
|
||||||
playerProxy.layers[this.layer].grids[id][cell] = data;
|
playerProxy.layers[this.layer].grids[id][cell] = state;
|
||||||
};
|
};
|
||||||
setDefault(layer.grids.data[id], "getUnlocked", true, false);
|
setDefault(layer.grids.data[id], "getUnlocked", true, false);
|
||||||
setDefault(layer.grids.data[id], "getCanClick", true, false);
|
setDefault(layer.grids.data[id], "getCanClick", true, false);
|
||||||
setDefault(layer.grids.data[id], "getStartData", "", false);
|
setDefault(layer.grids.data[id], "getStartState", "", false);
|
||||||
setDefault(layer.grids.data[id], "getStyle", undefined, false);
|
setDefault(layer.grids.data[id], "getStyle", undefined, false);
|
||||||
setDefault(layer.grids.data[id], "click", undefined, false);
|
setDefault(layer.grids.data[id], "click", undefined, false);
|
||||||
setDefault(layer.grids.data[id], "hold", undefined, false);
|
setDefault(layer.grids.data[id], "hold", undefined, false);
|
||||||
|
@ -433,15 +433,15 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
|
||||||
for (const id in layer.boards.data) {
|
for (const id in layer.boards.data) {
|
||||||
setDefault(layer.boards.data[id], "width", "100%");
|
setDefault(layer.boards.data[id], "width", "100%");
|
||||||
setDefault(layer.boards.data[id], "height", "400px");
|
setDefault(layer.boards.data[id], "height", "400px");
|
||||||
setDefault(layer.boards.data[id], "nodes", function() {
|
setDefault(layer.boards.data[id], "nodes", function(this: Board) {
|
||||||
return playerProxy.layers[this.layer].boards[this.id].nodes;
|
return playerProxy.layers[this.layer].boards[this.id].nodes;
|
||||||
});
|
});
|
||||||
setDefault(layer.boards.data[id], "selectedNode", function() {
|
setDefault(layer.boards.data[id], "selectedNode", function(this: Board) {
|
||||||
return playerProxy.layers[this.layer].boards[this.id].nodes.find(
|
return playerProxy.layers[this.layer].boards[this.id].nodes.find(
|
||||||
node => node.id === playerProxy.layers[this.layer].boards[this.id].selectedNode
|
node => node.id === playerProxy.layers[this.layer].boards[this.id].selectedNode
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
setDefault(layer.boards.data[id], "selectedAction", function() {
|
setDefault(layer.boards.data[id], "selectedAction", function(this: Board) {
|
||||||
if (this.selectedNode == null) {
|
if (this.selectedNode == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -460,11 +460,11 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
|
||||||
action.id === playerProxy.layers[this.layer].boards[this.id].selectedAction
|
action.id === playerProxy.layers[this.layer].boards[this.id].selectedAction
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
setDefault(layer.boards.data[id], "links", function() {
|
setDefault(layer.boards.data[id], "links", function(this: Board) {
|
||||||
if (this.selectedAction == null) {
|
if (this.selectedAction == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this.selectedAction.links) {
|
if (this.selectedAction.links && this.selectedNode) {
|
||||||
if (typeof this.selectedAction.links === "function") {
|
if (typeof this.selectedAction.links === "function") {
|
||||||
return this.selectedAction.links(this.selectedNode);
|
return this.selectedAction.links(this.selectedNode);
|
||||||
}
|
}
|
||||||
|
|
10
src/typings/features/grid.d.ts
vendored
10
src/typings/features/grid.d.ts
vendored
|
@ -5,11 +5,11 @@ export interface Grid extends Feature {
|
||||||
maxRows: number;
|
maxRows: number;
|
||||||
rows: number;
|
rows: number;
|
||||||
cols: number;
|
cols: number;
|
||||||
getData?: (cell: string | number) => State;
|
getState?: (cell: string | number) => State;
|
||||||
setData?: (cell: string | number, data: State) => void;
|
setState?: (cell: string | number, state: State) => void;
|
||||||
getUnlocked: boolean | ((cell: string | number) => boolean);
|
getUnlocked: boolean | ((cell: string | number) => boolean);
|
||||||
getCanClick: boolean | ((cell: string | number) => boolean);
|
getCanClick: boolean | ((cell: string | number) => boolean);
|
||||||
getStartData: State | ((cell: string | number) => State);
|
getStartState: State | ((cell: string | number) => State);
|
||||||
getStyle?:
|
getStyle?:
|
||||||
| Partial<CSSStyleDeclaration>
|
| Partial<CSSStyleDeclaration>
|
||||||
| ((cell: string | number) => Partial<CSSStyleDeclaration> | undefined);
|
| ((cell: string | number) => Partial<CSSStyleDeclaration> | undefined);
|
||||||
|
@ -20,8 +20,8 @@ export interface Grid extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GridCell extends Feature {
|
export interface GridCell extends Feature {
|
||||||
data: State;
|
state: State;
|
||||||
dataSet: (data: State) => void;
|
stateSet: (state: State) => void;
|
||||||
effect?: State;
|
effect?: State;
|
||||||
unlocked: boolean;
|
unlocked: boolean;
|
||||||
canClick: boolean;
|
canClick: boolean;
|
||||||
|
|
|
@ -151,7 +151,7 @@ function getCellHandler(id: string) {
|
||||||
let prop = target[key];
|
let prop = target[key];
|
||||||
|
|
||||||
if (isFunction(prop) && prop.forceCached === false) {
|
if (isFunction(prop) && prop.forceCached === false) {
|
||||||
return () => prop.call(receiver, id, target.getData(id));
|
return () => prop.call(receiver, id, target.getState(id));
|
||||||
}
|
}
|
||||||
if (prop != undefined || key.slice == undefined) {
|
if (prop != undefined || key.slice == undefined) {
|
||||||
return prop;
|
return prop;
|
||||||
|
@ -160,14 +160,14 @@ function getCellHandler(id: string) {
|
||||||
key = key.slice(0, 1).toUpperCase() + key.slice(1);
|
key = key.slice(0, 1).toUpperCase() + key.slice(1);
|
||||||
prop = target[`get${key}`];
|
prop = target[`get${key}`];
|
||||||
if (isFunction(prop)) {
|
if (isFunction(prop)) {
|
||||||
return prop.call(receiver, id, target.getData(id));
|
return prop.call(receiver, id, target.getState(id));
|
||||||
} else if (prop != undefined) {
|
} else if (prop != undefined) {
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
prop = target[`on${key}`];
|
prop = target[`on${key}`];
|
||||||
if (isFunction(prop)) {
|
if (isFunction(prop)) {
|
||||||
return () => prop.call(receiver, id, target.getData(id));
|
return () => prop.call(receiver, id, target.getState(id));
|
||||||
} else if (prop != undefined) {
|
} else if (prop != undefined) {
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue