doodle/pkg/campaign/campaign.go
Noah Petherbridge 38614ee280 Tighten Doodad JavaScript API, User Documentation
* Tightens up the surface area of API methods available to the
  JavaScript VMs for doodads. Variables and functions are carefully
  passed in one-by-one so the doodad script can only access intended
  functions and not snoop on undocumented APIs.
* Wrote tons of user documentation for Doodad Scripts: documented the
  full surface area of the exposed JavaScript API now that the surface
  area is known and limited.
* Early WIP code for the Campaign JSON
2020-04-21 23:50:45 -07:00

63 lines
1.7 KiB
Go

// Package campaign contains types and functions for the single player campaigns.
package campaign
// Campaign structure for the JSON campaign files.
type Campaign struct {
Version int `json:"version"`
Title string `json:"title"`
Author string `json:"author"`
Levels []Level `json:"levels"`
}
// Level is the "levels" object of the JSON file.
type Level struct {
Filename string `json:"filename"`
}
// LoadFile reads a campaign file from disk, checking a few locations.
// func LoadFile(filename string) (*Level, error) {
// // Search the system and user paths for this level.
// filename, err := filesystem.FindFile(filename)
// if err != nil {
// return nil, err
// }
//
// // Do we have the file in bindata?
// if jsonData, err := bindata.Asset(filename); err == nil {
// log.Info("loaded from embedded bindata")
// return FromJSON(filename, jsonData)
// }
//
// // WASM: try the file from localStorage or HTTP ajax request.
// if runtime.GOOS == "js" {
// if result, ok := wasm.GetSession(filename); ok {
// log.Info("recall level data from localStorage")
// return FromJSON(filename, []byte(result))
// }
//
// // Ajax request.
// jsonData, err := wasm.HTTPGet(filename)
// if err != nil {
// return nil, err
// }
//
// return FromJSON(filename, jsonData)
// }
//
// // Try the binary format.
// if level, err := LoadBinary(filename); err == nil {
// return level, nil
// } else {
// log.Warn(err.Error())
// }
//
// // Then the JSON format.
// if level, err := LoadJSON(filename); err == nil {
// return level, nil
// } else {
// log.Warn(err.Error())
// }
//
// return nil, errors.New("invalid file type")
// }