Skip to content

Commit

Permalink
Supporting lists in api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentFarris committed Feb 23, 2024
1 parent c3e834c commit 0e45a93
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/engine/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ type Host struct {

// NewHost creates a new host with the given name and log stream. The log stream
// is the log handler that is used by the slog package functions. A Host that
// is created through NewHost has no function until Initialize is called.
// is created through NewHost has no function until #Initialize is called.
//
// This is primarily called from #host_container/HostContainer.New
func NewHost(name string, logStream *logging.LogStream) *Host {
w := float32(DefaultWindowWidth)
h := float32(DefaultWindowHeight)
Expand Down Expand Up @@ -163,14 +165,14 @@ func (host *Host) resized() {
// separate editor entities from game entities.
//
// This will increment so it can be called many times, however it is expected
// that DoneCreatingEditorEntities will be called the same number of times.
// that #DoneCreatingEditorEntities will be called the same number of times.
func (host *Host) CreatingEditorEntities() {
host.inEditorEntity++
}

// DoneCreatingEditorEntities is used to signal that the editor is done creating
// entities. This should be called the same number of times as
// CreatingEditorEntities. When the internal counter reaches 0, then any entity
// #CreatingEditorEntities. When the internal counter reaches 0, then any entity
// created on the host will go to the standard entity pool.
func (host *Host) DoneCreatingEditorEntities() {
host.inEditorEntity--
Expand Down Expand Up @@ -250,11 +252,11 @@ func (host *Host) NewEntity() *Entity {
// events, update the entities, and render the scene. This will also check if
// the window has been closed or crashed and set the closing flag accordingly.
//
// The update order is FrameRunner -> Update -> LateUpdate -> EndUpdate
// FrameRunner: Functions added to RunAfterFrames
// Update: Functions added to Updater
// LateUpdate: Functions added to LateUpdater
// EndUpdate: Internal functions for preparing for the next frame
// The update order is FrameRunner -> Update -> LateUpdate -> EndUpdate:
// [-] FrameRunner: Functions added to RunAfterFrames
// [-] Update: Functions added to Updater
// [-] LateUpdate: Functions added to LateUpdater
// [-] EndUpdate: Internal functions for preparing for the next frame
//
// Any destroyed entities will also be ticked for their cleanup. This will also
// tick the editor entities for cleanup.
Expand Down
31 changes: 28 additions & 3 deletions src/generators/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
//go:embed api_index.md
var apiIndex string

const (
linkFmt = "[%s](#%s)"
)

func findRootFolder() (string, error) {
wd, err := os.Getwd()
if _, goMain, _, ok := runtime.Caller(0); ok {
Expand Down Expand Up @@ -306,7 +310,7 @@ func writeTypes(md io.StringWriter, text string) {
md.WriteString(line)
} else {
for j := i; j < len(lines); j++ {
if strings.Contains(lines[j], "}") {
if strings.Contains(lines[j], "}") && !strings.Contains(lines[j], "{") {
break
}
md.WriteString(lines[j])
Expand All @@ -331,8 +335,29 @@ func writeTypes(md io.StringWriter, text string) {
md.WriteString(line)
md.WriteString("\n```\n\n")
} else {
md.WriteString(strings.TrimSpace(line))
md.WriteString("\n")
skipNewline := false
words := strings.Fields(line)
out := make([]string, len(words))
for i := range words {
if strings.HasPrefix(words[i], "#") {
w := words[i][1:]
if idx := strings.LastIndex(w, "/"); idx > 0 {
w = w[idx+1:] + "#" + w[idx+1:]
}
out[i] = fmt.Sprintf(linkFmt, w, w)
} else if words[i] == "[-]" {
out[i] = "\n-"
skipNewline = true
} else {
out[i] = words[i]
}
}
md.WriteString(strings.TrimSpace(strings.Join(out, " ")))
if skipNewline {
md.WriteString(" ")
} else {
md.WriteString("\n")
}
}
}
}
Expand Down

0 comments on commit 0e45a93

Please sign in to comment.