Skip to content

Commit

Permalink
🎲🦠 -> Fixed issue with Metamask/wallet extension, added state for #15 &
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Feb 15, 2022
1 parent f402d9c commit 40a57f3
Show file tree
Hide file tree
Showing 29 changed files with 12,754 additions and 0 deletions.
43 changes: 43 additions & 0 deletions contracts/GameContent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ contract GameContent is ERC721 {
// Mapping from an address => tokenId
mapping(address => uint256) public nftHolders;

// Event/webhook to see if the NFT was correctly minted
event CharacterNFTMinted(
address sender,
uint256 tokenId,
uint256 characterIndex
);
event AttackComplete(uint256 newBossHp, uint256 newPlayerHp);

// Values passed in from scripts/run.js
constructor(
string[] memory characterNames,
Expand Down Expand Up @@ -126,6 +134,9 @@ contract GameContent is ERC721 {

// Increment tokenId for the next call
_tokenIds.increment();

// Catch the event (i.e. webhook/api EVENT)
emit CharacterNFTMinted(msg.sender, newItemId, _characterIndex);
}

function tokenURI(uint256 _tokenId)
Expand Down Expand Up @@ -168,4 +179,36 @@ contract GameContent is ERC721 {

return output;
}

// Check if a user has a CharacterNFT given to them, and then retrieve THEIR NFT's attributes
function checkIfUserHasNFT()
public
view
returns (CharacterAttributes memory)
{
// Get the tokenId of the user's character NFT
uint256 userNftTokenId = nftHolders[msg.sender];
// If the user has a tokenId in the map, return their character
if (userNftTokenId > 0) {
return nftHolderAttributes[userNftTokenId];
}
// Else return empty character
else {
CharacterAttributes memory emptyStruct;
return emptyStruct;
}
}

// Get characters
function getAllDefaultCharacters()
public
view
returns (CharacterAttributes[] memory)
{
return defaultCharacters;
}

function getBoss() public view returns (Boss memory) {
return bossCharacter;
}
}
2 changes: 2 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_STORE
9 changes: 9 additions & 0 deletions frontend/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"2gua.rainbow-brackets",
"usernamehw.errorlens",
"yzhang.markdown-all-in-one"
]
}
21 changes: 21 additions & 0 deletions frontend/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 buildspace

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# buildspace NFT Game Project

### **Welcome 👋**
To get started with this course, clone this repo and follow these commands:

1. Run `npm install` at the root of your directory
2. Run `npm run start` to start the project
3. Start coding!

### What is the `.vscode` Folder?
If you use VSCode to build your app, we included a list of suggested extensions that will help you build this project! Once you open this project in VSCode, you will see a popup asking if you want to download the recommended extensions :).


### **Questions?**
Have some questions make sure you head over to your [buildspace Dashboard](https://app.buildspace.so/courses/CO5cc2751b-e878-41c4-99fa-a614dc910ee9) and link your Discord account so you can get access to helpful channels teaching assistants, and your instructor!
39 changes: 39 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "nft-game-starter",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"ethers": "^5.4.7",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added frontend/public/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/favicon.ico
Binary file not shown.
60 changes: 60 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Metaverse Slayer</title>
<meta name="title" content="Metaverse Slayer" />
<meta name="description" content="Team up with me to defeat the foes of the Metaverse!" />

<!-- Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://buildspace.so/">
<meta property="og:title" content="Metaverse Slayer">
<meta property="og:description" content="Team up with me to defeat the foes of the Metaverse!">
<meta property="og:image" content="https://s3.amazonaws.com/cdn.buildspace.so/courses/nft-game/metadata.png">

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://buildspace.so/">
<meta property="twitter:title" content="Metaverse Slayer">
<meta property="twitter:description" content="Team up with me to defeat the foes of the Metaverse!">
<meta property="twitter:image"
content="https://s3.amazonaws.com/cdn.buildspace.so/courses/nft-game/metadata.png">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added frontend/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions frontend/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions frontend/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
142 changes: 142 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
.App {
height: 100vh;
background-color: #0d1116;
overflow: scroll;
text-align: center;
}

.container {
height: 100%;
background-color: #0d1116;
display: flex;
flex-direction: column;
justify-content: space-between;
}

.header-container {
padding-top: 30px;
}

.header {
margin: 0;
font-size: 50px;
font-weight: bold;
color: white;
}

.sub-text {
font-size: 25px;
color: white;
}

.content-container {
background-color: #a200d6;
}

.cta-button {
height: 45px;
border: 0;
width: auto;
padding-left: 40px;
padding-right: 40px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
color: white;
}

.connect-wallet-container {
display: flex;
flex-direction: column;
margin: auto;
max-width: 550px;
}

.connect-wallet-container img {
padding-bottom: 20px;
}

.connect-wallet-button {
background-image: linear-gradient(
to right,
#ff8177 0%,
#ff867a 0%,
#ff8c7f 21%,
#f99185 52%,
#cf556c 78%,
#b12a5b 100%
);
background-size: 200% 200%;
animation: gradient-animation 4s ease infinite;
}

.mint-button {
background: -webkit-linear-gradient(left, #a200d6, #ff6fdf);
background-size: 200% 200%;
animation: gradient-animation 4s ease infinite;
margin-right: 15px;
}

.opensea-button {
background-color: rgb(32, 129, 226);
}

.mint-count {
color: white;
font-size: 18px;
font-weight: bold;
}

.footer-container {
display: flex;
justify-content: center;
align-items: center;
padding-bottom: 30px;
}

.twitter-logo {
width: 35px;
height: 35px;
}

.footer-text {
color: white;
font-size: 16px;
font-weight: bold;
}

/* KeyFrames */
@-webkit-keyframes gradient-animation {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
@-moz-keyframes gradient-animation {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
@keyframes gradient-animation {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
Loading

0 comments on commit 40a57f3

Please sign in to comment.