Skip to content

Commit

Permalink
fixed flash games
Browse files Browse the repository at this point in the history
  • Loading branch information
finchodev committed Apr 5, 2022
1 parent d8a1ad8 commit 5079422
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 3 deletions.
6 changes: 3 additions & 3 deletions g.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ <h3 class="title">Tower Building</h3>
<img src="./game-imgs/slope.jpg" class="thumbnail">
<h3 class="title">Slope</h3>
</a>
<a class="game" href="./g/swfs/#bullet_bill_26.swf">
<a class="game" href="/g/flash/index.html?swf=bullet_bill_26.swf">
<img src="./game-imgs/bulletbill.png" class="thumbnail">
<h3 class="title">Bullet Bill</h3>
</a>
<a class="game" href="./g/swfs/#portal2d">
<a class="game" href="/g/flash/index.html?swf=portal2d.swf">
<img src="./game-imgs/portal.png" class="thumbnail">
<h3 class="title">Portal 2D</h3>
</a>
<a class="game" href="./g/swfs/#zombocalypse">
<a class="game" href="/g/flash/index.html?swf=zombocalypse.swf">
<img src="./game-imgs/zomb.png" class="thumbnail">
<h3 class="title">Zombocalypse</h3>
</a>
Expand Down
Binary file added g/flash/d6dd295efb44ba365d0d.wasm
Binary file not shown.
240 changes: 240 additions & 0 deletions g/flash/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<!DOCTYPE html>
<html>
<head>
<!-- HU Querystring fix -->
<base href="/g/flash/">

<title>Flash Player</title>
<style>
body {
overflow: hidden;
font-family: sans-serif;
}

.main {
background: black;
position: absolute;
width: 100%;
height: 100%;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
overflow: hidden;
}

.gembed {
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNTAiIGhlaWdodD0iNTAiPjx0ZXh0IHN0eWxlPSJmb250OiAzMHB4IHNhbnMtc2VyaWY7IiBmaWxsPSJ3aGl0ZSIgeD0iNTAlIiB5PSI1MCUiIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPkxvYWRpbmc8L3RleHQ+PC9zdmc+");
background-repeat: no-repeat;
background-position: center;
}

#ffd {
height: 200px;
width: 400px;
position: absolute;
background-color: #dddddd;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
border-radius: 2px;
overflow: auto;
z-index: 5;
}

#ffd::before {
opacity: 0;
width: 100%;
height: 0px;
background-color: #333333;
content: "Drop File Here";
position: absolute;
top: 0px;
left: 0px;
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
font-weight: bold;
color: white;
}

#ffd.filehover::before {
opacity: 1;
height: 100%;
}

#ffd.filehover {
border: 2px dashed #dddddd;
background-color: #333333;
}

input[type="file"] {
display: none;
}

#upload+label {
border: 1px solid rgb(118, 118, 118);
border-radius: 2px;
padding: 4px;
margin: 10px;
font-size: 13px;
background-color: white;
display: inline-block;
transition: ease .1s;
user-select: none;
}

#upload+label:hover {
background-color: #eee;
}

#ffd .source {
display: block;
position: absolute;
left: 50%;
transform: translatex(-50%);
bottom: 5px;
text-decoration: none;
color: black;
font-size: 10px;
}
</style>
<script>
// please dont use IE
if (!window.fetch) {
alert("Update your browser!");
throw "Update your browser!";
}

var cdn = "../swfs/";

// query string into object
var search = decodeURIComponent(window.location.search).substring(1).split("&");
var queries = {};
for (var i = 0; i < search.length; i++) {
var p = search[i].split('=');
queries[p[0]] = p[1];
}

// xhr
function grab(url, type, success, fail) {
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.overrideMimeType("text/plain; charset=x-user-defined");
req.responseType = type;
req.onload = function() {
if (req.status >= "400") {
fail(req.status);
} else {
success(this.response);
}
}
req.send();
}

// file reader
function readFile(file, callback) {
var reader = new FileReader();
reader.onload = function() {
callback(this.result);
}
reader.readAsArrayBuffer(file);
}

var rplayer;

// start
function startPlayer(data) {
console.log("Initializing with " + data.byteLength + " bytes of data");
rplayer.load({data: data});
}

window.addEventListener("load", function() {
var mainarea = document.getElementById("mainarea");
var ffd = document.getElementById("ffd");
var upload = document.getElementById("upload");

// make ruffle player
window.RufflePlayer = window.RufflePlayer || {};
window.RufflePlayer.config = window.RufflePlayer.config || {};
window.RufflePlayer.config.letterbox = "on";
window.RufflePlayer.config.autoplay = "auto";
const rufflei = window.RufflePlayer.newest();
rplayer = rufflei.createPlayer();
rplayer.classList.add("gembed");
rplayer.playButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="250" height="100" style="margin: auto; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"><svg viewBox="0 0 24 24" y="7pt" width="100%" height="36pt"><path fill="rgb(203, 203, 203)" d="M20.5 11H19V7c0-1.1-.9-2-2-2h-4V3.5C13 2.12 11.88 1 10.5 1S8 2.12 8 3.5V5H4c-1.1 0-1.99.9-1.99 2v3.8H3.5c1.49 0 2.7 1.21 2.7 2.7s-1.21 2.7-2.7 2.7H2V20c0 1.1.9 2 2 2h3.8v-1.5c0-1.49 1.21-2.7 2.7-2.7 1.49 0 2.7 1.21 2.7 2.7V22H17c1.1 0 2-.9 2-2v-4h1.5c1.38 0 2.5-1.12 2.5-2.5S21.88 11 20.5 11z"></path></svg><text style="font-family: sans-serif; font-size: 10pt; letter-spacing: normal; user-select: none;" fill="rgb(100, 100, 100)" x="50%" y="56pt" dominant-baseline="middle" text-anchor="middle">Click to enable Adobe Flash Player</text></svg>';
mainarea.appendChild(rplayer);

// ready for file upload
upload.onchange = function() {
ffd.style.display = "none";
rplayer.contextMenuElement.style.display = "none";
rplayer.contextMenuElement.style.zIndex = "auto";
let file = this.files[0];
readFile(file, function(data) {
console.log('Succesfully read SWF file "' + file.name + '"');
startPlayer(data);
});
}
document.ondragenter = function(e) {
if (e.dataTransfer.types.includes("Files")) ffd.classList.add("filehover");
}
ffd.ondragover = function(e) {
e.preventDefault();
}
ffd.ondrop = function(e) {
if (e.dataTransfer.types.includes("Files")) {
e.preventDefault();
ffd.style.display = "none";
rplayer.contextMenuElement.style.display = "none";
rplayer.contextMenuElement.style.zIndex = "auto";
let file = event.dataTransfer.files[0];
readFile(file, function(data) {
console.log('Succesfully read SWF file "' + file.name + '"');
startPlayer(data);
});
}
}

if (queries["swf"]) {
var swfloc = cdn + queries["swf"];
grab(swfloc, "arraybuffer", function(data) {
// start
console.log("Succesfully fetched SWF from " + swfloc);
startPlayer(data);
}, function(error) {
// xhr error
alert("Could not get SWF at " + swfloc + " (Error " + error + ")");
ffd.style.display = "block";
rplayer.contextMenuElement.style.zIndex = "-100";
});
} else {
// prompt user to upload a file
ffd.style.display = "block";
rplayer.contextMenuElement.style.zIndex = "-100";
}
}, false);
</script>
<script src="./ruffle.js"></script>
</head>
<body>
<div class="main" id="mainarea">
<div id="ffd" style="display: none;">
<h2>Flash Player Emulator</h2>
<input type="file" id="upload" accept=".swf, .spl">
<label for="upload">Choose File</label>
<a href="https://ruffle.rs" target="_blank" class="source">Source</a>
</div>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions g/flash/ruffle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions home.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ <h1 class="name"> <a class="focusLetter">F</a><a class="focusLetter">R</a><a cla
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>
<script src="particlesjs.js"></script>
<script src="./js/home.js"></script>
<script src="./js/home.js"></script>
</html>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ <h3 class="infql">Quick Launch sites</h3>
</div>
</body>
<script src="./js/alerts.js"></script>
<script src="https://unpkg.com/@ruffle-rs/ruffle"></script>
<script src="./js/index.js"></script>
</html>

0 comments on commit 5079422

Please sign in to comment.