From d81bc993b8e4acc63af8cf0030d391c4befd77fb Mon Sep 17 00:00:00 2001 From: LawnCable Date: Thu, 24 May 2018 16:17:50 -0400 Subject: added basic support to have the latest news entry on the info page --- assets/fonts/SourceSansPro-Light.otf | Bin 0 -> 226032 bytes assets/index.css | 34 +++++++++++++++++++++- src/main.ts | 4 +-- src/renderer/gameserver/data.ts | 4 +++ src/renderer/gameserver/news.ts | 54 +++++++++++++++++++++++++++++++++++ src/renderer/gameserver/server.ts | 18 ++++++++++++ src/renderer/serverView.ts | 2 +- 7 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 assets/fonts/SourceSansPro-Light.otf create mode 100644 src/renderer/gameserver/news.ts diff --git a/assets/fonts/SourceSansPro-Light.otf b/assets/fonts/SourceSansPro-Light.otf new file mode 100644 index 0000000..159979f Binary files /dev/null and b/assets/fonts/SourceSansPro-Light.otf differ diff --git a/assets/index.css b/assets/index.css index 4f2b87e..446b1b5 100644 --- a/assets/index.css +++ b/assets/index.css @@ -2,6 +2,10 @@ font-family: SourceSansPro; src: url("./fonts/SourceSansPro-Regular.otf") format("opentype"); } +@font-face { + font-family: SourceSansProLight; + src: url("./fonts/SourceSansPro-Light.otf") format("opentype"); +} html, body { @@ -216,7 +220,14 @@ html, body { pointer-events: none; filter: grayscale(30%) blur(1pt); } - +#contentBackground > div { +position: absolute; +top: 0; +min-width: 100%; +min-height: 100%; +background: radial-gradient(farthest-corner at 100% 0%, rgba(256, 255, 255, 0) 50%, rgb(0, 0, 0)); +z-index: 2; +} #serverPage{ position: absolute; z-index: 4; @@ -247,8 +258,29 @@ html, body { /*outline: 1pt red dotted;*/ background: rgba(0, 0, 0, 0.6); width: fit-content; + margin-bottom: 7pt; + padding: 3pt 3pt; +} + +.infoServerPage > .news { + background: rgba(0, 0, 0, 0.6); + width: fit-content; + cursor: default; + padding: 5pt 5pt; + font-family: SourceSansProLight; } +.infoServerPage > .news > a, + .infoServerPage > .news > p > a { + color:inherit; + text-decoration: none; + cursor: pointer; +} + +.infoServerPage > .news > a:hover, + .infoServerPage > .news > p > a:hover { + text-decoration: underline; +} .unknownServerPage { background: rgba(0, 0, 0, 0.6); diff --git a/src/main.ts b/src/main.ts index 7810495..0f60c34 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,8 +17,8 @@ if (isSecondInstance) { const createWindow = () => { // Create the browser window. mainWindow = new BrowserWindow({ - width: 1300, - height: 600, + width: 780, + height: 550, minHeight: 475, minWidth: 650, frame: false diff --git a/src/renderer/gameserver/data.ts b/src/renderer/gameserver/data.ts index e3162f6..8140581 100644 --- a/src/renderer/gameserver/data.ts +++ b/src/renderer/gameserver/data.ts @@ -2,6 +2,7 @@ import {socialLink} from './server'; import GameServer from './server'; import GameServerProfile from './profile'; +import { NewsType } from './news'; const TMW2 = new GameServer( @@ -15,6 +16,7 @@ const TMW2 = new GameServer( "TMW2: Monster Wars", "What happens if you mix TMW with Evol and add many new Ideas", "https://tmw2.org/news", + {url:"http://updates.tmw2.org/news.txt",type:NewsType.ManaPlus}, [{isVideo:false,file:"tmw2/background1.png"}], "tmw2/icon.png", [ @@ -34,6 +36,7 @@ const Evol = new GameServer( "Evol Online", "[EvolDescription]", "https://evolonline.org/", + undefined, [{isVideo:false,file:"evol/background1.png"}], "evol/icon.png", [ @@ -51,6 +54,7 @@ const TMW = new GameServer( "The Mana World", "The clasic TMW experience. Join adventures with people from all over the world.", "https://www.themanaworld.org/news-feed.php", + undefined, [{isVideo:false,file:"tmw/background1.png"}], "tmw/icon.png", [ diff --git a/src/renderer/gameserver/news.ts b/src/renderer/gameserver/news.ts new file mode 100644 index 0000000..b8c7b14 --- /dev/null +++ b/src/renderer/gameserver/news.ts @@ -0,0 +1,54 @@ +export enum NewsType { + Markdown, // Without html + yaml + ManaPlus //update news txt +} + +export namespace News { // Fetches only the most recent entry + export async function get(url:string,parser:NewsType):Promise{ + try { + //1. load + const unsafe_content = await request(url); + //2. sanitize + const content = killHTML( unsafe_content ); + //3. parse + if(parser == NewsType.ManaPlus){ + return manaTextParser(content); + } else if (parser == NewsType.Markdown){ + return "Parsing Failed: Markdown Parser is not implemented yet"; + } + } catch (e){ + console.log(e); + return `Failed to get the news, please select the news category on the right to view all news`; + } + } +} + +function request(url:string):Promise{ + return new Promise((res, rej)=>{ + var xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.onload = function() { + if (xhr.status === 200) { + res(xhr.responseText); + } + else { + rej(new Error(`xhr.status: ${xhr.status} != 200`)); + } + }; + xhr.send(); + }); +} + +function killHTML(raw:string):string{ + return raw.replace(/<|>/,"⚠️"); +} + +function manaTextParser(input:string){ + return input + .replace(/\[@@(.+?)\|(.+?)@@\]/g,'$2') + .replace(/##B(.+?)##b/g,'$1') + .replace(/##0 Actual Release: ##1 *(.+)/,'

$1

') + .replace(/\n/g,"
") + .replace(/br>([^]+?)

$1


<').replace(/
/g,"") + .replace(/##\d/g,""); +} diff --git a/src/renderer/gameserver/server.ts b/src/renderer/gameserver/server.ts index d0b4002..30b40e1 100644 --- a/src/renderer/gameserver/server.ts +++ b/src/renderer/gameserver/server.ts @@ -1,6 +1,7 @@ import GameServerProfile from './profile'; import { shell, ipcRenderer } from 'electron'; import { switchPage } from '../CustomEvents'; +import { News, NewsType } from './news'; export default class GameServer { @@ -10,6 +11,7 @@ export default class GameServer { public name:string, public shortDescription:string,// the server in 1-2 sentences public newsPageUrl:string, + public newsLatestPage:{url:string,type:NewsType}, public backgrounds:{isVideo:boolean,file:string}[], public icon:string, public socialLinks:socialLink[] @@ -145,6 +147,22 @@ export default class GameServer { shrtDsrption.classList.add("shortDescription"); shrtDsrption.innerText = this.shortDescription; content.appendChild(shrtDsrption); + if(this.newsLatestPage && this.newsLatestPage != null){ + const latestNews = document.createElement('div'); + latestNews.classList.add("news"); + content.appendChild(latestNews); + News.get(this.newsLatestPage.url,this.newsLatestPage.type).then((result:string)=>{ + latestNews.innerHTML = result; + const aTags = latestNews.getElementsByTagName("a"); + for (var i = 0; i < aTags.length; i++) { + const href = aTags[i].href.toString(); + aTags[i].addEventListener('click', ()=>{ + shell.openExternal(href); + }); + aTags[i].href = "#"; + } + }); + } return content; } diff --git a/src/renderer/serverView.ts b/src/renderer/serverView.ts index 7f932e7..2250680 100644 --- a/src/renderer/serverView.ts +++ b/src/renderer/serverView.ts @@ -95,7 +95,7 @@ function setBackground(){ background1.classList.add('animated'); background1.classList.add('fadeIn'); } - + contentBackground.appendChild(document.createElement('div')) contentBackground.hidden=false; contentBackground.classList.remove('hidden'); } -- cgit v1.2.3-60-g2f50