summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-05-17 22:16:00 -0400
committerrealtradam <[email protected]>2024-05-17 22:16:00 -0400
commit3321db8f9c549103ebae46bf025a3135208a2e3b (patch)
tree49dd106a76a73ea3e4ec0e826a9b2d690d8c5363
parent98571b599449bfd7497c9b098a07b376da670319 (diff)
downloadgameHolster-3321db8f9c549103ebae46bf025a3135208a2e3b.tar.gz
gameHolster-3321db8f9c549103ebae46bf025a3135208a2e3b.zip
uploading images to games and also iframes for games
-rw-r--r--app/assets/stylesheets/application.tailwind.css3
-rw-r--r--app/controllers/api/v1/games_controller.rb67
-rw-r--r--app/javascript/components/Game.jsx23
-rw-r--r--app/javascript/components/GameCard.jsx15
-rw-r--r--app/javascript/components/Games.jsx27
-rw-r--r--app/javascript/components/Home.jsx2
-rw-r--r--app/javascript/routes/index.jsx2
-rw-r--r--app/models/game.rb3
-rw-r--r--app/models/user.rb1
-rw-r--r--config/routes.rb15
10 files changed, 132 insertions, 26 deletions
diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css
index 58d9164..8ea4fad 100644
--- a/app/assets/stylesheets/application.tailwind.css
+++ b/app/assets/stylesheets/application.tailwind.css
@@ -25,6 +25,7 @@
width: 100%;
height: 100%;
object-fit: cover;
+ image-rendering: pixelated;
}
.gameCardWrapper {
@@ -84,6 +85,7 @@
.gameTitleImg {
width: 100%;
transition: transform 0.5s;
+ image-rendering: pixelated;
}
.gameCard:hover .gameTitleImg {
transform: translate3d(0%, -50px, 100px);
@@ -95,6 +97,7 @@
transition: all 0.5s;
position: absolute;
z-index: -1;
+ image-rendering: pixelated;
}
.gameCard:hover .gameCharacterImg {
diff --git a/app/controllers/api/v1/games_controller.rb b/app/controllers/api/v1/games_controller.rb
index 7b033df..e3838de 100644
--- a/app/controllers/api/v1/games_controller.rb
+++ b/app/controllers/api/v1/games_controller.rb
@@ -1,15 +1,20 @@
+require 'irb'
+
class Api::V1::GamesController < ApplicationController
skip_before_action :verify_authenticity_token
+ before_action :allow_iframe, only: [:play]
def create
- result = User.find_by(access_token_digest: cookies[:session])
- if(!result)
+ user = User.find_by(access_token_digest: cookies[:session])
+ if(!user)
head :unauthorized
else
- @game = Game.new(games_params)
- @game.titleSlug = games_params[:title].parameterize
- @game.user_id = result.id
+ pp params
+ @game = Game.new(game_params)
+ @game.titleSlug = game_params[:title].parameterize
+ @game.user_id = user.id
+ user.games << @game
if @game.save
- pp @game
+
render json: @game, status: :created
else
render json: @game.errors, status: :unprocessable_entity
@@ -17,8 +22,31 @@ class Api::V1::GamesController < ApplicationController
end
end
- # :user/:game/*path/:file
+
+ # list of all games
def index
+ game = Game.all.order(created_at: :desc)
+ render json: game
+ end
+
+ # single game or list of user's games
+ #get 'games/:user/:game', to: 'games#show'
+ #get 'games/:user', to: 'games#show'
+ def show
+ user = User.find_by! user_name: params[:user]
+ if params[:game].nil?
+ # get list of user games
+ games = Game.where(user_id: user.id).order(created_at: :desc)
+ render json: games
+ else
+ game = Game.find_by! user_id: user.id, titleSlug: params[:game]
+ render json: game
+ # get game
+ end
+ end
+
+ # :user/:game/*path/:file
+ def play
user = User.find_by user_name: params[:user]
if(user.nil?)
game = Game.all.order(created_at: :desc)
@@ -57,9 +85,30 @@ class Api::V1::GamesController < ApplicationController
#render html: game.game_files.first.download.html_safe #Game.first.game_file.download.html_safe
end
+ #get 'imggames/:user/:game/:file', to: 'games#show_img'
+ def show_img
+ user = User.find_by! user_name: params[:user]
+ game = Game.find_by! user_id: user.id, titleSlug: params[:game]
+
+ result = nil;
+ if params[:type] == "char"
+ result = game.char_img.download
+ elsif params[:type] == "title"
+ result = game.title_img.download
+ elsif params[:type] == "card"
+ result = game.card_img.download
+ end
+
+ send_data result, type: 'image/png', disposition: 'inline'
+ end
+
private
- def games_params
- params.require(:game).permit(:title, :titleSlug, game_files: [])
+ def game_params
+ params.require(:game).permit(:title, :card_img, :char_img, :title_img, game_files: [])
+ end
+
+ def allow_iframe
+ response.headers.delete('X-Frame-Options')
end
end
diff --git a/app/javascript/components/Game.jsx b/app/javascript/components/Game.jsx
new file mode 100644
index 0000000..8b80b8e
--- /dev/null
+++ b/app/javascript/components/Game.jsx
@@ -0,0 +1,23 @@
+import React, { useState, useEffect } from "react";
+import { useParams } from "react-router-dom";
+//import { Link } from "react-router-dom";
+import GameCard from "./GameCard";
+import Button from "./Button";
+
+//<Route path="/games/:user/:game" element={<Game />} />
+
+//export default () => (
+export default function Games () {
+ let { user, game } = useParams();
+//http://localhost:3000/api/v1/game/realtradam/orc-arena-of-time/index.html
+ return(
+ <>
+ <div>
+ <div className="flex flex-col gap-16 max-w-6xl shrink">
+ <div className="title font-bold text-6xl font-title">Orc: Arena of Time</div>
+ <iframe style={{ aspectRatio: 1 }} className="bg-black aspect-square max-h-[90vh] rounded" src="http://localhost:3000/api/v1/game/realtradam/orc-arena-of-time/index.html" title={game}></iframe>
+ </div>
+ </div>
+ </>
+ );
+};
diff --git a/app/javascript/components/GameCard.jsx b/app/javascript/components/GameCard.jsx
index 6b79630..9cd815d 100644
--- a/app/javascript/components/GameCard.jsx
+++ b/app/javascript/components/GameCard.jsx
@@ -1,17 +1,24 @@
import React from "react";
//import { Link } from "react-router-dom";
-export default function GameCard ({ link = "./", width = "72" })
+//game = {
+// card_img: "",
+// char_img: "",
+// title_img: ""
+//}
+
+export default function GameCard ({ link = "./", width = "72", game = { card_img: "https://ggayane.github.io/css-experiments/cards/dark_rider-cover.jpg", char_img: "https://ggayane.github.io/css-experiments/cards/dark_rider-character.png", title_img: "https://ggayane.github.io/css-experiments/cards/dark_rider-title.png" } })
{
+
return (
<>
<a href={ link } className="block w-min pt-10 px-1" target="_blank">
<div className="gameCard">
<div className="gameCardWrapper">
- <img src="https://ggayane.github.io/css-experiments/cards/dark_rider-cover.jpg" className="gameCardCoverImg" />
+ <img src={`/api/v1/games_img/realtradam/${game.titleSlug}.png?type=card`} className="gameCardCoverImg" />
</div>
- <img src="https://ggayane.github.io/css-experiments/cards/dark_rider-title.png" className="gameTitleImg p-5%" />
- <img src="https://ggayane.github.io/css-experiments/cards/dark_rider-character.webp" className="gameCharacterImg" />
+ <img src={`/api/v1/games_img/realtradam/${game.titleSlug}.png?type=title`} className="gameTitleImg p-5%" />
+ <img src={`/api/v1/games_img/realtradam/${game.titleSlug}.png?type=char`} className="gameCharacterImg" />
</div>
</a>
</>
diff --git a/app/javascript/components/Games.jsx b/app/javascript/components/Games.jsx
index 1862caa..f1545b8 100644
--- a/app/javascript/components/Games.jsx
+++ b/app/javascript/components/Games.jsx
@@ -1,12 +1,13 @@
import React, { useState, useEffect } from "react";
//import { Link } from "react-router-dom";
import GameCard from "./GameCard";
+import Button from "./Button";
//export default () => (
export default function Games () {
const [games, setGames] = useState([]);
useEffect(() => {
- const url = "/api/v1/games/index";
+ const url = "/api/v1/games";
fetch(url).then((response) => {
if (response.ok) {
return response.json();
@@ -14,8 +15,8 @@ export default function Games () {
throw new Error("Network response was not ok.");
}).then((response) => setGames(response)).catch(() => navigate("/"));
}, []);
- const allGames = games.map((games, index) => (
- <div>{ blog }</div>
+ const allGames = games.map((game) => (
+ <GameCard game={game} key={game.id}/>
));
var handleSubmit = (e) => {
e.preventDefault() //stops submit from happening
@@ -26,6 +27,9 @@ export default function Games () {
{
formData.append('game[game_files][]', form.game_files.files[i], form.game_files.files[i].value);
}
+ formData.append('game[card_img]', form.card_img.files[0], form.card_img.value);
+ formData.append('game[char_img]', form.char_img.files[0], form.char_img.value);
+ formData.append('game[title_img]', form.title_img.files[0], form.title_img.value);
for (var pair of formData.entries()) {
console.log(pair[0] + ', ' + pair[1])
@@ -53,7 +57,22 @@ export default function Games () {
<label>Files</label>
<input type="file" multiple="multiple" name="game_files" />
</div>
- <button type="submit" className="w-32 bg-stone-900 text-stone-50 rounded">submit</button>
+ <div>
+ <label>Card Image</label>
+ <input type="file" name="card_img" />
+ </div>
+ <div>
+ <label>Character Image</label>
+ <input type="file" name="char_img" />
+ </div>
+ <div>
+ <label>Title Image</label>
+ <input type="file" name="title_img" />
+ </div>
+ <div style={{ boxShadow: 'rgba(255,255,255,.1) 0 1px 0,rgba(0,0,0,.8) 0 1px 7px 0 inset' }} className="p-[5px] w-min h-min bg-stone-800 rounded-[5px]">
+ <Button width={ 28 } height={ 12 } link={ <button type="submit" className="w-28 h-12 bg-stone-transparent text-stone-50 rounded">Submit</button> }/>
+ </div>
+
</form>
</div>
</div>
diff --git a/app/javascript/components/Home.jsx b/app/javascript/components/Home.jsx
index 5f79834..863d81d 100644
--- a/app/javascript/components/Home.jsx
+++ b/app/javascript/components/Home.jsx
@@ -28,7 +28,7 @@ export default function Home () {
<div className="">
<div className="jumbotron jumbotron-fluid bg-transparent">
<div className="container secondary-color">
- <h1 className="text-2xl">Debug!</h1>
+ <h1 className="text-2xl">Debug! Again</h1>
<p className="">
Ea optio vitae culpa voluptatem consectetur. Ab quisquam sed ipsum. Perspiciatis minus odit quas qui consequuntur dicta reiciendis a. Nihil minima sed aliquam.
</p>
diff --git a/app/javascript/routes/index.jsx b/app/javascript/routes/index.jsx
index 6ab155f..1b778ef 100644
--- a/app/javascript/routes/index.jsx
+++ b/app/javascript/routes/index.jsx
@@ -3,6 +3,7 @@ import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Home from "../components/Home";
import Blogs from "../components/Blogs";
import Games from "../components/Games";
+import Game from "../components/Game";
import Layout from "../components/Layout";
export default function index()
@@ -26,6 +27,7 @@ export default function index()
<Route index element={<Home />} />
<Route path="/blogs" element={<Blogs />} />
<Route path="/games" element={<Games />} />
+ <Route path="/games/:user/:game" element={<Game />} />
</Route>
</Routes>
</Router>
diff --git a/app/models/game.rb b/app/models/game.rb
index 07c5098..196bef5 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -5,4 +5,7 @@ class Game < ApplicationRecord
#}
#belongs_to :user
has_many_attached :game_files
+ has_one_attached :card_img
+ has_one_attached :char_img
+ has_one_attached :title_img
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 521f0f9..0dd552d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,4 +1,3 @@
-require 'bcrypt'
class User < ApplicationRecord
validates :identifier, presence: true
has_many :games
diff --git a/config/routes.rb b/config/routes.rb
index c3f7ad7..078f1df 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -5,20 +5,21 @@ Rails.application.routes.draw do
# isolated domain, do not allow auth here
constraints host: 'localhost' do
# GAMES
- get 'game/:user/:game/*path/:file', to: 'games#index'
- get 'game/:user/:game/:file', to: 'games#index'
+ get 'game/:user/:game/*path/:file', to: 'games#play'
+ get 'game/:user/:game/:file', to: 'games#play'
end
constraints host: "127.0.0.1" do
# USERS
get 'users/index', to: 'users#index'
- #get 'users/new'
- #get 'users/create'
- #get 'users/delete'
# GAMES
post 'games', to: 'games#create'
- resources :games
+ get 'games', to: 'games#index'
+ #get 'games/:user/', to: 'games#show'
+ #get 'games/:user/:game', to: 'games#show'
+ get 'games_img/:user/:game', to: 'games#show_img'
+ #resources :games
# BLOGS
get 'blogs/index', to: 'blog#index'
@@ -33,8 +34,8 @@ Rails.application.routes.draw do
end
end
+ get '/*path' => 'homepage#index'
root 'homepage#index'
- #get '/*path' => 'homepage#index'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.