Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fresh commit history, using existing code:
Explicitly pass dependencies to nodes, so this way we dont need this abstraction registry which is a bit confusing to parse and would not be generic friendly (#1) Moved everything into workspaces. Created an editor workspace added empty contract and tests (#2) Editor flow (#3) * imported flow editor code. working on integrating it into the workspace. need to update to use the new api * show editor and preview side by side * have editor side by side * have editor properly rendering next to scene and we can orbit :) Editor alters scene (#5) * Render scene with spinning suzanne working nicely * have scene working * fix overflow issue * fixed controls color * can pause and resume * can select node from dropdown :) Update README.md Update README.md Update README.md Enabled minting ui (#7) * Clicking works Figured out how to add clicks! Had to pass 'async" to true and evaluate on startup! * simplified to juist clisk * Code cleanup from before * Can click to change! need a second output for it to work * cleaned up ui * got test running * wrote first test * can now have token gated actions. lets publish it! * wip on rainbow and clearing out js files * fix build * Added rainbow kit button * can mint token * saving and loading world works :) Fix smart contracts in space (#8) * emitting the count * got smart contracts working!!!, it fires and subscribes from thepage ;) * styled some nav and pages fixing main removing node thing remove jest click to animate can now be synced thanks toa number fix click to animate elim consoel.log update readme and simplify click to animate simplified readme fixed bugs around loading color, and loading from ipfs added animated building color moved framework into packages/framework. using preconstruct to build now Can now build the editor easily with: yarn install yarn build-editor update readme and fix logo
- Loading branch information
0 parents
commit 04b495e
Showing
243 changed files
with
29,061 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules | ||
dist | ||
.DS_Store | ||
package-lock.json | ||
node-spec.json | ||
*.blend1 | ||
node-spec.csv | ||
yarn-error.log | ||
# hardhat things | ||
cache | ||
artifacts | ||
typechain-types | ||
.env |
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,8 @@ | ||
module.exports = { | ||
trailingComma: 'es5', | ||
tabWidth: 2, | ||
semi: true, | ||
singleQuote: true, | ||
printWidth: 120, | ||
bracketSpacing: true, | ||
}; |
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,16 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"type": "chrome", | ||
"name": "https://localhost:5173", | ||
"request": "launch", | ||
"url": "https://localhost:5173" | ||
}, | ||
{ | ||
"type": "chrome", | ||
"name": "http://localhost:5173", | ||
"request": "launch", | ||
"url": "http://localhost:5173" | ||
} | ||
] | ||
} |
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,5 @@ | ||
{ | ||
"prettier.configPath": ".prettierrc.js", | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
} |
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,6 @@ | ||
Internet Systems Consortium license | ||
Copyright (c) 2022 behave-graph authors | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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,34 @@ | ||
# interX | ||
|
||
This respository is created as a fork from Ben Houston's [behave-graph](https://github.com/bhouston/behave-graph), and incorporates code from [behave-flow](https://github.com/beeglebug/behave-flow) for the user interface. It takes the existing functionality, and enables a scene to be edited side by side with the node-based editor, and allows the scene graphs to be stores on IPFS and evm compatible blockchains. | ||
|
||
This was made for the [EthGlobal EthSf hackathon](https://sf.ethglobal.com/) | ||
|
||
## Organization | ||
|
||
This repo is organized into the following workspaces: | ||
|
||
- /contracts contains the smart contract | ||
- /editor is the behavior-graph editor and minting tool, built in react, react three fiber and using the behave-flow code. | ||
- /framework contains the forked code from behave-graph which acts as the execution engine for the behavior graph | ||
|
||
## Useful code | ||
|
||
- [Behavior Graph smart contract](/contracts/BehaviorGraph.sol), with token gated actions | ||
- [Behavior Graph smart contract unit tests](/test/BehaviorGraph.ts) | ||
- [Scene Modification code from the Behavior Graph](/editor/src/scene/useSceneModifier.ts) | ||
- [Hook to mint the behavior graph and actions into the smart contract](/editor/src/hooks/useInteractiveWorldMinter.ts) | ||
|
||
## Developer Setup | ||
|
||
Install all dependencies: | ||
|
||
yarn install | ||
|
||
To start the editor: | ||
|
||
yarn dev | ||
|
||
To run the unit tests for the smart contracts | ||
|
||
yarn test |
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,15 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
bugfixes: true, | ||
targets: { | ||
esmodules: true, | ||
}, | ||
}, | ||
], | ||
'@babel/preset-react', | ||
'@babel/preset-typescript', | ||
], | ||
}; |
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,121 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import '@openzeppelin/contracts/token/ERC721/ERC721.sol'; | ||
import '@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol'; | ||
import '@openzeppelin/contracts/access/Ownable.sol'; | ||
import '@openzeppelin/contracts/utils/Counters.sol'; | ||
|
||
enum NodeType { | ||
Action, | ||
DataSource | ||
} | ||
|
||
struct TokenGateRule { | ||
bool active; | ||
address tokenContract; | ||
} | ||
|
||
|
||
struct Node { | ||
string id; | ||
NodeType nodeType; | ||
TokenGateRule tokenGateRule; | ||
} | ||
|
||
contract BehaviorGraph is ERC721, ERC721URIStorage, Ownable { | ||
using Counters for Counters.Counter; | ||
|
||
mapping(uint256 => mapping(string => Node)) private _tokenNodes; | ||
mapping(uint256 => mapping(string => uint256)) private _tokenNodeEmitCount; | ||
|
||
Counters.Counter private _nodeCounter; | ||
|
||
Counters.Counter private _tokenIdCounter; | ||
|
||
event SafeMint(uint256 tokenId, address to, string uri, Node[] nodes); | ||
|
||
error InvalidActionId(string nodeId); | ||
error MissingTokens(string nodeId, address tokenAddress); | ||
|
||
event ActionExecuted(address executor, uint256 tokenId, string actionId, uint256 count); | ||
|
||
constructor() ERC721("MyToken", "MTK") {} | ||
|
||
function _baseURI() internal pure override returns (string memory) { | ||
return "ipfs://"; | ||
} | ||
|
||
function safeMint(string memory sceneUri, Node[] calldata _nodes) public onlyOwner returns(uint256) { | ||
uint256 tokenId = _tokenIdCounter.current(); | ||
_tokenIdCounter.increment(); | ||
address to = msg.sender; | ||
_safeMint(to, tokenId); | ||
_setTokenURI(tokenId, sceneUri); | ||
_createNodes(tokenId, _nodes); | ||
emit SafeMint(tokenId, to, sceneUri, _nodes); | ||
|
||
return tokenId; | ||
} | ||
|
||
// The following functions are overrides required by Solidity. | ||
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { | ||
super._burn(tokenId); | ||
} | ||
|
||
function tokenURI(uint256 tokenId) | ||
public | ||
view | ||
override(ERC721, ERC721URIStorage) | ||
returns (string memory) | ||
{ | ||
return super.tokenURI(tokenId); | ||
} | ||
|
||
function _createNodes(uint256 tokenId, Node[] calldata _nodes) private onlyOwner { | ||
for(uint256 i = 0; i < _nodes.length; i++) { | ||
Node calldata node = _nodes[i]; | ||
_tokenNodes[tokenId][node.id] = node; | ||
} | ||
} | ||
|
||
function getNode(uint256 tokenId, string memory _nodeId) public view returns(Node memory) { | ||
return _tokenNodes[tokenId][_nodeId]; | ||
} | ||
|
||
function executeAction(uint256 tokenId, string calldata _nodeId) public { | ||
Node memory node = getNode(tokenId, _nodeId); | ||
|
||
_assertCanExecuteAction(node); | ||
|
||
uint256 actionCount = ++_tokenNodeEmitCount[tokenId][_nodeId]; | ||
|
||
emit ActionExecuted(msg.sender, tokenId, _nodeId, actionCount); | ||
} | ||
|
||
function getActionCounts(uint256 tokenId, string[] calldata _nodeIds) public view returns(uint256[] memory) { | ||
// uint256 numberElems = _nodeIds.length; | ||
uint256[] memory result = new uint256[](_nodeIds.length); | ||
|
||
for(uint256 i = 0; i < _nodeIds.length; i++) { | ||
string memory _nodeId = _nodeIds[i]; | ||
uint256 count = _tokenNodeEmitCount[tokenId][_nodeId]; | ||
result[i] = count; | ||
} | ||
return result; | ||
} | ||
|
||
function _assertCanExecuteAction(Node memory node) private view { | ||
if (!node.tokenGateRule.active) { | ||
return; | ||
} | ||
|
||
ERC721 erc721Contract = ERC721(node.tokenGateRule.tokenContract); | ||
|
||
uint256 balance = erc721Contract.balanceOf(msg.sender); | ||
|
||
if (balance <= 0) { | ||
revert MissingTokens(node.id, msg.sender); | ||
} | ||
} | ||
} |
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
|
||
contract Token is ERC721, ERC721URIStorage, Ownable { | ||
using Counters for Counters.Counter; | ||
|
||
Counters.Counter private _tokenIdCounter; | ||
|
||
constructor() ERC721("Token", "MTK") {} | ||
|
||
function safeMint(string memory uri) public { | ||
address to = msg.sender; | ||
uint256 tokenId = _tokenIdCounter.current(); | ||
_tokenIdCounter.increment(); | ||
_safeMint(to, tokenId); | ||
_setTokenURI(tokenId, uri); | ||
} | ||
|
||
// The following functions are overrides required by Solidity. | ||
|
||
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { | ||
super._burn(tokenId); | ||
} | ||
|
||
function tokenURI(uint256 tokenId) | ||
public | ||
view | ||
override(ERC721, ERC721URIStorage) | ||
returns (string memory) | ||
{ | ||
return super.tokenURI(tokenId); | ||
} | ||
} |
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 @@ | ||
../framework/dist |
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,10 @@ | ||
{ | ||
"extends": ["plugin:react-hooks/recommended", "prettier"], | ||
"rules": { | ||
"prettier/prettier": 0, | ||
"simple-import-sort/imports": 0, | ||
"import/extensions": 0, | ||
"unused-imports/no-unused-imports": 1, | ||
"@typescript-eslint/no-empty-function": 1 | ||
} | ||
} |
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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Interactive On-Chain World Builder</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,45 @@ | ||
{ | ||
"name": "@behavior-graph/editor", | ||
"private": true, | ||
"version": "0.0.1", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@fortawesome/fontawesome-svg-core": "^6.2.0", | ||
"@fortawesome/free-solid-svg-icons": "^6.2.0", | ||
"@fortawesome/react-fontawesome": "^0.2.0", | ||
"@rainbow-me/rainbowkit": "^0.7.1", | ||
"@react-three/drei": "^9.40.0", | ||
"@react-three/fiber": "^8.9.1", | ||
"classnames": "^2.3.2", | ||
"clsx": "^1.2.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-router-dom": "^6.4.3", | ||
"reactflow": "^11.2.0", | ||
"three": "^0.146.0", | ||
"use-why-did-you-update": "^0.1.0", | ||
"uuid": "^9.0.0", | ||
"wagmi": "^0.7.12", | ||
"web3.storage": "^4.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.22", | ||
"@types/react-dom": "^18.0.7", | ||
"@types/uuid": "^8.3.4", | ||
"@typescript-eslint/parser": "^5.42.0", | ||
"@vitejs/plugin-react": "^2.2.0", | ||
"autoprefixer": "^10.4.13", | ||
"eslint": "^8.26.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"postcss": "^8.4.18", | ||
"tailwindcss": "^3.2.2", | ||
"typescript": "^4.6.4", | ||
"vite": "^3.2.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,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
Binary file not shown.
Oops, something went wrong.