layout refact
This commit is contained in:
@@ -12,11 +12,18 @@ import (
|
||||
)
|
||||
|
||||
type DownloadController struct {
|
||||
service domain.DownloadServiceInterface
|
||||
downloadService domain.DownloadServiceInterface
|
||||
softwareService domain.SoftwareServiceInterface
|
||||
}
|
||||
|
||||
func NewDownloadController(service domain.DownloadServiceInterface) *DownloadController {
|
||||
return &DownloadController{service: service}
|
||||
func NewDownloadController(
|
||||
downloadService domain.DownloadServiceInterface,
|
||||
softwareService domain.SoftwareServiceInterface,
|
||||
) *DownloadController {
|
||||
return &DownloadController{
|
||||
downloadService: downloadService,
|
||||
softwareService: softwareService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DownloadController) serve(w http.ResponseWriter, r *http.Request, release *domain.Release, is_source bool) {
|
||||
@@ -62,7 +69,7 @@ func (c *DownloadController) handleError(w http.ResponseWriter, err error) {
|
||||
|
||||
func (c *DownloadController) GetLatestSource(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
release, err := c.service.GetLatestRelease(name)
|
||||
release, err := c.downloadService.GetLatestRelease(name)
|
||||
if err != nil {
|
||||
c.handleError(w, err)
|
||||
return
|
||||
@@ -73,7 +80,7 @@ func (c *DownloadController) GetLatestSource(w http.ResponseWriter, r *http.Requ
|
||||
|
||||
func (c *DownloadController) GetLatestCartridge(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
release, err := c.service.GetLatestRelease(name)
|
||||
release, err := c.downloadService.GetLatestRelease(name)
|
||||
if err != nil {
|
||||
c.handleError(w, err)
|
||||
return
|
||||
@@ -85,7 +92,7 @@ func (c *DownloadController) GetLatestCartridge(w http.ResponseWriter, r *http.R
|
||||
func (c *DownloadController) GetSource(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
version := chi.URLParam(r, "version")
|
||||
release, err := c.service.GetSpecificRelease(name, version)
|
||||
release, err := c.downloadService.GetSpecificRelease(name, version)
|
||||
if err != nil {
|
||||
c.handleError(w, err)
|
||||
return
|
||||
@@ -97,7 +104,7 @@ func (c *DownloadController) GetSource(w http.ResponseWriter, r *http.Request) {
|
||||
func (c *DownloadController) GetCartridge(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
version := chi.URLParam(r, "version")
|
||||
release, err := c.service.GetSpecificRelease(name, version)
|
||||
release, err := c.downloadService.GetSpecificRelease(name, version)
|
||||
if err != nil {
|
||||
c.handleError(w, err)
|
||||
return
|
||||
|
||||
@@ -49,6 +49,12 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
softwares, err := c.softwareService.List()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template_utils.GetTemplate("play_controller_play", "http/views/shared/layout.html", "http/views/play/play.html")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -58,6 +64,7 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
|
||||
tmpl.Execute(w, map[string]interface{}{
|
||||
"Software": software,
|
||||
"WebPlayableRelease": web_playable_release,
|
||||
"Softwares": softwares,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+15
-4
@@ -8,14 +8,25 @@ import (
|
||||
)
|
||||
|
||||
type RootController struct {
|
||||
service domain.SoftwareServiceInterface
|
||||
softwareService domain.SoftwareServiceInterface
|
||||
}
|
||||
|
||||
func NewRootController() *RootController {
|
||||
return &RootController{}
|
||||
func NewRootController(softwareService domain.SoftwareServiceInterface) *RootController {
|
||||
return &RootController{
|
||||
softwareService: softwareService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RootController) Index(w http.ResponseWriter, r *http.Request) {
|
||||
softwares, err := c.softwareService.List()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Softwares": softwares,
|
||||
}
|
||||
|
||||
tmpl, err := template_utils.GetTemplate("root_index", "http/views/shared/layout.html", "http/views/root/index.html")
|
||||
if err != nil {
|
||||
@@ -23,5 +34,5 @@ func (c *RootController) Index(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, nil)
|
||||
tmpl.Execute(w, data)
|
||||
}
|
||||
|
||||
@@ -24,24 +24,42 @@ func (c *SoftwareController) Index(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Softwares": softwares,
|
||||
}
|
||||
|
||||
tmpl, err := template_utils.GetTemplate("software_index", "http/views/shared/layout.html", "http/views/software/index.html")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl.Execute(w, softwares)
|
||||
tmpl.Execute(w, data)
|
||||
}
|
||||
|
||||
func (c *SoftwareController) Show(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
|
||||
data, err := c.softwareService.GetForShowByName(name)
|
||||
showData, err := c.softwareService.GetForShowByName(name)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
softwares, err := c.softwareService.List()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
"Software": showData.Software,
|
||||
"Releases": showData.Releases,
|
||||
"LatestRelease": showData.LatestRelease,
|
||||
"WebPlayableRelease": showData.WebPlayableRelease,
|
||||
"Softwares": softwares,
|
||||
}
|
||||
|
||||
tmpl, err := template_utils.GetTemplate("software_show", "http/views/shared/layout.html", "http/views/software/show.html")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -8,11 +8,18 @@ import (
|
||||
)
|
||||
|
||||
type SoftwareUpdaterController struct {
|
||||
service domain.SoftwareUpdaterServiceInterface
|
||||
softwareUpdaterService domain.SoftwareUpdaterServiceInterface
|
||||
softwareService domain.SoftwareServiceInterface
|
||||
}
|
||||
|
||||
func NewSoftwareUpdaterController(service domain.SoftwareUpdaterServiceInterface) *SoftwareUpdaterController {
|
||||
return &SoftwareUpdaterController{service: service}
|
||||
func NewSoftwareUpdaterController(
|
||||
softwareUpdaterService domain.SoftwareUpdaterServiceInterface,
|
||||
softwareService domain.SoftwareServiceInterface,
|
||||
) *SoftwareUpdaterController {
|
||||
return &SoftwareUpdaterController{
|
||||
softwareUpdaterService: softwareUpdaterService,
|
||||
softwareService: softwareService,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *SoftwareUpdaterController) Update(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -31,7 +38,7 @@ func (c *SoftwareUpdaterController) Update(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.service.Update(platform, name, version); err != nil {
|
||||
if err := c.softwareUpdaterService.Update(platform, name, version); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,10 +8,10 @@ import (
|
||||
func StartHttpServer(domain_instance domain.Domain) {
|
||||
router := NewRouter(
|
||||
NewSoftwareController(domain_instance.SoftwareService),
|
||||
NewSoftwareUpdaterController(domain_instance.SoftwareUpdaterService),
|
||||
NewDownloadController(domain_instance.DownloadService),
|
||||
NewSoftwareUpdaterController(domain_instance.SoftwareUpdaterService, domain_instance.SoftwareService),
|
||||
NewDownloadController(domain_instance.DownloadService, domain_instance.SoftwareService),
|
||||
NewPlayController(domain_instance.SoftwareService, domain_instance.FileService),
|
||||
NewRootController(),
|
||||
NewRootController(domain_instance.SoftwareService),
|
||||
).Init()
|
||||
|
||||
http_utils.StartGenericHTTPServer(http_utils.StartGenericHTTPServerContext{
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
<h1 class="my-4">Welcome</h1>
|
||||
|
||||
<p>
|
||||
Welcome to Teletype Games! This site is dedicated to showcasing <strong>open-source indie games</strong>,
|
||||
created with enthusiasm and as a hobby project.
|
||||
</p>
|
||||
<p>
|
||||
Explore our collection of unique games, navigate using the top menu to access the <strong>Home</strong> page,
|
||||
discover more <strong>Softwares</strong>, or check out our <strong>Youtube</strong> channel.
|
||||
Welcome to Teletype Games! We are an independent, community-driven game development collective. Our mission is to create small, experimental, and full-fledged games in short development cycles while keeping everything open, transparent, and collaborative.
|
||||
</p>
|
||||
|
||||
{{end}}
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/software">Softwares</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="https://www.youtube.com/@teletypegames" target="_blank">Youtube</a>
|
||||
</li>
|
||||
@@ -34,14 +31,32 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container mt-4 mb-4 content-border">
|
||||
{{block "content" .}}{{end}}
|
||||
<div class="container mt-4 mb-4">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="content-border">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item disabled" aria-disabled="true">Softwares</li>
|
||||
{{range .Softwares}}
|
||||
<li class="list-group-item">
|
||||
<a href="/software/{{.Software.Name}}">{{.Software.Name}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div class="content-border p-3">
|
||||
{{block "content" .}}{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="footer-border text-center py-3">
|
||||
<p>
|
||||
<a class="nav-link" href="http://teletype.hu" target="_blank">
|
||||
Tasnádi Zsolt 2025
|
||||
Teletype Games 2025-2026
|
||||
</a>
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<ul>
|
||||
{{range .}}
|
||||
{{range .Softwares}}
|
||||
<li>
|
||||
<a href="/software/{{.Name}}">{{.Title}}</a>
|
||||
<a href="/software/{{.Software.Name}}">{{.Software.Title}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
@@ -1,35 +1,72 @@
|
||||
{{define "content"}}
|
||||
<h1 class="my-4">{{.Software.Title}}</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
{{if .WebPlayableRelease}}
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
<h3>Play</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{.Software.Title}}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">{{.Software.Author}}</h6>
|
||||
<p class="card-text">{{.Software.Desc}}</p>
|
||||
<p class="card-text"><strong>Version:</strong> {{.LatestRelease.Version}}</p>
|
||||
<p class="card-text"><strong>License:</strong> {{.Software.License}}</p>
|
||||
<p class="card-text"><a href="{{.Software.Site}}" target="_blank">Website</a></p>
|
||||
<div class="ratio ratio-4x3" style="max-width: 960px; margin: 0 auto;">
|
||||
<iframe id="gameFrame" src="/play/{{.Software.Name}}/{{.WebPlayableRelease.Version}}/content/index.html"
|
||||
frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="btn-group d-flex justify-content-center" role="group" aria-label="Game controls">
|
||||
<button id="fullscreenButton" class="btn btn-secondary btn-sm">Fullscreen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-header">
|
||||
<h3>Overview</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-bordered">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row" style="width: 30%;">Title</th>
|
||||
<td>{{.Software.Title}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Author</th>
|
||||
<td>{{.Software.Author}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Description</th>
|
||||
<td>{{.Software.Desc}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Version</th>
|
||||
<td>{{.LatestRelease.Version}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">License</th>
|
||||
<td>{{.Software.License}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Website</th>
|
||||
<td><a href="{{.Software.Site}}" target="_blank">{{.Software.Site}}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="btn-group d-flex justify-content-end" role="group" aria-label="Operations">
|
||||
<a href="/download/{{.Software.Name}}/source" class="btn btn-primary btn-sm">Source</a>
|
||||
<a href="/download/{{.Software.Name}}/cartridge" class="btn btn-primary btn-sm">Cartridge</a>
|
||||
<a href="/software/{{.Software.Name}}" class="btn btn-primary btn-sm">Releases</a>
|
||||
<a href="/play/{{.Software.Name}}/{{.LatestRelease.Version}}" class="btn btn-primary btn-sm">Play</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{if .WebPlayableRelease}}
|
||||
<h3>Play</h3>
|
||||
<div class="mb-4">
|
||||
<div class="ratio ratio-4x3" style="max-width: 960px; margin: 0 auto;">
|
||||
<iframe id="gameFrame" src="/play/{{.Software.Name}}/{{.WebPlayableRelease.Version}}/content/index.html"
|
||||
frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<h3>Releases</h3>
|
||||
<div class="row">
|
||||
{{range .Releases}}
|
||||
@@ -42,7 +79,7 @@
|
||||
<div class="card-footer">
|
||||
<div class="btn-group d-flex justify-content-center" role="group" aria-label="Operations">
|
||||
{{if .HTMLFolderPath}}
|
||||
<a href="/play/{{$.Software.Name}}/{{.Version}}" class="btn btn-success btn-sm">Play</a>
|
||||
<a href="/play/{{$.Software.Name}}/{{.Version}}" class="btn btn-primary btn-sm">Play</a>
|
||||
{{end}}
|
||||
<a href="/download/{{$.Software.Name}}/{{.Version}}/source"
|
||||
class="btn btn-primary btn-sm">Source</a>
|
||||
@@ -54,6 +91,4 @@
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<p><a href="/" class="btn btn-primary">Back to Softwares</a></p>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user