-
Notifications
You must be signed in to change notification settings - Fork 0
/
Webway.sol
108 lines (84 loc) · 3.62 KB
/
Webway.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
pragma solidity >=0.8.0 <0.9.0;
//SPDX-License-Identifier: MIT
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "hardhat/console.sol";
// import "@openzeppelin/contracts/access/Ownable.sol";
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
string constant spacea_ipfs = "ipfs://bafkreibpsykg63ru34uwkl3qufgymrk5l2gt6wmjvapb3nqmzyfbnaypvy";
address constant address_a = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
string constant effectAKey = "makeSkyOnFire";
string constant effectAIpfs = "ipfs://bafkreief42ckfa7fbxikb33xqjxmukqkf4lmbq3pk6cclpo6ajrvxf4m6u";
string constant effectBKey = "changeWaterColor";
string constant effectBIpfs = "ipfs://bafkreihr4tnpf4f4lkbmyz3pv5ofmewgcgkyuaj6yvgy53z46stjvzqayu";
contract Webway is ERC721URIStorage {
// event EffectEmitted(string _type, );
struct Effect {
uint256 _token_id;
string _key;
bool _active;
string _uri;
bool init;
}
event EffectToggle(uint256 _token_id, string _key, bool _active, string _uri);
event ChangeURI(uint256 _index, string _uri);
// string[] effectIndex = ['statue1','statue2','skybox1'];
// mapping(string => Effect) effectData;
mapping(uint256 => mapping (string => Effect)) public effectData;
mapping(string => mapping(address => uint)) public metadataUri;
uint256 counter;
constructor(string memory name_, string memory symbol_) ERC721 (name_, symbol_) {
_safeMint(address_a, counter);
changeURI(counter, spacea_ipfs);
addEffect(counter, effectAIpfs, effectAKey);
addEffect(counter, effectBIpfs, effectBKey);
// addEffect(effectBIpfs, effectBKey);
counter++;
_safeMint(address_a, counter);
addEffect(counter, effectAIpfs, effectAKey);
changeURI(counter, spacea_ipfs);
counter++;
// _initEffects();
}
function mintNewSpace(string memory _uri) public {
_safeMint(msg.sender, counter);
changeURI(counter, _uri);
counter++;
}
function addEffect(uint256 _index, string memory _uri, string memory _key) public {
require(!effectData[_index][_key].init, "Effect already initialized");
Effect storage newEffect = effectData[_index][_key];
newEffect._token_id = _index;
newEffect._key = _key;
newEffect._active = false;
newEffect._uri = _uri;
newEffect.init = true;
emit EffectToggle(_index, _key, false, _uri);
}
// function _initEffects() internal {
// Effect storage statue = effectData['statue'];
// Effect storage sky = effectData['sky'];
// Effect storage portal = effectData['portal'];
// statue._type = 'object';
// statue._uri = 'statuehash';
// statue.init = true;
// sky._type = 'background';
// sky._uri = 'skyhash';
// sky.init = true;
// portal._type = 'portal';
// portal._uri = 'portalhash';
// portal.init = true;
// toggleEffect('statue');
// toggleEffect('sky');
// toggleEffect('portal');
// }
function changeURI(uint256 _index, string memory _uri) public {
_setTokenURI(_index, _uri);
emit ChangeURI(_index, _uri);
}
function toggleEffect(uint256 _index, string memory _id) public {
Effect storage _effect = effectData[_index][_id];
require(_effect.init == true, "No such effect found");
_effect._active = !_effect._active;
emit EffectToggle(_index, _effect._key, _effect._active, _effect._uri);
}
}