mirror of
https://github.com/asherao/dcs-scratchpad.git
synced 2025-10-29 16:56:22 +00:00
save Scratchpad content into Scratchpad\0000.txt
This commit is contained in:
parent
cc777d8aff
commit
f498771429
10
README.md
10
README.md
@ -1,6 +1,6 @@
|
|||||||
# DCS Scratchpad
|
# DCS Scratchpad
|
||||||
|
|
||||||
Resizable and movable DCS World ingame Scratchpad for quick persistant notes - especially useful in VR.
|
Resizable and movable DCS World in-game Scratchpad for quick persistent notes - especially useful in VR.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -9,14 +9,18 @@ Copy the `Scripts` folder into your DCS Saved games folder.
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- Toggle the scratchpad with `CTRL+Shift+X`
|
- Toggle the scratchpad with `CTRL+Shift+X`
|
||||||
- Use `Esc` to remove the textfield focus, but keep the scratchpad open
|
- Use `Esc` to remove the text field focus, but keep the scratchpad open
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
Some settings can be changed in your DCS saved games folder under `Config/ScratchpadConfig.lua` (if the file does not exist, start DCS once after mod installation):
|
Some settings can be changed in your DCS saved games folder under `Config/ScratchpadConfig.lua` (if the file does not exist, start DCS once after mod installation):
|
||||||
|
|
||||||
- `hotkey` change the hotkey used to toggle the scratchpad
|
- `hotkey` change the hotkey used to toggle the scratchpad
|
||||||
- `fontSize` increase or decrease the font size of the scratchpad's textarea
|
- `fontSize` increase or decrease the font size of the Scratchpads textarea
|
||||||
|
|
||||||
|
## Scratchpad Content
|
||||||
|
|
||||||
|
The Scratchpads content is persisted into `Scratchpad\0000.txt` (in your saved games folder; if the file does not exist, start DCS once after mod installation/upgrade). You can also change the file in your favorite text editor before starting DCS.
|
||||||
|
|
||||||
## Kudos
|
## Kudos
|
||||||
|
|
||||||
|
|||||||
@ -29,10 +29,19 @@ function scratchpad_load()
|
|||||||
scratchpad.config = tbl.config
|
scratchpad.config = tbl.config
|
||||||
|
|
||||||
-- config migration
|
-- config migration
|
||||||
|
|
||||||
|
-- add default fontSize config
|
||||||
if scratchpad.config.fontSize == nil then
|
if scratchpad.config.fontSize == nil then
|
||||||
scratchpad.config.fontSize = 14
|
scratchpad.config.fontSize = 14
|
||||||
scratchpad.saveConfiguration()
|
scratchpad.saveConfiguration()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- move content into text file
|
||||||
|
if scratchpad.config.content ~= nil then
|
||||||
|
scratchpad.saveContent("0000", scratchpad.config.content, false)
|
||||||
|
scratchpad.config.content = nil
|
||||||
|
scratchpad.saveConfiguration()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
scratchpad.log("Configuration not found, creating defaults...")
|
scratchpad.log("Configuration not found, creating defaults...")
|
||||||
scratchpad.config = {
|
scratchpad.config = {
|
||||||
@ -40,12 +49,41 @@ function scratchpad_load()
|
|||||||
windowPosition = { x = 200, y = 200 },
|
windowPosition = { x = 200, y = 200 },
|
||||||
windowSize = { w = 350, h = 150 },
|
windowSize = { w = 350, h = 150 },
|
||||||
fontSize = 14,
|
fontSize = 14,
|
||||||
content = "Start writing here ...",
|
|
||||||
}
|
}
|
||||||
scratchpad.saveConfiguration()
|
scratchpad.saveConfiguration()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function scratchpad.getContent(name)
|
||||||
|
local path = lfs.writedir()..[[Scratchpad\]]..name..[[.txt]]
|
||||||
|
file, err = io.open(path, "r")
|
||||||
|
if err then
|
||||||
|
scratchpad.log("Error reading file: "..path)
|
||||||
|
return ""
|
||||||
|
else
|
||||||
|
local content = file:read("*all")
|
||||||
|
file:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function scratchpad.saveContent(name, content, override)
|
||||||
|
lfs.mkdir(lfs.writedir()..[[Scratchpad\]])
|
||||||
|
local path = lfs.writedir()..[[Scratchpad\]]..name..[[.txt]]
|
||||||
|
local mode = "a"
|
||||||
|
if override then
|
||||||
|
mode = "w"
|
||||||
|
end
|
||||||
|
file, err = io.open(path, mode)
|
||||||
|
if err then
|
||||||
|
scratchpad.log("Error writing file: "..path)
|
||||||
|
else
|
||||||
|
file:write(content)
|
||||||
|
file:flush()
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function scratchpad.saveConfiguration()
|
function scratchpad.saveConfiguration()
|
||||||
U.saveInFile(scratchpad.config, "config", lfs.writedir() .. "Config/ScratchpadConfig.lua")
|
U.saveInFile(scratchpad.config, "config", lfs.writedir() .. "Config/ScratchpadConfig.lua")
|
||||||
end
|
end
|
||||||
@ -89,10 +127,9 @@ function scratchpad_load()
|
|||||||
skin.skinData.states.released[1].text.fontSize = scratchpad.config.fontSize
|
skin.skinData.states.released[1].text.fontSize = scratchpad.config.fontSize
|
||||||
textarea:setSkin(skin)
|
textarea:setSkin(skin)
|
||||||
|
|
||||||
textarea:setText(scratchpad.config.content)
|
textarea:setText(scratchpad.getContent("0000"))
|
||||||
textarea:addChangeCallback(function(self)
|
textarea:addChangeCallback(function(self)
|
||||||
scratchpad.config.content = self:getText()
|
scratchpad.saveContent("0000", self:getText(), true)
|
||||||
scratchpad.saveConfiguration()
|
|
||||||
end)
|
end)
|
||||||
textarea:addFocusCallback(function(self)
|
textarea:addFocusCallback(function(self)
|
||||||
if self:getFocused() then
|
if self:getFocused() then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user